elif tag == 'variable':
# Add the html escaped key to the output
thing = _get_key(key, scopes)
+ if thing is True and key == '.':
+ # if we've coerced into a boolean by accident
+ # (inverted tags do this)
+ # then get the un-coerced object (next in the stack)
+ thing = scopes[1]
if type(thing) != unicode:
thing = unicode(str(thing), 'utf-8')
output += _html_escape(thing)
self.assertEqual(result, expected)
+ # https://github.com/noahmorrison/chevron/issues/17
+ def test_inverted_coercion(self):
+ args = {
+ 'template': '{{#object}}{{^child}}{{.}}{{/child}}{{/object}}',
+ 'data': {'object': [
+ 'foo', 'bar', {'child': True}, 'baz'
+ ]}
+ }
+
+ result = chevron.render(**args)
+ expected = 'foobarbaz'
+
+ self.assertEqual(result, expected)
+
# Run unit tests from command line
if __name__ == "__main__":