Class: Occams::Content::Tag::Fragment
- Inherits:
-
Occams::Content::Tag
- Object
- Occams::Content::Tag
- Occams::Content::Tag::Fragment
- Defined in:
- lib/occams/content/tags/fragment.rb
Overview
Base Tag class that other fragment tags depend on. Tag handles following options:
`render`: true (default) | false
do we want to render this content on the page, or manually access it via
helpers. Good example would be content for meta tags.
`namespace`:
Just a string that allows grouping of form elements in the admin area
Instance Attribute Summary collapse
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#renderable ⇒ Object
Returns the value of attribute renderable.
Attributes inherited from Occams::Content::Tag
Instance Method Summary collapse
- #content ⇒ Object
-
#form_field ⇒ Object
Tag renders its own form inputs via ‘form_field(template, index)` For example: class MyTag < Occams::Content::Tag::Fragment def form_field(view, index, &block) # omit yield if you don’t want default wrapper yield view.text_area “input_name”, “value” end end.
- #form_field_id ⇒ Object
-
#fragment ⇒ Occams::Cms::Fragment
Grabs existing fragment record or spins up a new instance if there’s none.
-
#initialize(context:, params: [], source: nil) ⇒ Fragment
constructor
A new instance of Fragment.
-
#render ⇒ Object
If ‘render: false` was passed in we won’t render anything.
Methods inherited from Occams::Content::Tag
Constructor Details
#initialize(context:, params: [], source: nil) ⇒ Fragment
Returns a new instance of Fragment.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/occams/content/tags/fragment.rb', line 18 def initialize(context:, params: [], source: nil) super @options = params. @identifier = params[0] unless @identifier.present? raise Error, "Missing identifier for fragment tag: #{source}" end @namespace = @options['namespace'] || 'default' @renderable = @options['render'].to_s.downcase != 'false' end |
Instance Attribute Details
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
13 14 15 |
# File 'lib/occams/content/tags/fragment.rb', line 13 def identifier @identifier end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
13 14 15 |
# File 'lib/occams/content/tags/fragment.rb', line 13 def namespace @namespace end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
16 17 18 |
# File 'lib/occams/content/tags/fragment.rb', line 16 def @options end |
#renderable ⇒ Object
Returns the value of attribute renderable.
12 13 14 |
# File 'lib/occams/content/tags/fragment.rb', line 12 def renderable @renderable end |
Instance Method Details
#content ⇒ Object
39 40 41 |
# File 'lib/occams/content/tags/fragment.rb', line 39 def content fragment.content end |
#form_field ⇒ Object
57 58 59 |
# File 'lib/occams/content/tags/fragment.rb', line 57 def form_field raise 'Form field rendering not implemented for this Tag' end |
#form_field_id ⇒ Object
61 62 63 |
# File 'lib/occams/content/tags/fragment.rb', line 61 def form_field_id "fragment-#{@identifier}" end |
#fragment ⇒ Occams::Cms::Fragment
Grabs existing fragment record or spins up a new instance if there’s none
34 35 36 37 |
# File 'lib/occams/content/tags/fragment.rb', line 34 def fragment context.fragments.detect { |f| f.identifier == identifier } || context.fragments.build(identifier: identifier) end |
#render ⇒ Object
If ‘render: false` was passed in we won’t render anything. Assuming that that fragment content will be rendered manually
45 46 47 |
# File 'lib/occams/content/tags/fragment.rb', line 45 def render renderable ? content : '' end |