Skip to content

Commit

Permalink
Merge pull request #13359 from rwjblue/link-subexpr-helpers
Browse files Browse the repository at this point in the history
[BUGFIX beta] Fix subexpr `{{if}}` / `{{unless}}` to use protocol.
  • Loading branch information
rwjblue committed Apr 18, 2016
2 parents 97a2d96 + dd38937 commit fd69421
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ moduleFor('Helpers test: inline {{if}}', class extends TogglingHelperConditional

});

moduleFor('@glimmer Helpers test: nested {{if}} helpers (returning truthy values)', class extends TogglingHelperConditionalsTest {
moduleFor('Helpers test: nested {{if}} helpers (returning truthy values)', class extends TogglingHelperConditionalsTest {

templateFor({ cond, truthy, falsy }) {
return `{{if (if ${cond} ${cond} false) ${truthy} ${falsy}}}`;
}

});

moduleFor('@glimmer Helpers test: nested {{if}} helpers (returning falsy values)', class extends TogglingHelperConditionalsTest {
moduleFor('Helpers test: nested {{if}} helpers (returning falsy values)', class extends TogglingHelperConditionalsTest {

templateFor({ cond, truthy, falsy }) {
return `{{if (if ${cond} true ${cond}) ${truthy} ${falsy}}}`;
}

});

moduleFor('@glimmer Helpers test: {{if}} used with another helper', class extends TogglingHelperConditionalsTest {
moduleFor('Helpers test: {{if}} used with another helper', class extends TogglingHelperConditionalsTest {

wrapperFor(templates) {
return `{{concat ${templates.join(' ')}}}`;
Expand Down
19 changes: 12 additions & 7 deletions packages/ember-htmlbars/lib/hooks/link-render-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@ export default function linkRenderNode(renderNode, env, scope, path, params, has
let keyword = env.hooks.keywords[path];
if (keyword && keyword.link) {
keyword.link(renderNode.getState(), params, hash);
} else if (path === 'unbound') {
return true;
} else {
switch (path) {
case 'unbound': return true;
case 'unless':
case 'if': params[0] = shouldDisplay(params[0], toBool); break;
case 'each': params[0] = eachParam(params[0]); break;
case 'with': params[0] = shouldDisplay(params[0], identity); break;
}
linkParamsFor(path, params);
}

// If there is a dot in the path, we need to subscribe to the arguments in the
Expand Down Expand Up @@ -65,6 +61,15 @@ export default function linkRenderNode(renderNode, env, scope, path, params, has
return true;
}

export function linkParamsFor(path, params) {
switch (path) {
case 'unless':
case 'if': params[0] = shouldDisplay(params[0], toBool); break;
case 'each': params[0] = eachParam(params[0]); break;
case 'with': params[0] = shouldDisplay(params[0], identity); break;
}
}

function eachParam(list) {
let listChange = getKey(list, '[]');

Expand Down
3 changes: 3 additions & 0 deletions packages/ember-htmlbars/lib/hooks/subexpr.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
labelsFor,
labelFor
} from 'ember-metal/streams/utils';
import { linkParamsFor } from 'ember-htmlbars/hooks/link-render-node';

export default function subexpr(env, scope, helperName, params, hash) {
// TODO: Keywords and helper invocation should be integrated into
Expand All @@ -18,6 +19,8 @@ export default function subexpr(env, scope, helperName, params, hash) {
return keyword(null, env, scope, params, hash, null, null);
}

linkParamsFor(helperName, params);

var label = labelForSubexpr(params, hash, helperName);
var helper = lookupHelper(helperName, scope.getSelf(), env);

Expand Down

0 comments on commit fd69421

Please sign in to comment.