Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add support for $velocityHasNext variable

  • Loading branch information...
commit cc862e658c05366c914c0536be05ef2b5da3db2d 1 parent 4046fb2
@purcell authored
Showing with 5 additions and 0 deletions.
  1. +1 −0  airspeed/__init__.py
  2. +4 −0 tests/airspeed_test.py
View
1  airspeed/__init__.py
@@ -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
4 tests/airspeed_test.py
@@ -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({}))
Please sign in to comment.
Something went wrong with that request. Please try again.