Class: Antwort::EmailTemplate

Inherits:
Object
  • Object
show all
Includes:
FileHelpers, Helpers
Defined in:
lib/antwort/email/template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FileHelpers

#count_files, #create_file!, #email_id_from_folder_name, #list_folders

Methods included from Helpers

#symbolize_keys!

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

#bodyObject (readonly)

Returns the value of attribute body.



6
7
8
# File 'lib/antwort/email/template.rb', line 6

def body
  @body
end

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/antwort/email/template.rb', line 6

def data
  @data
end

#fileObject (readonly)

Returns the value of attribute file.



6
7
8
# File 'lib/antwort/email/template.rb', line 6

def file
  @file
end

#layoutObject (readonly)

Returns the value of attribute layout.



6
7
8
# File 'lib/antwort/email/template.rb', line 6

def layout
  @layout
end

#metadataObject (readonly)

Returns the value of attribute metadata.



6
7
8
# File 'lib/antwort/email/template.rb', line 6

def 
  
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/antwort/email/template.rb', line 6

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/antwort/email/template.rb', line 6

def path
  @path
end

#titleObject (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.expand_path(path, Dir.pwd)
  return path if File.exist? full_path
  nil
end

#imagesObject



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_buildObject



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

#partialsObject



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

#urlObject



25
26
27
# File 'lib/antwort/email/template.rb', line 25

def url
  "/template/#{@name}"
end