Class: Trestle::Toolbar::Block

Inherits:
Object
  • Object
show all
Defined in:
lib/trestle/toolbar.rb

Overview

Wraps a toolbar block to provide evaluation within the context of a template and enumerator

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Block

Returns a new instance of Block.



36
37
38
# File 'lib/trestle/toolbar.rb', line 36

def initialize(&block)
  @block = block
end

Instance Method Details

#evaluate(builder, template, enumerator, *args) ⇒ Object



40
41
42
43
44
# File 'lib/trestle/toolbar.rb', line 40

def evaluate(builder, template, enumerator, *args)
  context = Context.new(builder, enumerator, *args)
  result = template.capture { template.instance_exec(context, *args, &@block) }
  enumerator << [result] if result.present?
end