Class: ComfortableMexicanSofa::Content::Tag::Fragment
- Inherits:
-
ComfortableMexicanSofa::Content::Tag
- Object
- ComfortableMexicanSofa::Content::Tag
- ComfortableMexicanSofa::Content::Tag::Fragment
- Defined in:
- lib/comfortable_mexican_sofa/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 ComfortableMexicanSofa::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 < ComfortableMexicanSofa::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 ⇒ Comfy::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 ComfortableMexicanSofa::Content::Tag
Constructor Details
#initialize(context:, params: [], source: nil) ⇒ Fragment
Returns a new instance of Fragment.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/comfortable_mexican_sofa/content/tags/fragment.rb', line 19 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.
14 15 16 |
# File 'lib/comfortable_mexican_sofa/content/tags/fragment.rb', line 14 def identifier @identifier end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
14 15 16 |
# File 'lib/comfortable_mexican_sofa/content/tags/fragment.rb', line 14 def namespace @namespace end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
17 18 19 |
# File 'lib/comfortable_mexican_sofa/content/tags/fragment.rb', line 17 def @options end |
#renderable ⇒ Object
Returns the value of attribute renderable.
13 14 15 |
# File 'lib/comfortable_mexican_sofa/content/tags/fragment.rb', line 13 def renderable @renderable end |
Instance Method Details
#content ⇒ Object
40 41 42 |
# File 'lib/comfortable_mexican_sofa/content/tags/fragment.rb', line 40 def content fragment.content end |
#form_field ⇒ Object
Tag renders its own form inputs via ‘form_field(template, index)` For example:
class MyTag < ComfortableMexicanSofa::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
58 59 60 |
# File 'lib/comfortable_mexican_sofa/content/tags/fragment.rb', line 58 def form_field raise "Form field rendering not implemented for this Tag" end |
#form_field_id ⇒ Object
62 63 64 |
# File 'lib/comfortable_mexican_sofa/content/tags/fragment.rb', line 62 def form_field_id "fragment-#{@identifier}" end |
#fragment ⇒ Comfy::Cms::Fragment
Grabs existing fragment record or spins up a new instance if there’s none
35 36 37 38 |
# File 'lib/comfortable_mexican_sofa/content/tags/fragment.rb', line 35 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
46 47 48 |
# File 'lib/comfortable_mexican_sofa/content/tags/fragment.rb', line 46 def render renderable ? content : "" end |