mustache / spec

The Mustache spec.
MIT License
364 stars 71 forks source link

Nested Behaviors #94

Closed andrewthad closed 10 months ago

andrewthad commented 8 years ago

This originally came up in an issue for a haskell mustache implementation, (https://github.com/JustusAdam/mustache/issues/6) but I will describe a simpler example here with language-agnostic terminology.

Suppose that I have data represented in YAML as follows:

people:
  - person_name: Andrew
    person_age: 24
    dogs:
      - dog_name: Rover
        dog_weight: 42
      - dog_name: Gnarles Barkley
        dog_weight: 10
  - person_name: Bob
    person_age: 63
    dogs:
      - dog_name: Trixie
      - dog_weight: 20

And a template that looks like this:

Everyone's dogs
{{people}}
{{dogs}}
The dog {{dog_name}} belongs to {{person_name}}.
{{/dogs}}
{{/people}}

The output I expect (modulo some newlines) is:

The dog Rover belongs to Andrew.
The dog Gnarles Barkley belongs to Andrew.
The dog Trixie belongs to Bob.

However, the haskell mustache implementation, which completely passes version 1.1.3 of the specs, would give me this:

The dog Rover belongs to .
The dog Gnarles Barkley belongs to .
The dog Trixie belongs to .

So, I propose adding a spec test that would assure that bound variables remain bound in a nested section. Please let me know if I can clarify this further.

groue commented 8 years ago

Doesn't https://github.com/mustache/spec/blob/83b0721610a4e11832e83df19c73ace3289972b9/specs/sections.yml#L56-L93 test for that? Hm. That test doesn't actually involves an array (dogs), and that's may be why JustusAdam/mustache passes all tests and missed this case.

andrewthad commented 8 years ago

As it turns out, the simplified example that I gave above doesn't actually cause problems with https://github.com/JustusAdam/mustache. After playing around with my original failing case some more, I've come up with this: https://github.com/mustache/spec/pull/95/files

The issue that https://github.com/JustusAdam/mustache has is that it renders 1.1x.1y instead of a1.A1x.A1y. So the problem is that, within a list section, the elements on the context stack that are hashmaps are forgotten (but strings are fine, which is why my original simplified example doesn't actually create any problems).

andrewthad commented 8 years ago

Is this anything preventing my PR from being merged in? https://github.com/mustache/spec/pull/95/files

groue commented 8 years ago

You need to grab the attention of a repo maintainer, which I'm not.

jgonggrijp commented 10 months ago

Closing as this seems to have been addressed with #114.