Class: Locomotive::Liquid::Tags::Editable::Base
- Inherits:
-
Liquid::Block
- Object
- Liquid::Block
- Locomotive::Liquid::Tags::Editable::Base
- Defined in:
- lib/locomotive/liquid/tags/editable/base.rb
Constant Summary collapse
Instance Attribute Summary collapse
-
#slug ⇒ Object
Returns the value of attribute slug.
Instance Method Summary collapse
- #end_tag ⇒ Object
-
#initialize(tag_name, markup, tokens, context) ⇒ Base
constructor
A new instance of Base.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, markup, tokens, context) ⇒ Base
Returns a new instance of Base.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/locomotive/liquid/tags/editable/base.rb', line 11 def initialize(tag_name, markup, tokens, context) if markup =~ Syntax @slug = $1.gsub(/[\"\']/, '') @options = { fixed: false } markup.scan(::Liquid::TagAttributes) { |key, value| @options[key.to_sym] = value.gsub(/^[\"\']/, '').gsub(/[\"\']$/, '') } else raise ::Liquid::SyntaxError.new("Syntax Error in 'editable_xxx' - Valid syntax: editable_xxx <slug>(, <options>)") end super end |
Instance Attribute Details
#slug ⇒ Object
Returns the value of attribute slug.
9 10 11 |
# File 'lib/locomotive/liquid/tags/editable/base.rb', line 9 def slug @slug end |
Instance Method Details
#end_tag ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/locomotive/liquid/tags/editable/base.rb', line 23 def end_tag super if @context[:page].present? @context[:page].add_or_update_editable_element(default_element_attributes, document_type) end end |
#render(context) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/locomotive/liquid/tags/editable/base.rb', line 31 def render(context) current_page = context.registers[:page] element = current_page.find_editable_element(context['block'].try(:name), @slug) if element.present? render_element(context, element) else Locomotive.log :error, "[editable element] missing element `#{context['block'].try(:name)}` / #{@slug} on #{current_page.fullpath}" '' end end |