Class: LiquidBlocks::Extends
- Inherits:
-
Liquid::Block
- Object
- Liquid::Block
- LiquidBlocks::Extends
- Defined in:
- lib/liquid_blocks/extends.rb
Constant Summary collapse
- Syntax =
/(#{Liquid::QuotedFragment}+)/
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens) ⇒ Extends
constructor
A new instance of Extends.
- #parse(tokens) ⇒ Object
- #render(context) ⇒ Object
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/liquid_blocks/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?(::LiquidBlocks::Block); m end end |
Instance Method Details
#parse(tokens) ⇒ Object
20 21 22 |
# File 'lib/liquid_blocks/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/liquid_blocks/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 |