Module: Inversion::TemplateTiltAdditions

Included in:
Template
Defined in:
lib/inversion/tilt.rb

Overview

Also add #each to Inversion::Template so they can be returned from actions directly, too.

Instance Method Summary collapse

Instance Method Details

#eachObject

TODO: Factor the common parts of this out in Inversion::Template so there’s no duplication.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/inversion/tilt.rb', line 53

def each
  self.log.info "rendering template 0x%08x (Sinatra-style)" % [ self.object_id/2 ]
  state = Inversion::RenderState.new( nil, self.attributes, self.options )

  # Pre-render hook
  self.walk_tree {|node| node.before_rendering(state) }

  self.log.debug "  rendering node tree: %p" % [ @node_tree ]
  self.walk_tree {|node| state << node }

  # Post-render hook
  self.walk_tree {|node| node.after_rendering(state) }

  self.log.info "  done rendering template 0x%08x" % [ self.object_id/2 ]
  return state.destination.each do |node|
    yield( node.to_s )
  end
end