Class: Locomotive::Steam::Liquid::Tags::Editable::Base

Inherits:
Liquid::Block
  • Object
show all
Includes:
Concerns::Attributes
Defined in:
lib/locomotive/steam/liquid/tags/editable/base.rb

Direct Known Subclasses

Control, File, Model, Text

Constant Summary collapse

Syntax =
/(#{::Liquid::QuotedFragment})(\s*,\s*#{::Liquid::Expression}+)?/o

Instance Attribute Summary collapse

Attributes included from Concerns::Attributes

#attributes, #raw_attributes

Instance Method Summary collapse

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, options)
  if markup =~ Syntax
    @page_fullpath    = options[: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

#labelObject

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_fullpathObject

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

#slugObject

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

Returns:

  • (Boolean)


60
61
62
# File 'lib/locomotive/steam/liquid/tags/editable/base.rb', line 60

def blank?
  false
end

#default_renderObject



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: options[: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