Commits

Michael Granger committed 24563ed

Fixing a problem with non-array values in the for tag

Comments (0)

Files changed (2)

lib/inversion/template/fortag.rb

 
 		# Loop will exit as soon as the Enumerator runs out of elements
 		loop do
-			args = Array( lvalue.next )
-			# self.log.debug "  iterated block args are: %p" % [ args ]
+			args = lvalue.next
+			args = [ args ] unless args.is_a?( Array )
 
 			# Turn the block arguments into an overrides hash by zipping up
 			# the arguments names and values

spec/inversion/template/fortag_spec.rb

 			render_state.to_s.should =~ /ch \(1\) => ch/
 		end
 
+		it "preserves an array of subhashes" do
+			tree = Inversion::Parser.new( nil ).parse( <<-"END_TEMPLATE" )
+			<?for subhash in the_hash[:a] ?>
+				Subhash is a <?call subhash.class.name ?>
+			<?end for ?>
+			END_TEMPLATE
+
+			# Drop the non-container nodes at the beginning and end
+			tree.delete_if {|node| !node.container? }
+
+			the_hash = { :a => [ { :b => 'foo', :c => 'bar' }, { :d => 'blah', :e => 'blubb'} ] }
+
+			render_state = Inversion::RenderState.new( :the_hash => the_hash )
+			tree.first.render( render_state )
+
+			render_state.to_s.should =~ /Subhash is a Hash/i
+		end
+
 	end