Skip to content
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

Tags with whitespace before the value are not allowed #10

Closed
sethladd opened this issue Jan 30, 2015 · 4 comments
Closed

Tags with whitespace before the value are not allowed #10

sethladd opened this issue Jan 30, 2015 · 4 comments

Comments

@sethladd
Copy link
Contributor

Not sure if this is by design.

This works:

{{ foo.bar }}

(notice the whitespace)

This does not work:

{{ #foo.bar }}

But this does work:

{{#foo.bar}}

@xxgreg
Copy link
Owner

xxgreg commented Feb 3, 2015

I can't reproduce this. Could you send me some code. The tests below all pass.

test('Whitespace in section tags', () {
  expect(parse('{{#foo.bar}}oi{{/foo.bar}}').renderString({'foo': {'bar': true}}), equals('oi'));
  expect(parse('{{# foo.bar}}oi{{/foo.bar}}').renderString({'foo': {'bar': true}}), equals('oi'));
  expect(parse('{{#foo.bar }}oi{{/foo.bar}}').renderString({'foo': {'bar': true}}), equals('oi'));
  expect(parse('{{# foo.bar }}oi{{/foo.bar}}').renderString({'foo': {'bar': true}}), equals('oi'));
  expect(parse('{{#foo.bar}}oi{{/ foo.bar}}').renderString({'foo': {'bar': true}}), equals('oi'));
  expect(parse('{{#foo.bar}}oi{{/foo.bar }}').renderString({'foo': {'bar': true}}), equals('oi'));
  expect(parse('{{#foo.bar}}oi{{/ foo.bar }}').renderString({'foo': {'bar': true}}), equals('oi'));
  expect(parse('{{# foo.bar }}oi{{/ foo.bar }}').renderString({'foo': {'bar': true}}), equals('oi'));

});

test('Whitespace in variable tags', () {
  expect(parse('{{foo.bar}}').renderString({'foo': {'bar': true}}), equals('true'));
  expect(parse('{{ foo.bar}}').renderString({'foo': {'bar': true}}), equals('true'));
  expect(parse('{{foo.bar }}').renderString({'foo': {'bar': true}}), equals('true'));
  expect(parse('{{ foo.bar }}').renderString({'foo': {'bar': true}}), equals('true'));
});

xxgreg added a commit that referenced this issue Feb 3, 2015
@xxgreg
Copy link
Owner

xxgreg commented Feb 3, 2015

I'm guessing you meant this:

{{ #libraries }} ... {{ /libraries }}

By my reading of the mustache spec these are two variable tags which looks up a variable named '#libraries' and '/libraries'.

For example:

 render('{{ #libraries }} + {{ /libraries }} = 3', {'#libraries': 1, '/libraries': 2});

Should result in "1 + 2 = 3".

But there are discussions about how to specify this:

mustache/spec#67

If you want to have portable template code it sounds like the best solution is to do it this way:

{{# libraries }} ... {{/ libraries }}

@xxgreg
Copy link
Owner

xxgreg commented Feb 3, 2015

I checked pystache and node.js mustache they both treat the following as a section. So I guess instead of following the spec, I'll do as the other implementations do.

{{ #libraries }} ... {{ /libraries }}

I've implemented this, including adding a bunch of tests for strange corner cases.

@xxgreg xxgreg closed this as completed Feb 3, 2015
@sethladd
Copy link
Contributor Author

sethladd commented Feb 3, 2015

Ack, sorry, I mis-typed my original description. I've updated the description. You indeed did figure out what I was trying to say :)

Thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants