# If we're a variable tag
elif tag == 'variable':
# Add the html escaped key to the output
- thing = _get_key(key, scopes, warn=warn, keep=keep, def_ldel=def_ldel, def_rdel=def_ldel)
+ thing = _get_key(key, scopes, warn=warn, keep=keep, def_ldel=def_ldel, def_rdel=def_rdel)
if thing is True and key == '.':
# if we've coerced into a boolean by accident
# (inverted tags do this)
# If we're a no html escape tag
elif tag == 'no escape':
# Just lookup the key and add it
- thing = _get_key(key, scopes, warn=warn, keep=keep, def_ldel=def_ldel, def_rdel=def_ldel)
+ thing = _get_key(key, scopes, warn=warn, keep=keep, def_ldel=def_ldel, def_rdel=def_rdel)
if not isinstance(thing, unicode_type):
thing = unicode(str(thing), 'utf-8')
output += thing
# If we're a section tag
elif tag == 'section':
# Get the sections scope
- scope = _get_key(key, scopes, warn=warn, keep=keep, def_ldel=def_ldel, def_rdel=def_ldel)
+ scope = _get_key(key, scopes, warn=warn, keep=keep, def_ldel=def_ldel, def_rdel=def_rdel)
# If the scope is a callable (as described in
# https://mustache.github.io/mustache.5.html)
# If we're an inverted section
elif tag == 'inverted section':
# Add the flipped scope to the scopes
- scope = _get_key(key, scopes, warn=warn, keep=keep, def_ldel=def_ldel, def_rdel=def_ldel)
+ scope = _get_key(key, scopes, warn=warn, keep=keep, def_ldel=def_ldel, def_rdel=def_rdel)
scopes.insert(0, not scope)
# If we're a partial
self.assertEqual(resultEmpty, expected)
os.chdir('..')
+ # https://github.com/noahmorrison/chevron/pull/94
+ def test_keep(self):
+ args = {
+ 'template': '{{ first }} {{ second }} {{ third }}',
+ 'data': {
+ "first": "1st",
+ "third": "3rd",
+ },
+ }
+
+ result = chevron.render(**args)
+ expected = '1st 3rd'
+ self.assertEqual(result, expected)
+
+ args['keep'] = True
+
+ result = chevron.render(**args)
+ expected = '1st {{ second }} 3rd'
+ self.assertEqual(result, expected)
+
+ args['template'] = '{{first}} {{second}} {{third}}'
+ result = chevron.render(**args)
+ expected = '1st {{ second }} 3rd'
+ self.assertEqual(result, expected)
+
+ args['template'] = '{{ first }} {{ second }} {{ third }}'
+ result = chevron.render(**args)
+ expected = '1st {{ second }} 3rd'
+ self.assertEqual(result, expected)
+
+ # https://github.com/noahmorrison/chevron/pull/94
+ def test_keep_from_partials(self):
+ args = {
+ 'template': '{{ first }} {{> with_missing_key }} {{ third }}',
+ 'data': {
+ "first": "1st",
+ "third": "3rd",
+ },
+ 'partials_dict': {
+ 'with_missing_key': '{{missing_key}}',
+ },
+ }
+
+ result = chevron.render(**args)
+ expected = '1st 3rd'
+ self.assertEqual(result, expected)
+
+ args['keep'] = True
+
+ result = chevron.render(**args)
+ expected = '1st {{ missing_key }} 3rd'
+ self.assertEqual(result, expected)
+
# Run unit tests from command line
if __name__ == "__main__":