Module: ERBB::Receiver
- Defined in:
- lib/erbb/receiver.rb
Overview
Used to decorate the binding receiver with methods we want available in the template that are not defined on the binding receiver.
Constant Summary collapse
- RENDERED_TEMPLATE =
The name of the ivar to use for storing the rendered template output
'@_erbb_out'.freeze
Instance Method Summary collapse
-
#named_block(block_name, *args) {|args| ... } ⇒ Object
When called within a template, defines a named_block.
-
#named_blocks ⇒ Hash
The blocks.
Instance Method Details
#named_block(block_name, *args) {|args| ... } ⇒ Object
When called within a template, defines a named_block. Repeated calls to a block with the same name within a template will be concatenated in the order in which they appear in the template.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/erbb/receiver.rb', line 11 def named_block(block_name, *args, &block) # dup the output so far and save it original_output = __erbb_get_rendered_template.dup # wipe the template output ivar __erbb_set_rendered_template("") # render the block, populating the ivar with the result yield(*args) # concatenate the rendered output from the named block into the hash named_blocks[block_name.to_sym] ||= "" named_blocks[block_name.to_sym] << __erbb_get_rendered_template # restore the template output ivar to its original value plus this block __erbb_set_rendered_template(original_output + __erbb_get_rendered_template) end |
#named_blocks ⇒ Hash
Returns The blocks.
30 31 32 |
# File 'lib/erbb/receiver.rb', line 30 def named_blocks @_erbb_named_blocks ||= {} end |