Class: Burr::ExtendsTag

Inherits:
Liquid::Block
  • Object
show all
Defined in:
lib/burr/liquid_ext/extends.rb

Constant Summary collapse

Syntax =
/(#{Liquid::QuotedFragment}+)/

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ ExtendsTag

Returns a new instance of ExtendsTag.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/burr/liquid_ext/extends.rb', line 7

def initialize(tag_name, markup, tokens)
  if markup =~ Syntax
    @template_name = $1
  else
    raise Liquid::SyntaxError.new("Syntax Error in 'extends' - Valid syntax: extends [template]")
  end

  super

  @blocks = @nodelist.inject({}) do |m, node|
    m[node.name] = node if node.is_a?(Burr::BlockTag); m
  end
end

Instance Method Details

#parse(tokens) ⇒ Object



21
22
23
# File 'lib/burr/liquid_ext/extends.rb', line 21

def parse(tokens)
  parse_all(tokens)
end

#render(context) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/burr/liquid_ext/extends.rb', line 25

def render(context)
  template = load_template(context)
  parent_blocks = find_blocks(template.root)

  @blocks.each do |name, block|
    if pb = parent_blocks[name]
      pb.parent = block.parent
      pb.add_parent(pb.nodelist)
      pb.nodelist = block.nodelist
    else
      if is_extending?(template)
        template.root.nodelist << block
      end
    end
  end

  template.render(context)
end