class ComfortableMexicanSofa::Content::Tag::Fragment
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
Attributes
identifier[R]
namespace[R]
options[R]
@type [{String => String}]
renderable[RW]
Public Class Methods
new(context:, params: [], source: nil)
click to toggle source
Calls superclass method
ComfortableMexicanSofa::Content::Tag::new
# File lib/comfortable_mexican_sofa/content/tags/fragment.rb, line 19 def initialize(context:, params: [], source: nil) super @options = params.extract_options! @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
Public Instance Methods
content()
click to toggle source
# File lib/comfortable_mexican_sofa/content/tags/fragment.rb, line 40 def content fragment.content end
form_field()
click to toggle source
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
# 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()
click to toggle source
# File lib/comfortable_mexican_sofa/content/tags/fragment.rb, line 62 def form_field_id "fragment-#{@identifier}" end
fragment()
click to toggle source
Grabs existing fragment record or spins up a new instance if there's none @return [Comfy::Cms::Fragment]
# 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()
click to toggle source
If `render: false` was passed in we won't render anything. Assuming that that fragment content will be rendered manually
# File lib/comfortable_mexican_sofa/content/tags/fragment.rb, line 46 def render renderable ? content : "" end