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}+)/o

Instance Attribute Summary

Attributes inherited from Tag

#line_number, #nodelist, #options, #warnings

Instance Method Summary collapse

Methods inherited from Block

#block_delimiter, #block_name, #nodelist, #render, #unknown_tag, #warnings

Methods inherited from Tag

#name, parse, #raw, #render

Methods included from ParserSwitching

#parse_with_selected_parser

Constructor Details

#initialize(tag_name, markup, options) ⇒ Extends

Returns a new instance of Extends.



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

def initialize(tag_name, markup, options)
  super

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

  # variables needed by the inheritance mechanism during the parsing
  options[:inherited_blocks] ||= {
    nested:   [], # used to get the full name of the blocks if nested (stack mechanism)
    all:      {}  # keep track of the blocks by their full name
  }
end

Instance Method Details

#blank?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/liquid/tags/extends.rb', line 38

def blank?
  false
end

#parse(tokens) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/liquid/tags/extends.rb', line 27

def parse(tokens)
  super

  parent_template = parse_parent_template

  # replace the nodes of the current template by those from the parent
  # which itself may have have done the same operation if it includes
  # the extends tag.
  nodelist.replace(parent_template.root.nodelist)
end