Class: Locomotive::Steam::Liquid::Tags::Extends
- Inherits:
-
Liquid::Block
- Object
- Liquid::Block
- Locomotive::Steam::Liquid::Tags::Extends
- Defined in:
- lib/locomotive/steam/liquid/tags/extends.rb
Overview
Extends allows designer to use template inheritance.
{% extends home %}
{% block content }Hello world{% endblock %}
Constant Summary collapse
- SYNTAX =
/(#{::Liquid::QuotedFragment}+)/o
Instance Method Summary collapse
- #blank? ⇒ Boolean
-
#initialize(tag_name, markup, options) ⇒ Extends
constructor
A new instance of Extends.
- #parse(tokens) ⇒ Object
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, markup, options) ⇒ Extends
Returns a new instance of Extends.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/locomotive/steam/liquid/tags/extends.rb', line 14 def initialize(tag_name, markup, ) super if markup =~ SYNTAX @template_name = Regexp.last_match(1).gsub(/["']/o, '').strip else raise ::Liquid::SyntaxError.new("Syntax Error in 'extends' - Valid syntax: extends <page_handle_or_parent_keyword>") 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
41 42 43 |
# File 'lib/locomotive/steam/liquid/tags/extends.rb', line 41 def blank? false end |
#parse(tokens) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/locomotive/steam/liquid/tags/extends.rb', line 30 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 |
#render(context) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/locomotive/steam/liquid/tags/extends.rb', line 45 def render(context) context.stack do context['layout_name'] = @layout_name super end end |