Class: H2o::Tags::Block

Inherits:
Tag show all
Defined in:
lib/h2o/tags/block.rb

Overview

Block tag allows to divide document into reusable blocks

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parser, argstring) ⇒ Block

Returns a new instance of Block.

Raises:



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

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/h2o/tags/block.rb', line 6

def name
  @name
end

#parentObject

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_sizeObject



17
18
19
# File 'lib/h2o/tags/block.rb', line 17

def stack_size
  @stack.size
end