Class: LiquidInheritance::Extends

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

Constant Summary collapse

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

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ Extends

Returns a new instance of Extends.



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

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?(::LiquidInheritance::Block); m
  end
end

Instance Method Details

#parse(tokens) ⇒ Object



20
21
22
# File 'lib/tags/extends.rb', line 20

def parse(tokens)
  parse_all(tokens)
end

#render(context) ⇒ Object



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

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