Sha256: 72d66d5ebc38bd27a7b4ef3343293e128b04b8f91cf0d0d88eeb78660a5ec824
Contents?: true
Size: 1 KB
Versions: 2
Compression:
Stored size: 1 KB
Contents
module Trestle class Toolbar extend ActiveSupport::Autoload autoload :Builder autoload :Context def initialize(builder=Builder) @builder = builder @blocks = [] end def groups(template, *args) Enumerator.new do |y| @blocks.each do |block| builder = @builder.new(template, *args) block.evaluate(builder, template, y, *args) end end end def append(&block) @blocks.push(Block.new(&block)) end def prepend(&block) @blocks.unshift(Block.new(&block)) end # Wraps a toolbar block to provide evaluation within the context of a template and enumerator class Block def initialize(&block) @block = block end 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 end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
trestle-0.8.11 | lib/trestle/toolbar.rb |
trestle-0.8.10 | lib/trestle/toolbar.rb |