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

Actions with bound attributes #214

Closed thec0keman closed 8 years ago

thec0keman commented 9 years ago

Passing a bound param into an action fails to quote the action name correct (0.5.0-beta branch).

This string in Emblem: button click='openItem item' test should compile to: <button {{action "openItem" item on="click"}}>Test</button> but instead compiles to: <button {{action openItem item on="click"}}>test</button>

bantic commented 9 years ago

@thec0keman This is an ambiguous part of the Emblem syntax, and may need some tweaking.

We explicitly made the decision to do it the way it is to allow someone the ability to use a bound action name if necessary (your first example above, e.g.: {{action boundActionName}}).

The rule of thumb is that if the action helper is a multi-word string, use the contents of that string exactly.

This means you could get the behavior you want by: button click="'openItem' item" compiles to: <button {{action 'openItem' item on="click"}}></button>

We'd be open to a better way to handle this, but it seemed important to allow someone to be able to use an unquoted (bound) action, and this seemed like the only way with the existing syntax.

thec0keman commented 9 years ago

That makes a lot of sense. I would suggest adding this to the readme / changelog for those making the upgrade.

andorov commented 9 years ago

It would also be good to add that something like this is possible -

  a click="actionWithParam 'fixedParamString'" foo

Single quotes are needed around the parameter and double quotes around the entire argument to click. Although until recently single quotes on the outside worked as well.

I can create a pr if you like.

bantic commented 9 years ago

@andorov yes, please

andorov commented 9 years ago

i'll add it to emblem-site

andorov commented 9 years ago

@bantic i submitted 3 pull requests. let me know if i should make any changes.

bantic commented 9 years ago

@andorov thank you — I don't have commit bit there. @machty Can you add me to emblem-site and/or merge in https://github.com/machty/emblem-site/pull/24 https://github.com/machty/emblem-site/pull/23 https://github.com/machty/emblem-site/pull/22