Class: ComfortableMexicanSofa::Content::Tag::Snippet
- Inherits:
-
ComfortableMexicanSofa::Content::Tag
- Object
- ComfortableMexicanSofa::Content::Tag
- ComfortableMexicanSofa::Content::Tag::Snippet
- Defined in:
- lib/comfortable_mexican_sofa/content/tags/snippet.rb
Overview
Tag for reusable snippets within context’s site scope. Looks like this:
{{cms:snippet identifier}}
Snippets may have more tags in them like fragments, so they may be expanded too.
Instance Attribute Summary collapse
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
Attributes inherited from ComfortableMexicanSofa::Content::Tag
Instance Method Summary collapse
- #content ⇒ Object
-
#initialize(context:, params: [], source: nil) ⇒ Snippet
constructor
A new instance of Snippet.
-
#snippet ⇒ Object
Grabbing or initializing Comfy::Cms::Snippet object.
Methods inherited from ComfortableMexicanSofa::Content::Tag
Constructor Details
#initialize(context:, params: [], source: nil) ⇒ Snippet
Returns a new instance of Snippet.
11 12 13 14 15 16 17 18 |
# File 'lib/comfortable_mexican_sofa/content/tags/snippet.rb', line 11 def initialize(context:, params: [], source: nil) super @identifier = params[0] unless @identifier.present? raise Error, "Missing identifier for snippet tag" end end |
Instance Attribute Details
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
9 10 11 |
# File 'lib/comfortable_mexican_sofa/content/tags/snippet.rb', line 9 def identifier @identifier end |
Instance Method Details
#content ⇒ Object
20 21 22 |
# File 'lib/comfortable_mexican_sofa/content/tags/snippet.rb', line 20 def content snippet.content end |
#snippet ⇒ Object
Grabbing or initializing Comfy::Cms::Snippet object
25 26 27 28 |
# File 'lib/comfortable_mexican_sofa/content/tags/snippet.rb', line 25 def snippet context.site.snippets.detect { |s| s.identifier == identifier } || context.site.snippets.build(identifier: identifier) end |