Class: Antwort::EmailTemplate
- Inherits:
-
Object
- Object
- Antwort::EmailTemplate
- Includes:
- FileHelpers, Helpers
- Defined in:
- lib/antwort/email/template.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#layout ⇒ Object
readonly
Returns the value of attribute layout.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #exists? ⇒ Boolean
-
#has_images? ⇒ Boolean
rubocop:disable Style/PredicateName.
-
#image_path(file_name) ⇒ Object
rubocop:enable Style/PredicateName.
- #images ⇒ Object
-
#initialize(template_name) ⇒ EmailTemplate
constructor
A new instance of EmailTemplate.
- #last_build ⇒ Object
- #partials ⇒ Object
- #url ⇒ Object
Methods included from FileHelpers
#count_files, #create_file!, #email_id_from_folder_name, #list_folders
Methods included from Helpers
Constructor Details
#initialize(template_name) ⇒ EmailTemplate
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/antwort/email/template.rb', line 8 def initialize(template_name) @name = template_name @path = "emails/#{@name}" @file = "#{@path}/index.html.erb" if exists? read_template @data = load_data @layout = set_layout @title = [:title] || 'Untitled' end end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
6 7 8 |
# File 'lib/antwort/email/template.rb', line 6 def body @body end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/antwort/email/template.rb', line 6 def data @data end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
6 7 8 |
# File 'lib/antwort/email/template.rb', line 6 def file @file end |
#layout ⇒ Object (readonly)
Returns the value of attribute layout.
6 7 8 |
# File 'lib/antwort/email/template.rb', line 6 def layout @layout end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
6 7 8 |
# File 'lib/antwort/email/template.rb', line 6 def end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/antwort/email/template.rb', line 6 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/antwort/email/template.rb', line 6 def path @path end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
6 7 8 |
# File 'lib/antwort/email/template.rb', line 6 def title @title end |
Instance Method Details
#exists? ⇒ Boolean
21 22 23 |
# File 'lib/antwort/email/template.rb', line 21 def exists? File.file? @file end |
#has_images? ⇒ Boolean
rubocop:disable Style/PredicateName
44 45 46 |
# File 'lib/antwort/email/template.rb', line 44 def has_images? !images.empty? end |
#image_path(file_name) ⇒ Object
rubocop:enable Style/PredicateName
49 50 51 52 53 54 |
# File 'lib/antwort/email/template.rb', line 49 def image_path(file_name) path = "assets/images/#{@name}/#{file_name}" full_path = File.(path, Dir.pwd) return path if File.exist? full_path nil end |
#images ⇒ Object
38 39 40 41 |
# File 'lib/antwort/email/template.rb', line 38 def images dir = "./assets/images/#{@name}" Dir.entries(dir).select { |file| file[0] != '.' } end |
#last_build ⇒ Object
33 34 35 36 |
# File 'lib/antwort/email/template.rb', line 33 def last_build built_emails = list_folders('./build') built_emails.select { |f| f.split('-')[0..-2].join('-') == @name }.sort.last end |
#partials ⇒ Object
29 30 31 |
# File 'lib/antwort/email/template.rb', line 29 def partials Dir.entries(@path).select { |f| f[0] == '_' && f[-4, 4] == '.erb' } end |
#url ⇒ Object
25 26 27 |
# File 'lib/antwort/email/template.rb', line 25 def url "/template/#{@name}" end |