Class: LiquidBlocks::Extends

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

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ Extends

Returns a new instance of Extends.



8
9
10
11
12
13
14
15
# File 'lib/liquid_blocks/extends.rb', line 8

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

Instance Attribute Details

#template_nameObject (readonly)

Returns the value of attribute template_name.



6
7
8
# File 'lib/liquid_blocks/extends.rb', line 6

def template_name
  @template_name
end

Instance Method Details

#load_template(context) ⇒ Liquid::Document

Load the template that is being extended by the current tag.

Parameters:

  • context (Liquid::Context)

    the context to use when loading the template

Returns:

  • (Liquid::Document)

    the parsed template



30
31
32
33
# File 'lib/liquid_blocks/extends.rb', line 30

def load_template(context)
  source = Liquid::Template.file_system.read_template_file(@template_name, context)
  Liquid::Template.parse(source)
end

#parse(tokens) ⇒ Object



17
18
19
# File 'lib/liquid_blocks/extends.rb', line 17

def parse(tokens)
  parse_all(tokens)
end

#render(context) ⇒ Object



21
22
23
24
# File 'lib/liquid_blocks/extends.rb', line 21

def render(context)
  origin = populate_nodelist(self, context)
  origin.render(context)
end