Class: Locomotive::Steam::Liquid::Tags::Editable::Base
- Inherits:
-
Liquid::Block
- Object
- Liquid::Block
- Locomotive::Steam::Liquid::Tags::Editable::Base
show all
- 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
Instance Method Summary
collapse
Constructor Details
#initialize(tag_name, markup, options) ⇒ Base
Returns a new instance of Base.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/locomotive/steam/liquid/tags/editable/base.rb', line 12
def initialize(tag_name, markup, options)
if markup =~ Syntax
@page_fullpath = options[:page].fullpath
@label_or_slug = $1.gsub(/[\"\']/, '')
@element_options = { fixed: false, inline_editing: true }
markup.scan(::Liquid::TagAttributes) { |key, value| @element_options[key.to_sym] = value.gsub(/^[\"\']/, '').gsub(/[\"\']$/, '') }
self.set_label_and_slug
else
raise ::Liquid::SyntaxError.new("Valid syntax: #{tag_name} <slug>(, <options>)")
end
super
end
|
Instance Attribute Details
#slug ⇒ Object
Returns the value of attribute slug.
10
11
12
|
# File 'lib/locomotive/steam/liquid/tags/editable/base.rb', line 10
def slug
@slug
end
|
Instance Method Details
#blank? ⇒ Boolean
50
51
52
|
# File 'lib/locomotive/steam/liquid/tags/editable/base.rb', line 50
def blank?
false
end
|
#default_render ⇒ Object
35
|
# File 'lib/locomotive/steam/liquid/tags/editable/base.rb', line 35
alias :default_render :render
|
#parse(tokens) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/locomotive/steam/liquid/tags/editable/base.rb', line 27
def parse(tokens)
super.tap do
ActiveSupport::Notifications.instrument("steam.parse.editable.#{@tag_name}", page: options[:page], attributes: default_element_attributes)
register_default_content
end
end
|
#render(context) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/locomotive/steam/liquid/tags/editable/base.rb', line 37
def render(context)
service = context.registers[:services].editable_element
page = fetch_page(context)
block = @element_options[:block] || context['block'].try(:name)
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'})"
super
end
end
|