wbond / pybars3

Handlebars.js template support for Python 3 and 2
GNU Lesser General Public License v3.0
179 stars 46 forks source link

Fix the way _each handles @key for dict #4

Closed adambom closed 10 years ago

adambom commented 10 years ago

Prior to this patch the following template would fail when foo was an instance of dict:

{{#each foo}}
    {{@key}}: {{this}}
{{/each}}

In the case where foo = {'bar': 'baz'} one would expect the output to be bar: baz, but instead the output is bar: bar.

The following code addresses this bug by using iter to get the iterable items of the collection, whether it be a list or a dict. If it's a dict, then local_context is set to be the value for the appropriate key before it's passed to the Scope constructor.

adambom commented 10 years ago

Closing b/c fixed in #2