machty / emblem.js

Emblem.js - Ember-friendly, indented syntax alternative for Handlebars.js
http://emblemjs.com
MIT License
1.04k stars 81 forks source link

Unbound shorthand (!) failing in some cases #218

Closed asermax closed 5 years ago

asermax commented 9 years ago

Used to have img src=model.coverImage! on an emblem template, but after started using ember-cli-emblem-hbs-printer it stopped working.

I was also using the shorthand in some other places (literally everywhere I wanted some unbound values) and the previous version seemed happy to complain, though now that I went through the syntax documentation again it aparently is only valid within HTML attributes.

Is the shorthand no longer valid?

asermax commented 9 years ago

Actually, I found out that it's working correctly on other templates, so it seems something specific to that template. It's really strange since img src='{{ unbound model.coverImage }}' works correctly, which is supposedly equivalent to what the shorthand does.

bantic commented 9 years ago

@asermax I wonder if Emblem is compiling in the "!" rather than making it an unbound property. I'll investigate this.

bantic commented 9 years ago

@asermax You can use the try emblem site to see how Emblem will deal with different strings.

img src=model.coverImage! => <img src="{{unbound coverImage}}">, which seems like it should be working.

You can try pasting in your entire template to the "try emblem" site linked above to see if that helps diagnose the issue.

asermax commented 9 years ago

Nice, that web makes debugging the template a lot easier, thanks.

Looks like the issue is that the generated Handlebars template doesn't respect the full path to the property, it only takes the last part of the path into account. For example img src=model.foo.bar.coverImage! generates <img src="{{unbound coverImage}}"> too, making the issue more obvious. Using the shorthand outside a html property works correctly tho: h3 = model.coverImage! outputs <h3>{{unbound model.coverImage}}</h3>.

My particular issue came up because for that specific template there was a simple Controller backing it up (we started migrating our controllers given the upcoming ObjectController deprecation), while the other templates where it did work, didn't have a explicit controller, so Ember was autogenerating a ObjectController which proxied the property to the model even if emblem ignored the rest of the path.

Hope this helps fix the issue.

bantic commented 9 years ago

@asermax Yes, thank you, I missed that before. I've added a sample failing test in 835c94e, will take a look at this later on.