Class: Aerogel::Render::BlockHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/aerogel/core/render/block_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ BlockHelper

Creates a block helper object. args will be passed to the block as arguments.



14
15
16
17
18
19
20
# File 'lib/aerogel/core/render/block_helper.rb', line 14

def initialize( *args, &block )
  @args = args
  @block = block

  # makes methods and helpers accessible at the self instance scope
  @self_before_instance_eval = eval "self", @block.binding
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



40
41
42
# File 'lib/aerogel/core/render/block_helper.rb', line 40

def method_missing(method, *args, &block)
  @self_before_instance_eval.send method, *args, &block
end

Instance Method Details

#renderObject

Renders output to the template or returns it as a string.



32
33
34
35
36
37
38
# File 'lib/aerogel/core/render/block_helper.rb', line 32

def render
  content = output_capture(@block) do
    instance_exec( *@args, &@block )
  end
  content_wrapped = output_capture() { wrap( content ) }
  output_concat content_wrapped
end

#wrap(content) ⇒ Object

Wraps captured content with custom tags or text. Most of the time, method should be redefined by descendant class. A good example would be a form helper, that surrounds captured content with <form ..></form> tags.



26
27
28
# File 'lib/aerogel/core/render/block_helper.rb', line 26

def wrap( content )
  content
end