Class: H2o::Tags::Block
Overview
Block tag allows to divide document into reusable blocks
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #add_layer(nodelist) ⇒ Object
-
#initialize(parser, argstring) ⇒ Block
constructor
A new instance of Block.
- #render(context, stream, index = -1) ⇒ Object
- #stack_size ⇒ Object
Constructor Details
#initialize(parser, argstring) ⇒ Block
Returns a new instance of Block.
9 10 11 12 13 14 15 |
# File 'lib/h2o/tags/block.rb', line 9 def initialize parser, argstring @name = argstring.to_sym @stack = [ parser.parse(:endblock) ] blocks = parser.storage[:blocks] ||= {} raise SyntaxError, "block name needs to be unique" if blocks.include? @name blocks[@name] = self end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/h2o/tags/block.rb', line 6 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
7 8 9 |
# File 'lib/h2o/tags/block.rb', line 7 def parent @parent end |
Instance Method Details
#add_layer(nodelist) ⇒ Object
21 22 23 |
# File 'lib/h2o/tags/block.rb', line 21 def add_layer nodelist @stack << nodelist end |
#render(context, stream, index = -1) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/h2o/tags/block.rb', line 25 def render context, stream, index=-1 context.stack do context[:block] = BlockContext.new(self, context, stream, index) @stack[index].render(context, stream) end end |
#stack_size ⇒ Object
17 18 19 |
# File 'lib/h2o/tags/block.rb', line 17 def stack_size @stack.size end |