chevron
chevron copied to clipboard
List rendering does not work with view objects
I'm trying to use chevron in my project, where I was previously using pystache. Pystache was really flexible in what I could pass to it, and it would treat anything as a list, that can be iterated on. While changing to chevron, however, I found that I have to wrap a lot of stuff with list(), mostly dict .keys()/.values() views.
Minimal repro from pyhon console:
import chevron
ctx = {'template': '{{#list}}{{.}}{{/list}}', 'data':{'list': {'foo': 'bar', 'baz': 'foobar'}.values()}}
chevron.render(**ctx)
"dict_values(['bar', 'foobar'])"
ctx = {'template': '{{#list}}{{.}}{{/list}}', 'data':{'list': list({'foo': 'bar', 'baz': 'foobar'}.values())}}
chevron.render(**ctx)
'barfoobar'
I'm using Python 3.7.3
List rendering does not seem to work at all (at least in Python 3.9.5):
import chevron
import pystache
data = {
'members': [
{ 'name': 'M1' },
{ 'name': 'M2' },
{ 'name': 'M3' },
]
}
tmpl = '''
{{ #members }}
- {{ name }}
{{ /members }}
'''
print('PyStache', pystache.render(tmpl, data))
print('Chevron', chevron.render(tmpl, data))
This results in
PyStache
- M1
- M2
- M3
Chevron
-
The PyStache output is what I would expect.