Class: Liquid::InheritedBlock
- Defined in:
- lib/liquid/tags/inherited_block.rb
Overview
Blocks are used with the Extends tag to define the content of blocks. Nested blocks are allowed.
{% 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 collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
Attributes inherited from Tag
#line, #nodelist, #options, #warnings
Class Method Summary collapse
Instance Method Summary collapse
- #call_super(context) ⇒ Object
- #end_tag ⇒ Object
-
#initialize(tag_name, markup, tokens, options) ⇒ InheritedBlock
constructor
A new instance of InheritedBlock.
- #render(context) ⇒ Object
Methods inherited from Block
#blank?, #block_delimiter, #block_name, #create_variable, #parse, #unknown_tag, #warnings
Methods inherited from Tag
#blank?, new_with_options, #parse, #parse_with_selected_parser
Constructor Details
#initialize(tag_name, markup, tokens, options) ⇒ InheritedBlock
Returns a new instance of InheritedBlock.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/liquid/tags/inherited_block.rb', line 15 def initialize(tag_name, markup, tokens, ) if markup =~ Syntax @name = $1.gsub(/["']/o, '').strip else raise(SyntaxError.new([:locale].t("errors.syntax.block")), [:line]) end self.set_full_name!() ([:block_stack] ||= []).push(self) [:current_block] = self super if tokens end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/liquid/tags/inherited_block.rb', line 13 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
12 13 14 |
# File 'lib/liquid/tags/inherited_block.rb', line 12 def parent @parent end |
Class Method Details
.clone_block(block) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/liquid/tags/inherited_block.rb', line 52 def self.clone_block(block) new_block = self.new(block.send(:instance_variable_get, :"@tag_name"), block.name, nil, {}) new_block.parent = block.parent new_block.nodelist = block.nodelist new_block end |
Instance Method Details
#call_super(context) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/liquid/tags/inherited_block.rb', line 44 def call_super(context) if parent parent.render(context) else '' end end |
#end_tag ⇒ Object
37 38 39 40 41 42 |
# File 'lib/liquid/tags/inherited_block.rb', line 37 def end_tag self.register_current_block [:block_stack].pop [:current_block] = [:block_stack].last end |
#render(context) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/liquid/tags/inherited_block.rb', line 30 def render(context) context.stack do context['block'] = InheritedBlockDrop.new(self) render_all(@nodelist, context) end end |