Class: Liquid::Extends
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
- #blank? ⇒ Boolean
-
#initialize(tag_name, markup, options) ⇒ Extends
constructor
A new instance of Extends.
- #parse(tokens) ⇒ Object
Methods inherited from Block
#block_delimiter, #block_name, #nodelist, #render, #unknown_tag, #warnings
Methods inherited from Tag
Methods included from ParserSwitching
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, ) super if markup =~ Syntax @template_name = $1.gsub(/["']/o, '').strip else raise(SyntaxError.new([:locale].t("errors.syntax.extends".freeze))) end # variables needed by the inheritance mechanism during the parsing [: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
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 |