Permalink
Browse files

Add support for $velocityHasNext variable

  • Loading branch information...
purcell committed Sep 21, 2010
1 parent 4046fb2 commit cc862e658c05366c914c0536be05ef2b5da3db2d
Showing with 5 additions and 0 deletions.
  1. +1 −0 airspeed/__init__.py
  2. +4 −0 tests/airspeed_test.py
View
@@ -919,6 +919,7 @@ def evaluate(self, stream, namespace, loader):
for item in iterable:
namespace = LocalNamespace(namespace)
namespace['velocityCount'] = counter
+ namespace['velocityHasNext'] = counter < len(iterable)
namespace[self.loop_var_name] = item
self.block.evaluate(stream, namespace, loader)
counter += 1
View
@@ -187,6 +187,10 @@ def test_loop_counter_variables_do_not_clash_in_nested_loops(self):
namespace = {"greetings": ["Hello", "Goodbye"], "names": ["Chris", "Steve"]}
self.assertEquals("Outer 1, inner 1, inner 2. Outer 2, inner 1, inner 2. ", template.merge(namespace))
+ def test_has_next(self):
+ template = airspeed.Template("#foreach ($i in [1, 2, 3])$i. #if ($velocityHasNext)yes#end, #end")
+ self.assertEquals("1. yes, 2. yes, 3. , ", template.merge({}))
+
def test_can_use_an_integer_variable_defined_in_template(self):
template = airspeed.Template("#set ($value = 10)$value")
self.assertEquals("10", template.merge({}))

0 comments on commit cc862e6

Please sign in to comment.