Class: Locomotive::Steam::Liquid::Tags::Editable::Base
- Inherits:
-
Liquid::Block
- Object
- Liquid::Block
- Locomotive::Steam::Liquid::Tags::Editable::Base
- Includes:
- Concerns::Attributes
- Defined in:
- lib/locomotive/steam/liquid/tags/editable/base.rb
Constant Summary collapse
- Syntax =
/(#{::Liquid::QuotedFragment})(\s*,\s*#{::Liquid::Expression}+)?/o
Instance Attribute Summary collapse
-
#label ⇒ Object
Returns the value of attribute label.
-
#page_fullpath ⇒ Object
Returns the value of attribute page_fullpath.
-
#slug ⇒ Object
Returns the value of attribute slug.
Attributes included from Concerns::Attributes
Instance Method Summary collapse
- #blank? ⇒ Boolean
- #default_render ⇒ Object
-
#initialize(tag_name, markup, options) ⇒ Base
constructor
A new instance of Base.
- #parse(tokens) ⇒ Object
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, markup, options) ⇒ Base
Returns a new instance of Base.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/locomotive/steam/liquid/tags/editable/base.rb', line 14 def initialize(tag_name, markup, ) if markup =~ Syntax @page_fullpath = [:page].fullpath @label_or_slug = $1.gsub(/[\"\']/, '') parse_attributes(markup, fixed: false, inline_editing: true) set_label_and_slug else raise ::Liquid::SyntaxError.new("Valid syntax: #{tag_name} <slug>(, <options>)") end super end |
Instance Attribute Details
#label ⇒ Object
Returns the value of attribute label.
12 13 14 |
# File 'lib/locomotive/steam/liquid/tags/editable/base.rb', line 12 def label @label end |
#page_fullpath ⇒ Object
Returns the value of attribute page_fullpath.
12 13 14 |
# File 'lib/locomotive/steam/liquid/tags/editable/base.rb', line 12 def page_fullpath @page_fullpath end |
#slug ⇒ Object
Returns the value of attribute slug.
12 13 14 |
# File 'lib/locomotive/steam/liquid/tags/editable/base.rb', line 12 def slug @slug end |
Instance Method Details
#blank? ⇒ Boolean
60 61 62 |
# File 'lib/locomotive/steam/liquid/tags/editable/base.rb', line 60 def blank? false end |
#default_render ⇒ Object
37 |
# File 'lib/locomotive/steam/liquid/tags/editable/base.rb', line 37 alias :default_render :render |
#parse(tokens) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/locomotive/steam/liquid/tags/editable/base.rb', line 29 def parse(tokens) super.tap do ActiveSupport::Notifications.instrument("steam.parse.editable.#{@tag_name}", page: [:page], attributes: default_element_attributes) register_default_content end end |
#render(context) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/locomotive/steam/liquid/tags/editable/base.rb', line 39 def render(context) evaluate_attributes(context) service = context.registers[:services].editable_element page = fetch_page(context) block = attributes[:block] || context['block'].try(:name) # If Steam inside Wagon (test mode), we've to let the developer know # that editable_**** tags don't work if the site has declared at least one section if context['wagon'] && context.registers[:repositories].section.count > 0 Locomotive::Common::Logger.error "[#{page.fullpath}] You can't use editable elements whereas you declared section(s)".colorize(:red) end if element = service.find(page, block, slug) render_element(context, element) else Locomotive::Common::Logger.error "[#{page.fullpath}] missing #{@tag_name} \"#{slug}\" (#{context['block'].try(:name) || 'default'})".colorize(:yellow) super end end |