Class: Spree::Emails::Template
- Inherits:
-
Object
- Object
- Spree::Emails::Template
- Defined in:
- app/services/spree/emails/template.rb
Overview
One Liquid email template: a file on disk, with optional front matter holding its subject, or a store's saved version with the subject in its own field.
Constant Summary collapse
- FRONT_MATTER =
/\A---\s*\n(.*?)\n---\s*(?:\n|\z)/m
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#body ⇒ String
The template without its front matter.
-
#initialize(key:, path: nil, subject: nil, body: nil) ⇒ Template
constructor
A new instance of Template.
-
#stored? ⇒ Boolean
Whether this is a store's saved template or a draft, rather than a file.
-
#subject ⇒ String?
The subject line as Liquid.
Constructor Details
#initialize(key:, path: nil, subject: nil, body: nil) ⇒ Template
Returns a new instance of Template.
15 16 17 18 19 20 |
# File 'app/services/spree/emails/template.rb', line 15 def initialize(key:, path: nil, subject: nil, body: nil) @key = key @path = path @subject = subject @body = body end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
9 10 11 |
# File 'app/services/spree/emails/template.rb', line 9 def key @key end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'app/services/spree/emails/template.rb', line 9 def path @path end |
Instance Method Details
#body ⇒ String
Returns the template without its front matter.
33 34 35 |
# File 'app/services/spree/emails/template.rb', line 33 def body stored? ? @body.to_s : source.sub(FRONT_MATTER, '') end |
#stored? ⇒ Boolean
Returns whether this is a store's saved template or a draft, rather than a file.
23 24 25 |
# File 'app/services/spree/emails/template.rb', line 23 def stored? path.nil? end |
#subject ⇒ String?
Returns the subject line as Liquid.
28 29 30 |
# File 'app/services/spree/emails/template.rb', line 28 def subject stored? ? @subject : front_matter['subject'] end |