From ed54cda663c74a9dcbfd99087ae79aa23d87d6cb Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Thu, 2 Apr 2015 16:52:33 -0400 Subject: [PATCH 1/2] [BUGFIX release] Ensure `options.fn` can be called in a compat helper. --- packages/ember-htmlbars/lib/compat/helper.js | 2 +- packages/ember-htmlbars/tests/compat/helper_test.js | 2 +- .../ember-htmlbars/tests/system/lookup-helper_test.js | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/ember-htmlbars/lib/compat/helper.js b/packages/ember-htmlbars/lib/compat/helper.js index a3566363600..f3628509844 100644 --- a/packages/ember-htmlbars/lib/compat/helper.js +++ b/packages/ember-htmlbars/lib/compat/helper.js @@ -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), diff --git a/packages/ember-htmlbars/tests/compat/helper_test.js b/packages/ember-htmlbars/tests/compat/helper_test.js index 503c380f18d..8744c421e9d 100644 --- a/packages/ember-htmlbars/tests/compat/helper_test.js +++ b/packages/ember-htmlbars/tests/compat/helper_test.js @@ -217,7 +217,7 @@ QUnit.test('allows usage of the template fn', function() { controller: { value: 'foo' }, - template: compile('{{#test}}foo{{/test}}') + template: compile('{{#test}}{{value}}{{/test}}') }); runAppend(view); diff --git a/packages/ember-htmlbars/tests/system/lookup-helper_test.js b/packages/ember-htmlbars/tests/system/lookup-helper_test.js index 4a6f3939a9d..b9fe609724e 100644 --- a/packages/ember-htmlbars/tests/system/lookup-helper_test.js +++ b/packages/ember-htmlbars/tests/system/lookup-helper_test.js @@ -5,7 +5,8 @@ import Component from "ember-views/views/component"; function generateEnv(helpers) { return { - helpers: (helpers ? helpers : {}) + helpers: (helpers ? helpers : {}), + data: { view: { } } }; } @@ -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'); From 0640d468335722088c2cecb3c0068c41248ea950 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Thu, 2 Apr 2015 16:59:04 -0400 Subject: [PATCH 2/2] [BUGFIX release] Ensure `options.inverse` can be called in a compat helper. --- packages/ember-htmlbars/lib/compat/helper.js | 6 ++++++ .../tests/compat/helper_test.js | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/packages/ember-htmlbars/lib/compat/helper.js b/packages/ember-htmlbars/lib/compat/helper.js index f3628509844..da4f9696574 100644 --- a/packages/ember-htmlbars/lib/compat/helper.js +++ b/packages/ember-htmlbars/lib/compat/helper.js @@ -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) { diff --git a/packages/ember-htmlbars/tests/compat/helper_test.js b/packages/ember-htmlbars/tests/compat/helper_test.js index 8744c421e9d..84c9fc7a9c9 100644 --- a/packages/ember-htmlbars/tests/compat/helper_test.js +++ b/packages/ember-htmlbars/tests/compat/helper_test.js @@ -225,6 +225,27 @@ QUnit.test('allows usage of the template fn', function() { 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); + + equal(view.$().text(), 'foo'); +}); + QUnit.test('ordered param types are added to options.types', function() { expect(3);