Class: Liquid::Extends

Inherits:
Block show all
Defined in:
lib/liquid/tags/extends.rb

Overview

Extends allows designer to use template inheritance

{% extends home %}
{% block content }Hello world{% endblock %}

Constant Summary collapse

Syntax =
/(#{QuotedFragment}+)/

Constants inherited from Block

Block::ContentOfVariable, Block::FullToken, Block::IsTag, Block::IsVariable

Instance Attribute Summary

Attributes inherited from Tag

#line, #nodelist, #options, #warnings

Instance Method Summary collapse

Methods inherited from Block

#block_delimiter, #block_name, #create_variable, #parse, #render, #unknown_tag, #warnings

Methods inherited from Tag

#name, new_with_options, #parse, #parse_with_selected_parser, #render

Constructor Details

#initialize(tag_name, markup, tokens, options) ⇒ Extends

Returns a new instance of Extends.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/liquid/tags/extends.rb', line 11

def initialize(tag_name, markup, tokens, options)
  if markup =~ Syntax
    @template_name = $1.gsub(/["']/o, '').strip
  else
    raise(SyntaxError.new(options[:locale].t("errors.syntax.extends")), options[:line])
  end

  @options = options

  @parent_template = parse_parent_template

  prepare_parsing

  super

  end_tag
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/liquid/tags/extends.rb', line 40

def blank?
  false
end

#end_tagObject



33
34
35
36
37
38
# File 'lib/liquid/tags/extends.rb', line 33

def end_tag
  # replace the nodelist by the new one
  @nodelist = @parent_template.root.nodelist.clone

  @parent_template = nil # no need to keep it
end

#prepare_parsingObject



29
30
31
# File 'lib/liquid/tags/extends.rb', line 29

def prepare_parsing
  @options.merge!(:blocks => self.find_blocks(@parent_template.root.nodelist))
end