Class: I18nEmails::Email
- Inherits:
-
Object
- Object
- I18nEmails::Email
- Includes:
- ActionView::Helpers::TagHelper, ActionView::Helpers::TextHelper
- Defined in:
- lib/i18n_emails.rb
Constant Summary collapse
- BODY_SPLIT =
/^-{3,}\n/
Class Method Summary collapse
-
.load_all(dir = I18nEmails.load_path) ⇒ Object
Returns a hash of the content of all .email files contained the the specified directory (searches recursivly).
Instance Method Summary collapse
-
#initialize(path) ⇒ Email
constructor
A new instance of Email.
- #key ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(path) ⇒ Email
Returns a new instance of Email.
48 49 50 51 |
# File 'lib/i18n_emails.rb', line 48 def initialize(path) @path = path @file_contents = File.read(path) end |
Class Method Details
.load_all(dir = I18nEmails.load_path) ⇒ Object
Returns a hash of the content of all .email files contained the the specified directory (searches recursivly)
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/i18n_emails.rb', line 24 def load_all(dir = I18nEmails.load_path) hash = {} Dir[File.join(dir, "*")].each do |file_or_folder| if File.directory?(file_or_folder) hash[File.basename(file_or_folder)] = Email.load_all(file_or_folder) else if email_file?(file_or_folder) email = Email.new(file_or_folder) hash[email.key] = email.to_hash end end end hash end |
Instance Method Details
#key ⇒ Object
53 54 55 |
# File 'lib/i18n_emails.rb', line 53 def key File.basename(@path).gsub(".email", '') end |
#to_hash ⇒ Object
57 58 59 60 |
# File 'lib/i18n_emails.rb', line 57 def to_hash header, body = @file_contents.split(BODY_SPLIT) YAML::load(header).merge({'body' => simple_format(body)}) end |