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

[BUGFIX release] Fix Ember.Handlebars comaptible helpers. #10813

Merged
merged 2 commits into from
Apr 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/ember-htmlbars/lib/compat/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function calculateCompatType(item) {
function HandlebarsCompatibleHelper(fn) {
this.helperFunction = function helperFunc(params, hash, options, env) {
var param, blockResult, fnResult;
var context = this;
var context = env.data.view;
var handlebarsOptions = {
hash: { },
types: new Array(params.length),
Expand All @@ -49,6 +49,12 @@ function HandlebarsCompatibleHelper(fn) {
handlebarsOptions.fn = function() {
blockResult = options.template.render(context, env, options.morph.contextualElement);
};

if (options.inverse) {
handlebarsOptions.inverse = function() {
blockResult = options.inverse.render(context, env, options.morph.contextualElement);
};
}
}

for (var prop in hash) {
Expand Down
23 changes: 22 additions & 1 deletion packages/ember-htmlbars/tests/compat/helper_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,28 @@ QUnit.test('allows usage of the template fn', function() {
controller: {
value: 'foo'
},
template: compile('{{#test}}foo{{/test}}')
template: compile('{{#test}}{{value}}{{/test}}')
});

runAppend(view);

equal(view.$().text(), 'foo');
});

QUnit.test('allows usage of the template inverse', function() {
expect(1);

function someHelper(options) {
options.inverse();
}

registerHandlebarsCompatibleHelper('test', someHelper);

view = EmberView.create({
controller: {
value: 'foo'
},
template: compile('{{#test}}Nothing to see here.{{else}}{{value}}{{/test}}')
});

runAppend(view);
Expand Down
9 changes: 7 additions & 2 deletions packages/ember-htmlbars/tests/system/lookup-helper_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import Component from "ember-views/views/component";

function generateEnv(helpers) {
return {
helpers: (helpers ? helpers : {})
helpers: (helpers ? helpers : {}),
data: { view: { } }
};
}

Expand Down Expand Up @@ -92,7 +93,11 @@ QUnit.test('wraps helper from container in a Handlebars compat helper', function
var fakeOptions = {
morph: { update() { } }
};
var fakeEnv = {};
var fakeEnv = {
data: {
view: { }
}
};
actual.helperFunction(fakeParams, fakeHash, fakeOptions, fakeEnv);

ok(called, 'HTMLBars compatible wrapper is wraping the provided function');
Expand Down