-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarification on root-level implicit iterators #87
Comments
Exceptions are not good: it would be better if And yes, the spec needs a clarification on that. |
Is there a process for proposing the change? Do I just open a PR? I think the right thing here is to add the And add this test to it, as well: - name: Implicit Iterator - Root-level
desc: Implicit iterators should work on root-level lists.
data: [ { value: 'a' }, { value: 'b' } ]
template: '"{{#.}}({{value}}){{/.}}"'
expected: '"(a)(b)"' Not sure if it makes sense to add test(s) to the interpolation spec, too, e.g: - name: Dotted Names - Single Period
desc: A single period should resolve to the top of the context stack.
data:
name: 'Alice'
template: '{{#name}}({{.}}){{/name}}'
expected: '(Alice)'
- name: Dotted Names - Root-level Single Period
desc: A single period at the root level should resolve to the passed-in data.
data: 'Alice'
template: '"{{.}}"'
expected: '"Alice"' In particular, I can imagine that last one might not be reasonable for a lot of implementations. |
Any updates or feedback on this? Anyone? |
The repo maintainers have not given a sign of life for years. |
:( |
This does not mean that Hogan itself is not maintained! |
Oh, for sure. I have an actual PR sitting (equally long) over there. |
Based on the discussion at mustache#87 (comment) Signed-off-by: Kevin Locke <kevin@kevinlocke.name>
@Mr0grog We have active maintenance again and I encourage you to submit a pull request with the clarifications that you have in mind. |
Oh wow, I haven’t thought about this issue in ages! Will try to bring myself back up to speed on this and submit something when I have time. (If someone else watching is more actively experiencing this and is more up-to-speed, feel free to take this on.) |
Mustache.php does the "right thing" with the previous examples, as well as this monstrosity: - name: Shenanigans
desc: This is silly, but should be allowed.
data: [ 'a', 'b' ]
template: '"{{#.}}({{.}}){{/.}}"'
expected: '"(a)(b)"' … to be honest I don't hate it? I mean, you shouldn't use it. But it's consistent. I don't hate that it's possible. |
Since some implementations differ on whether the root of the context stack can be iterated over, this adds langauge to the "Sections" spec clarifying that it can. It also adds a test for this case. Fixes mustache#87. I did not add the two additional tests for the "Interpolation" spec that I recommended in that issue, since there are tests that cover them now (not sure if these are new or if I just missed them before).
@jgonggrijp OK, I added a PR for this in #176. I changed the spec language in a slightly different way from what I proposed here, but I think it’s better. The two extra tests I suggested adding to the "Interpolation" spec already exist now, so I skipped them (not sure if I missed them before or if they are new). |
Can the implicit iterator be used to iterate over a list if that list is the root level item on the context stack? e.g. should this:
{{#.}} {{name}} {{/.}}
work with this data:[{name: Alice}, {name: Bob}]
to generate:Alice Bob
?From a reading of the interpolation spec it sounds like it should:
But there’s actually no mention of implicit iterators in the descriptive part of the sections spec and the tests it contains do not cover this case. It just so happens that some implementations also have conflicting behavior here.
I recently finished switching all of a client’s Mustache.js-rendered templates to being precompiled with Hogan.js. In Mustache, the scenario described above works fine, but in Hogan it does not. In a true test of Murphy’s Law, I ran afoul of this issue during the switch.
It would be great to get some clarification in the tests themselves and, ideally, in the descriptive part of the spec as well.
Hogan has a long-standing bug for this; some clarity from this spec would probably go a long way towards resolving the issue, either by forcing Hogan to change through failing tests or by clarifying that behavior isn’t one Hogan needs to support.
The text was updated successfully, but these errors were encountered: