Class: Ruty::Tags::Extends

Inherits:
Ruty::Tag show all
Defined in:
lib/ruty/tags/inheritance.rb

Overview

tag used to load a template from another file. must be the first tag of a document!

Instance Method Summary collapse

Constructor Details

#initialize(parser, argstring) ⇒ Extends

Returns a new instance of Extends.


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ruty/tags/inheritance.rb', line 54

def initialize parser, argstring
  if not parser.first
    parser.fail('extends tag must be at the beginning of a template')
  elsif not argstring =~ /^(["'])(.*?)\1$/
    parser.fail('extends takes exactly one argument which must be ' +
                'an hardcoded string')
  end

  # parse the template to the end and load parent nodelist
  parser.parse_all
  @nodelist = parser.load_local(argstring[1...-1])
  blocks = @nodelist.parser.storage[:blocks] || {}

  # iterate over all blocks found while parsing and add them
  # to the parent nodelist which will be the new nodelist
  (parser.storage[:blocks] || []).each do |name, tag|
    blocks[name].add_layer(tag) if blocks.include?(name)
  end
end

Instance Method Details

#render_node(context, stream) ⇒ Object


74
75
76
# File 'lib/ruty/tags/inheritance.rb', line 74

def render_node context, stream
  @nodelist.render_node(context, stream)
end