Class: Locomotive::Steam::Liquid::Tags::Section

Inherits:
Liquid::Include
  • Object
show all
Includes:
Concerns::Attributes, Concerns::Section
Defined in:
lib/locomotive/steam/liquid/tags/section.rb

Direct Known Subclasses

GlobalSection

Constant Summary collapse

Syntax =
/(#{::Liquid::QuotedString}|#{::Liquid::VariableSignature}+)\s*,*(.*)?/o.freeze

Instance Attribute Summary collapse

Attributes included from Concerns::Attributes

#attributes, #raw_attributes

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, options) ⇒ Section

Returns a new instance of Section.



14
15
16
17
18
19
20
21
22
23
# File 'lib/locomotive/steam/liquid/tags/section.rb', line 14

def initialize(tag_name, markup, options)
  super

  if markup =~ Syntax
    @section_type, _attributes = $1, $2
    @template_name_expr = @section_type.gsub!(/['"]/, '')

    parse_attributes(_attributes)
  end
end

Instance Attribute Details

#section_typeObject (readonly)

Returns the value of attribute section_type.



12
13
14
# File 'lib/locomotive/steam/liquid/tags/section.rb', line 12

def section_type
  @section_type
end

Instance Method Details

#parse(tokens) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/locomotive/steam/liquid/tags/section.rb', line 25

def parse(tokens)
  notify_on_parsing(section_type,
    id:         "page-#{attributes[:id] || section_type}",
    key:        (attributes[:id] || section_type).to_s,
    label:      attributes[:label],
    placement:  attributes[:placement]&.to_sym
  )
end

#render(context) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/locomotive/steam/liquid/tags/section.rb', line 34

def render(context)
  evaluate_attributes(context)

  # the context (parsing) doesn't include the page key if cache is on
  parse_context[:page] = context.registers[:page]

  # use the Liquid filesystem to get the template of the section
  template = parse_template(section_type, context)

  # fetch the section definition
  section = find_section(context)

  # if the tag is called by the Section middleware, use the content
  # from the request.
  content = context.registers[:_section_content]

  # if no content from the middleware, go get it from the page
  content ||= find_section_content(context)

  context.stack do
    set_section_dom_id(context)
    render_section(context, template, section, content)
  end
end