Class: Nisetegami::Template
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Nisetegami::Template
- Defined in:
- app/models/nisetegami/template.rb
Constant Summary collapse
- CONTENT =
constants
[:subject, :body_html, :body_text]
- HEADERS =
[:cc, :bcc, :reply_to, :from]
Class Method Summary collapse
-
.lookup(mailer_instance) ⇒ Object
Accepts an instance of the ActionMailer::Base subclass and attempts to find associated template using name and action_name of the mailer.
Instance Method Summary collapse
- #headers(variables = {}) ⇒ Object
- #layout_html_path ⇒ Object
- #layout_text_path ⇒ Object
- #mailer ⇒ Object
-
#mapping ⇒ Object
Returns a mapping for
self
, as a Hash. - #message(recipient, variables) ⇒ Object
-
#recent ⇒ Object
scopes.
- #variable_mapping ⇒ Object
-
#variable_names ⇒ Object
Returns a list of variables for
self
, using a Nisetegami::Mapping definitions.
Class Method Details
.lookup(mailer_instance) ⇒ Object
Accepts an instance of the ActionMailer::Base subclass and attempts to find associated template using name and action_name of the mailer.
42 43 44 |
# File 'app/models/nisetegami/template.rb', line 42 def self.lookup(mailer_instance) relation.where(mailer: mailer_instance.class.name, action: mailer_instance.action_name).first end |
Instance Method Details
#headers(variables = {}) ⇒ Object
97 98 99 100 101 102 |
# File 'app/models/nisetegami/template.rb', line 97 def headers(variables = {}) = { subject: render_subject(variables) } [:css] = associated_stylesheets unless only_text? HEADERS.each { |header| [header] = self[header] unless self[header].blank? } end |
#layout_html_path ⇒ Object
46 47 48 |
# File 'app/models/nisetegami/template.rb', line 46 def layout_html_path layout_html && File.join(Nisetegami.layouts_path, layout_html) end |
#layout_text_path ⇒ Object
50 51 52 |
# File 'app/models/nisetegami/template.rb', line 50 def layout_text_path layout_text && File.join(Nisetegami.layouts_path, layout_text) end |
#mailer ⇒ Object
75 76 77 78 |
# File 'app/models/nisetegami/template.rb', line 75 def mailer @_mailer ||= self[:mailer].constantize rescue NameError end |
#mapping ⇒ Object
Returns a mapping for self
, as a Hash.
55 56 57 |
# File 'app/models/nisetegami/template.rb', line 55 def mapping @_mapping ||= ::Nisetegami.mapping.lookup(mailer, action) end |
#message(recipient, variables) ⇒ Object
104 105 106 107 |
# File 'app/models/nisetegami/template.rb', line 104 def (recipient, variables) return nil unless valid? mailer.testing(action, recipient, variables) end |
#recent ⇒ Object
scopes
14 |
# File 'app/models/nisetegami/template.rb', line 14 scope :recent, order('id DESC') |
#variable_mapping ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'app/models/nisetegami/template.rb', line 65 def variable_mapping @_variable_mapping ||= begin mapping.each_with_object([]) do |(variable, thing), array| # @todo: store variable_mapping in mapping instead of classes [?] meths = Nisetegami::Utils.liquid_methods_for(Nisetegami.cast[thing]) array << (meths.blank? ? variable.to_sym : { variable.to_sym => meths }) end end end |
#variable_names ⇒ Object
Returns a list of variables for self
, using a Nisetegami::Mapping definitions.
61 62 63 |
# File 'app/models/nisetegami/template.rb', line 61 def variable_names @_variable_names ||= mapping.keys end |