Class: Occams::Content::Tag::Snippet
- Inherits:
-
Occams::Content::Tag
- Object
- Occams::Content::Tag
- Occams::Content::Tag::Snippet
- Defined in:
- lib/occams/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 Occams::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 Occams::Cms::Snippet object.
Methods inherited from Occams::Content::Tag
Constructor Details
#initialize(context:, params: [], source: nil) ⇒ Snippet
Returns a new instance of Snippet.
10 11 12 13 14 15 16 17 |
# File 'lib/occams/content/tags/snippet.rb', line 10 def initialize(context:, params: [], source: nil) super @identifier = params[0] return if @identifier.present? raise Error, 'Missing identifier for snippet tag' end |
Instance Attribute Details
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
8 9 10 |
# File 'lib/occams/content/tags/snippet.rb', line 8 def identifier @identifier end |
Instance Method Details
#content ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/occams/content/tags/snippet.rb', line 19 def content if snippet.markdown Kramdown::Document.new(snippet.content.to_s).to_html else snippet.content end end |
#snippet ⇒ Object
Grabbing or initializing Occams::Cms::Snippet object
28 29 30 31 |
# File 'lib/occams/content/tags/snippet.rb', line 28 def snippet context.site.snippets.detect { |s| s.identifier == identifier } || context.site.snippets.build(identifier: identifier) end |