Class: Liquid2::ExtendsTag

Inherits:
Tag
  • Object
show all
Defined in:
lib/liquid2/nodes/tags/extends.rb

Overview

The extends tag.

Instance Attribute Summary collapse

Attributes inherited from Node

#blank, #token

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Tag

#name

Methods inherited from Node

#block_scope, #expressions, #render_with_disabled_tag_check, #template_scope

Constructor Details

#initialize(token, name) ⇒ ExtendsTag

Returns a new instance of ExtendsTag.



20
21
22
23
24
# File 'lib/liquid2/nodes/tags/extends.rb', line 20

def initialize(token, name)
  super(token)
  @template_name = name
  @blank = false
end

Instance Attribute Details

#template_nameObject (readonly)

Returns the value of attribute template_name.



8
9
10
# File 'lib/liquid2/nodes/tags/extends.rb', line 8

def template_name
  @template_name
end

Class Method Details

.parse(token, parser) ⇒ ExtendsTag

Parameters:

  • token ([Symbol, String?, Integer])
  • parser (Parser)

Returns:



13
14
15
16
17
18
# File 'lib/liquid2/nodes/tags/extends.rb', line 13

def self.parse(token, parser)
  name = parser.parse_name
  parser.carry_whitespace_control
  parser.eat(:token_tag_end)
  new(token, name)
end

Instance Method Details

#children(static_context, include_partials: true) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/liquid2/nodes/tags/extends.rb', line 35

def children(static_context, include_partials: true)
  return [] unless include_partials

  begin
    parent = static_context.env.get_template(
      @template_name,
      context: static_context,
      tag: "extends"
    )
    parent.ast
  rescue LiquidTemplateNotFoundError => e
    e.token = @token
    e.template_name = static_context.template.full_name
    raise e
  end
end

#partial_scopeObject



52
53
54
# File 'lib/liquid2/nodes/tags/extends.rb', line 52

def partial_scope
  Partial.new(@template_name, :inherited, [])
end

#render(context, buffer) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/liquid2/nodes/tags/extends.rb', line 26

def render(context, buffer)
  base_template = stack_blocks(context, context.template)
  context.extend({}, template: base_template) do
    base_template&.render_with_context(context, buffer)
  end
  context.tag_namespace[:extends].clear
  context.interrupts << :stop_render
end