Inversion 'for' tag.
Iteration tag for outputting a template part for each member of a collection (i.e., an object that is Enumerable).
<?for var in attribute ?> <?for var in attribute.methodchain ?> <?for var1, var2 in attribute.methodchain ?>
<?for employee in company.employees ?> Hey <?call employee.name ?>! You're fired! <?end ?>
Create a new ForTag with the specified body.
# File lib/inversion/template/fortag.rb, line 62 def initialize( body, linenum=nil, colnum=nil ) @block_args = [] @enumerator = nil super( 'for ' + body, linenum, colnum ) end
Render the tag as the body of a comment, suitable for template debugging.
# File lib/inversion/template/fortag.rb, line 106 def as_comment_body comment = "%s: { %s IN template.%s }" % [ self.tagname, self.block_args.join(', '), self.enumerator ] return comment end
Iterate over the enumerator in state and render the tag's contents for each iteration.
# File lib/inversion/template/fortag.rb, line 84 def render( state ) lvalue = state.eval( self.enumerator ) or return nil self.log.debug "Rendering %p via block args: %p" % [ lvalue, self.block_args ] lvalue.each do |*args| # Turn the block arguments into an overrides hash by zipping up # the arguments names and values overrides = Hash[ self.block_args.zip(args) ] # Overlay the block args from the 'for' over the template attributes and render # each subnode state.with_attributes( overrides ) do super end end return nil end
Generated with the Darkfish Rdoc Generator 2.