From f81bf1eb49563ebf901ef1ffac9c9a096b01da7d Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Sat, 25 Jul 2015 18:52:13 -0400 Subject: [PATCH 1/7] [BUGFIX release] Deprecate Ember.Handlebars.makeViewHelper. --- .../default_resolver_test.js | 6 ++++- .../lib/system/make-view-helper.js | 8 ++++++ .../tests/compat/helper_test.js | 15 ++++++++--- .../tests/compat/make-view-helper_test.js | 9 +++++-- .../tests/helpers/yield_test.js | 27 ++++++++++++++----- .../tests/system/make_view_helper_test.js | 10 +++++-- .../tests/helpers/helper_registration_test.js | 8 +++--- 7 files changed, 64 insertions(+), 19 deletions(-) diff --git a/packages/ember-application/tests/system/dependency_injection/default_resolver_test.js b/packages/ember-application/tests/system/dependency_injection/default_resolver_test.js index 14b531fe27a..16329c48538 100644 --- a/packages/ember-application/tests/system/dependency_injection/default_resolver_test.js +++ b/packages/ember-application/tests/system/dependency_injection/default_resolver_test.js @@ -126,7 +126,11 @@ QUnit.test('the default resolver resolves helpers on the namespace', function() let LegacyBareFunctionHelper = function() {}; let LegacyHandlebarsBoundHelper = makeHandlebarsBoundHelper(function() {}); let LegacyHTMLBarsBoundHelper = makeHTMLBarsBoundHelper(function() {}); - let ViewHelper = makeViewHelper(function() {}); + let ViewHelper; + + expectDeprecation(function() { + ViewHelper = makeViewHelper(function() {}); + }, '`Ember.Handlebars.makeViewHelper` and `Ember.HTMLBars.makeViewHelper` are deprecated. Please refactor to normal component usage.'); application.ShorthandHelper = ShorthandHelper; application.CompleteHelper = CompleteHelper; diff --git a/packages/ember-htmlbars/lib/system/make-view-helper.js b/packages/ember-htmlbars/lib/system/make-view-helper.js index dacd786fde6..3e8a77cfb56 100644 --- a/packages/ember-htmlbars/lib/system/make-view-helper.js +++ b/packages/ember-htmlbars/lib/system/make-view-helper.js @@ -1,3 +1,5 @@ +import Ember from 'ember-metal/core'; + /** @module ember @submodule ember-htmlbars @@ -15,6 +17,12 @@ @since 1.2.0 */ export default function makeViewHelper(ViewClass) { + Ember.deprecate( + '`Ember.Handlebars.makeViewHelper` and `Ember.HTMLBars.makeViewHelper` are deprecated. Please refactor to normal component usage.', + false, + { id: 'ember-htmlbars.make-view-helper', until: '2.0.0' } + ); + return { isLegacyViewHelper: true, isHTMLBars: true, diff --git a/packages/ember-htmlbars/tests/compat/helper_test.js b/packages/ember-htmlbars/tests/compat/helper_test.js index 46dd8dff147..9759125fc27 100644 --- a/packages/ember-htmlbars/tests/compat/helper_test.js +++ b/packages/ember-htmlbars/tests/compat/helper_test.js @@ -181,13 +181,17 @@ QUnit.test('bound ordered params are provided with their original paths', functi }); QUnit.test('registering a helper created from `Ember.Handlebars.makeViewHelper` does not double wrap the helper', function() { - expect(1); + expect(2); var ViewHelperComponent = Component.extend({ layout: compile('woot!') }); - var helper = makeViewHelper(ViewHelperComponent); + var helper; + expectDeprecation(function() { + helper = makeViewHelper(ViewHelperComponent); + }, '`Ember.Handlebars.makeViewHelper` and `Ember.HTMLBars.makeViewHelper` are deprecated. Please refactor to normal component usage.'); + registerHandlebarsCompatibleHelper('view-helper', helper); view = EmberView.extend({ @@ -200,7 +204,7 @@ QUnit.test('registering a helper created from `Ember.Handlebars.makeViewHelper` }); QUnit.test('makes helpful assertion when called with invalid arguments', function() { - expect(1); + expect(2); var ViewHelperComponent = Component.extend({ layout: compile('woot!') @@ -208,7 +212,10 @@ QUnit.test('makes helpful assertion when called with invalid arguments', functio ViewHelperComponent.toString = function() { return 'Some Random Class'; }; - var helper = makeViewHelper(ViewHelperComponent); + var helper; + expectDeprecation(function() { + helper = makeViewHelper(ViewHelperComponent); + }, '`Ember.Handlebars.makeViewHelper` and `Ember.HTMLBars.makeViewHelper` are deprecated. Please refactor to normal component usage.'); registerHandlebarsCompatibleHelper('view-helper', helper); view = EmberView.extend({ diff --git a/packages/ember-htmlbars/tests/compat/make-view-helper_test.js b/packages/ember-htmlbars/tests/compat/make-view-helper_test.js index 5659256c4c3..6f60f46808f 100644 --- a/packages/ember-htmlbars/tests/compat/make-view-helper_test.js +++ b/packages/ember-htmlbars/tests/compat/make-view-helper_test.js @@ -28,12 +28,17 @@ QUnit.module('ember-htmlbars: compat - makeViewHelper compat', { }); QUnit.test('makeViewHelper', function() { - expect(1); + expect(2); var ViewHelperComponent = Component.extend({ layout: compile('woot!') }); - var helper = makeViewHelper(ViewHelperComponent); + + var helper; + expectDeprecation(function() { + helper = makeViewHelper(ViewHelperComponent); + }, '`Ember.Handlebars.makeViewHelper` and `Ember.HTMLBars.makeViewHelper` are deprecated. Please refactor to normal component usage.'); + registry.register('helper:view-helper', helper); view = EmberView.extend({ diff --git a/packages/ember-htmlbars/tests/helpers/yield_test.js b/packages/ember-htmlbars/tests/helpers/yield_test.js index 310905b1d8c..92639b5e0e7 100644 --- a/packages/ember-htmlbars/tests/helpers/yield_test.js +++ b/packages/ember-htmlbars/tests/helpers/yield_test.js @@ -12,6 +12,7 @@ import { registerHelper } from 'ember-htmlbars/helpers'; import makeViewHelper from 'ember-htmlbars/system/make-view-helper'; +import ComponentLookup from 'ember-views/component_lookup'; import compile from 'ember-template-compiler/system/compile'; import { runAppend, runDestroy } from 'ember-runtime/tests/utils'; @@ -21,20 +22,29 @@ import viewKeyword from 'ember-htmlbars/keywords/view'; var view, registry, container, originalViewKeyword; +function setupContainer() { + registry = new Registry(); + container = registry.container(); + registry.optionsForType('template', { instantiate: false }); + registry.register('component-lookup:main', ComponentLookup); +} + +function teardownContainer() { + runDestroy(container); + registry = container = view = null; +} + QUnit.module('ember-htmlbars: Support for {{yield}} helper', { setup() { + setupContainer(); originalViewKeyword = registerKeyword('view', viewKeyword); - registry = new Registry(); - container = registry.container(); - registry.optionsForType('template', { instantiate: false }); }, teardown() { run(function() { Ember.TEMPLATES = {}; }); runDestroy(view); - runDestroy(container); - registry = container = view = null; + teardownContainer(); resetKeyword('view', originalViewKeyword); } }); @@ -264,6 +274,7 @@ QUnit.test('nested simple bindings inside of a yielded template should work prop QUnit.module('ember-htmlbars: Component {{yield}}', { setup() { + setupContainer(); originalViewKeyword = registerKeyword('view', viewKeyword); }, teardown() { @@ -279,15 +290,17 @@ QUnit.test('yield with nested components (#3220)', function() { layout: compile('{{yield}}') }); - registerHelper('inner-component', makeViewHelper(InnerComponent)); + registry.register('component:inner-component', InnerComponent); var OuterComponent = Component.extend({ layout: compile('{{#inner-component}}{{yield}}{{/inner-component}}') }); - registerHelper('outer-component', makeViewHelper(OuterComponent)); + registry.register('component:outer-component', OuterComponent); view = EmberView.extend({ + container, + template: compile( '{{#outer-component}}Hello world{{/outer-component}}' ) diff --git a/packages/ember-htmlbars/tests/system/make_view_helper_test.js b/packages/ember-htmlbars/tests/system/make_view_helper_test.js index afbbdc3ecdf..05109e891de 100644 --- a/packages/ember-htmlbars/tests/system/make_view_helper_test.js +++ b/packages/ember-htmlbars/tests/system/make_view_helper_test.js @@ -30,7 +30,10 @@ QUnit.test('makes helpful assertion when called with invalid arguments', functio return 'Some Random Class'; }; - var helper = makeViewHelper(SomeRandom); + var helper; + expectDeprecation(function() { + helper = makeViewHelper(SomeRandom); + }, '`Ember.Handlebars.makeViewHelper` and `Ember.HTMLBars.makeViewHelper` are deprecated. Please refactor to normal component usage.'); registry.register('helper:some-random', helper); view = EmberView.create({ @@ -48,7 +51,10 @@ QUnit.test('can properly yield', function() { layout: compile('Some Random Class - {{yield}}') }); - var helper = makeViewHelper(SomeRandom); + var helper; + expectDeprecation(function() { + helper = makeViewHelper(SomeRandom); + }, '`Ember.Handlebars.makeViewHelper` and `Ember.HTMLBars.makeViewHelper` are deprecated. Please refactor to normal component usage.'); registry.register('helper:some-random', helper); view = EmberView.create({ diff --git a/packages/ember/tests/helpers/helper_registration_test.js b/packages/ember/tests/helpers/helper_registration_test.js index d8b718ae394..c5b25cf01d4 100644 --- a/packages/ember/tests/helpers/helper_registration_test.js +++ b/packages/ember/tests/helpers/helper_registration_test.js @@ -102,9 +102,11 @@ QUnit.test('Bound `makeViewHelper` helpers registered on the container can be us foo: 'alex' })); - registry.register('helper:x-foo', makeViewHelper(Ember.Component.extend({ - layout: compile('woot!!{{attrs.name}}') - }))); + expectDeprecation(function() { + registry.register('helper:x-foo', makeViewHelper(Ember.Component.extend({ + layout: compile('woot!!{{attrs.name}}') + }))); + }, '`Ember.Handlebars.makeViewHelper` and `Ember.HTMLBars.makeViewHelper` are deprecated. Please refactor to normal component usage.'); }); equal(Ember.$('#wrapper').text(), 'woot!! woot!!alex', 'The helper was invoked from the container'); From 3b880ea37c42356ab9c7e9cc9b973bffb743a2b8 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Sat, 25 Jul 2015 19:11:47 -0400 Subject: [PATCH 2/7] [BUGFIX release] Deprecate Ember.HTMLBars._registerHelper. --- packages/ember-htmlbars/lib/helpers.js | 7 +++++++ packages/ember-htmlbars/lib/main.js | 5 +++-- .../ember-htmlbars/tests/helpers/yield_test.js | 4 ---- .../tests/helpers/helper_registration_test.js | 15 +++++++++++---- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/packages/ember-htmlbars/lib/helpers.js b/packages/ember-htmlbars/lib/helpers.js index 9d21dfbe370..8016f423ca2 100644 --- a/packages/ember-htmlbars/lib/helpers.js +++ b/packages/ember-htmlbars/lib/helpers.js @@ -7,6 +7,8 @@ @private @property helpers */ +import Ember from 'ember-metal/core'; + var helpers = Object.create(null); /** @@ -25,4 +27,9 @@ export function registerHelper(name, helperFunc) { helpers[name] = helperFunc; } +export let deprecatedRegisterHelper = Ember.deprecateFunc( + 'Using Ember.HTMLBars._registerHelper is deprecated. Helpers (even dashless ones) are automatically resolved.', + { id: 'ember-htmlbars.register-helper', until: '2.0.0' }, + registerHelper); + export default helpers; diff --git a/packages/ember-htmlbars/lib/main.js b/packages/ember-htmlbars/lib/main.js index 9ab208d9650..72629e8c0a0 100644 --- a/packages/ember-htmlbars/lib/main.js +++ b/packages/ember-htmlbars/lib/main.js @@ -36,7 +36,8 @@ import makeViewHelper from 'ember-htmlbars/system/make-view-helper'; import makeBoundHelper from 'ember-htmlbars/system/make_bound_helper'; import { - registerHelper + registerHelper, + deprecatedRegisterHelper } from 'ember-htmlbars/helpers'; import { ifHelper, @@ -84,7 +85,7 @@ if (Ember.ENV._ENABLE_LEGACY_VIEW_SUPPORT) { } Ember.HTMLBars = { - _registerHelper: registerHelper, + _registerHelper: deprecatedRegisterHelper, template: template, compile: compile, precompile: precompile, diff --git a/packages/ember-htmlbars/tests/helpers/yield_test.js b/packages/ember-htmlbars/tests/helpers/yield_test.js index 92639b5e0e7..a83e4e2262d 100644 --- a/packages/ember-htmlbars/tests/helpers/yield_test.js +++ b/packages/ember-htmlbars/tests/helpers/yield_test.js @@ -8,10 +8,6 @@ import { Registry } from 'ember-runtime/system/container'; import { A } from 'ember-runtime/system/native_array'; import Component from 'ember-views/views/component'; import helpers from 'ember-htmlbars/helpers'; -import { - registerHelper -} from 'ember-htmlbars/helpers'; -import makeViewHelper from 'ember-htmlbars/system/make-view-helper'; import ComponentLookup from 'ember-views/component_lookup'; import compile from 'ember-template-compiler/system/compile'; diff --git a/packages/ember/tests/helpers/helper_registration_test.js b/packages/ember/tests/helpers/helper_registration_test.js index c5b25cf01d4..b5c722c9d2a 100644 --- a/packages/ember/tests/helpers/helper_registration_test.js +++ b/packages/ember/tests/helpers/helper_registration_test.js @@ -7,10 +7,9 @@ import Helper from 'ember-htmlbars/helper'; import { registerKeyword, resetKeyword } from 'ember-htmlbars/tests/utils'; import viewKeyword from 'ember-htmlbars/keywords/view'; - -var compile, helpers, makeBoundHelper; +import helpers from 'ember-htmlbars/helpers'; +var compile, makeBoundHelper; compile = EmberHandlebars.compile; -helpers = EmberHandlebars.helpers; makeBoundHelper = EmberHandlebars.makeBoundHelper; var makeViewHelper = EmberHandlebars.makeViewHelper; @@ -20,7 +19,6 @@ function reverseHelper(value) { return arguments.length > 1 ? value.split('').reverse().join('') : '--'; } - QUnit.module('Application Lifecycle - Helper Registration', { setup() { originalViewKeyword = registerKeyword('view', viewKeyword); @@ -34,6 +32,7 @@ QUnit.module('Application Lifecycle - Helper Registration', { App = null; Ember.TEMPLATES = {}; }); + delete helpers['foo-bar-baz-widget']; resetKeyword('view', originalViewKeyword); } }); @@ -171,3 +170,11 @@ QUnit.test('Helpers can receive injections', function() { ok(serviceCalled, 'service was injected, method called'); }); + +QUnit.test('Ember.HTMLBars._registerHelper is deprecated', function() { + expectDeprecation(function() { + Ember.HTMLBars._registerHelper('foo-bar-baz-widget', function() {}); + }); + + ok(helpers['foo-bar-baz-widget'], 'helper was registered'); +}); From 7e3b4109ee1c228daeed9b3c4b31da1bea2b5de9 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Sat, 25 Jul 2015 19:22:31 -0400 Subject: [PATCH 3/7] [BUGFIX release] Deprecate `Ember.HTMLBars.makeBoundHelper`. --- .../system/dependency_injection/default_resolver_test.js | 7 +++++-- packages/ember-htmlbars/lib/system/make_bound_helper.js | 7 ++++++- packages/ember-htmlbars/tests/helpers/view_test.js | 4 ++-- .../ember-htmlbars/tests/system/make_bound_helper_test.js | 1 + 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/ember-application/tests/system/dependency_injection/default_resolver_test.js b/packages/ember-application/tests/system/dependency_injection/default_resolver_test.js index 16329c48538..36183484435 100644 --- a/packages/ember-application/tests/system/dependency_injection/default_resolver_test.js +++ b/packages/ember-application/tests/system/dependency_injection/default_resolver_test.js @@ -125,8 +125,11 @@ QUnit.test('the default resolver resolves helpers on the namespace', function() let CompleteHelper = Helper.extend(); let LegacyBareFunctionHelper = function() {}; let LegacyHandlebarsBoundHelper = makeHandlebarsBoundHelper(function() {}); - let LegacyHTMLBarsBoundHelper = makeHTMLBarsBoundHelper(function() {}); - let ViewHelper; + let ViewHelper, LegacyHTMLBarsBoundHelper; + + expectDeprecation(function() { + LegacyHTMLBarsBoundHelper = makeHTMLBarsBoundHelper(function() {}); + }, 'Using `Ember.HTMLBars.makeBoundHelper` is deprecated. Please refactor to using `Ember.Helper` or `Ember.Helper.helper`.'); expectDeprecation(function() { ViewHelper = makeViewHelper(function() {}); diff --git a/packages/ember-htmlbars/lib/system/make_bound_helper.js b/packages/ember-htmlbars/lib/system/make_bound_helper.js index b2cbd762292..cf30e046f23 100644 --- a/packages/ember-htmlbars/lib/system/make_bound_helper.js +++ b/packages/ember-htmlbars/lib/system/make_bound_helper.js @@ -2,7 +2,7 @@ @module ember @submodule ember-htmlbars */ - +import Ember from 'ember-metal/core'; import { helper } from 'ember-htmlbars/helper'; /** @@ -49,5 +49,10 @@ import { helper } from 'ember-htmlbars/helper'; @since 1.10.0 */ export default function makeBoundHelper(fn) { + Ember.deprecate( + 'Using `Ember.HTMLBars.makeBoundHelper` is deprecated. Please refactor to using `Ember.Helper` or `Ember.Helper.helper`.', + false, + { id: 'ember-htmlbars.make-bound-helper', until: '3.0.0' } + ); return helper(fn); } diff --git a/packages/ember-htmlbars/tests/helpers/view_test.js b/packages/ember-htmlbars/tests/helpers/view_test.js index ac45dea0c65..19371b3e314 100644 --- a/packages/ember-htmlbars/tests/helpers/view_test.js +++ b/packages/ember-htmlbars/tests/helpers/view_test.js @@ -15,7 +15,7 @@ import compile from 'ember-template-compiler/system/compile'; import template from 'ember-template-compiler/system/template'; import { observersFor } from 'ember-metal/observer'; import Controller from 'ember-runtime/controllers/controller'; -import makeBoundHelper from 'ember-htmlbars/system/make_bound_helper'; +import { helper as makeHelper } from 'ember-htmlbars/helper'; import { runAppend, runDestroy } from 'ember-runtime/tests/utils'; import { set } from 'ember-metal/property_set'; @@ -392,7 +392,7 @@ QUnit.test('Should apply classes when bound property specified', function() { }); QUnit.test('Should apply a class from a sub expression', function() { - registry.register('helper:string-concat', makeBoundHelper(function(params) { + registry.register('helper:string-concat', makeHelper(function(params) { return params.join(''); })); diff --git a/packages/ember-htmlbars/tests/system/make_bound_helper_test.js b/packages/ember-htmlbars/tests/system/make_bound_helper_test.js index 2c793049766..2cbe0eac242 100644 --- a/packages/ember-htmlbars/tests/system/make_bound_helper_test.js +++ b/packages/ember-htmlbars/tests/system/make_bound_helper_test.js @@ -17,6 +17,7 @@ function registerRepeatHelper() { QUnit.module('ember-htmlbars: makeBoundHelper', { setup() { + expectDeprecation('Using `Ember.HTMLBars.makeBoundHelper` is deprecated. Please refactor to using `Ember.Helper` or `Ember.Helper.helper`.'); registry = new Registry(); container = registry.container(); }, From 45e96d16b15ae023af5d3cf90c867ca3788bee2a Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Sat, 25 Jul 2015 21:59:37 -0400 Subject: [PATCH 4/7] [BUGFIX release] Deprecate `Ember.Handlebars.makeBoundHelper`. --- .../default_resolver_test.js | 7 +++++-- .../lib/compat/make-bound-helper.js | 13 ++++++++++++- .../lib/compat/register-bound-helper.js | 2 +- .../tests/compat/make_bound_helper_test.js | 13 +------------ .../tests/helpers/unbound_test.js | 1 + .../tests/helpers/helper_registration_test.js | 19 ++++++++----------- 6 files changed, 28 insertions(+), 27 deletions(-) diff --git a/packages/ember-application/tests/system/dependency_injection/default_resolver_test.js b/packages/ember-application/tests/system/dependency_injection/default_resolver_test.js index 36183484435..181201d6ad4 100644 --- a/packages/ember-application/tests/system/dependency_injection/default_resolver_test.js +++ b/packages/ember-application/tests/system/dependency_injection/default_resolver_test.js @@ -124,8 +124,11 @@ QUnit.test('the default resolver resolves helpers on the namespace', function() let ShorthandHelper = makeHelper(function() {}); let CompleteHelper = Helper.extend(); let LegacyBareFunctionHelper = function() {}; - let LegacyHandlebarsBoundHelper = makeHandlebarsBoundHelper(function() {}); - let ViewHelper, LegacyHTMLBarsBoundHelper; + let ViewHelper, LegacyHandlebarsBoundHelper, LegacyHTMLBarsBoundHelper; + + expectDeprecation(function() { + LegacyHandlebarsBoundHelper = makeHandlebarsBoundHelper(function() {}); + }, 'Using Ember.Handlebars.makeBoundHelper is deprecated. Please refactor to using `Ember.Helper.helper`.'); expectDeprecation(function() { LegacyHTMLBarsBoundHelper = makeHTMLBarsBoundHelper(function() {}); diff --git a/packages/ember-htmlbars/lib/compat/make-bound-helper.js b/packages/ember-htmlbars/lib/compat/make-bound-helper.js index 89a0fa0feb3..f989e0118bb 100644 --- a/packages/ember-htmlbars/lib/compat/make-bound-helper.js +++ b/packages/ember-htmlbars/lib/compat/make-bound-helper.js @@ -37,7 +37,8 @@ import { @deprecated @private */ -export default function makeBoundHelper(fn, ...dependentKeys) { + +export function makeBoundHelper(fn, ...dependentKeys) { return { _dependentKeys: dependentKeys, @@ -65,3 +66,13 @@ export default function makeBoundHelper(fn, ...dependentKeys) { } }; } + +export default function deprecatedMakeBoundHelper(fn, ...dependentKeys) { + Ember.deprecate( + 'Using Ember.Handlebars.makeBoundHelper is deprecated. Please refactor to using `Ember.Helper.helper`.', + false, + { id: 'ember-htmlbars.handlebars-make-bound-helper', until: '2.0.0' } + ); + + return makeBoundHelper(...arguments); +} diff --git a/packages/ember-htmlbars/lib/compat/register-bound-helper.js b/packages/ember-htmlbars/lib/compat/register-bound-helper.js index b40f2f30557..24491c56505 100644 --- a/packages/ember-htmlbars/lib/compat/register-bound-helper.js +++ b/packages/ember-htmlbars/lib/compat/register-bound-helper.js @@ -4,7 +4,7 @@ */ import helpers from 'ember-htmlbars/helpers'; -import makeBoundHelper from 'ember-htmlbars/compat/make-bound-helper'; +import { makeBoundHelper } from 'ember-htmlbars/compat/make-bound-helper'; var slice = [].slice; diff --git a/packages/ember-htmlbars/tests/compat/make_bound_helper_test.js b/packages/ember-htmlbars/tests/compat/make_bound_helper_test.js index 74094750c9e..20bac9e4a96 100644 --- a/packages/ember-htmlbars/tests/compat/make_bound_helper_test.js +++ b/packages/ember-htmlbars/tests/compat/make_bound_helper_test.js @@ -43,6 +43,7 @@ function expectDeprecationInHTMLBars() { QUnit.module('ember-htmlbars: compat - makeBoundHelper', { setup() { + expectDeprecation('Using Ember.Handlebars.makeBoundHelper is deprecated. Please refactor to using `Ember.Helper.helper`.'); }, teardown() { runDestroy(view); @@ -50,18 +51,6 @@ QUnit.module('ember-htmlbars: compat - makeBoundHelper', { } }); -QUnit.test('primitives should work correctly [DEPRECATED]', function() { - view = EmberView.create({ - prims: Ember.A(['string', 12]), - - template: compile('{{#each view.prims as |prim|}}{{#if prim}}inside-if{{/if}}{{/each}}') - }); - - runAppend(view); - - equal(view.$().text(), 'inside-ifinside-if'); -}); - QUnit.test('should update bound helpers when properties change', function() { expectDeprecationInHTMLBars(); diff --git a/packages/ember-htmlbars/tests/helpers/unbound_test.js b/packages/ember-htmlbars/tests/helpers/unbound_test.js index 8b6bcd61552..e18b2762959 100644 --- a/packages/ember-htmlbars/tests/helpers/unbound_test.js +++ b/packages/ember-htmlbars/tests/helpers/unbound_test.js @@ -495,6 +495,7 @@ QUnit.module('ember-htmlbars: {{#unbound}} helper -- Container Lookup', { QUnit.test('should lookup helpers in the container', function() { expectDeprecationInHTMLBars(); + expectDeprecation('Using Ember.Handlebars.makeBoundHelper is deprecated. Please refactor to using `Ember.Helper.helper`.'); registry.register('helper:up-case', makeBoundHelper(function(value) { return value.toUpperCase(); })); diff --git a/packages/ember/tests/helpers/helper_registration_test.js b/packages/ember/tests/helpers/helper_registration_test.js index b5c722c9d2a..bdc34cdb990 100644 --- a/packages/ember/tests/helpers/helper_registration_test.js +++ b/packages/ember/tests/helpers/helper_registration_test.js @@ -3,22 +3,17 @@ import Ember from 'ember-metal/core'; import isEnabled from 'ember-metal/features'; import EmberHandlebars from 'ember-htmlbars/compat'; import HandlebarsCompatibleHelper from 'ember-htmlbars/compat/helper'; -import Helper from 'ember-htmlbars/helper'; +import Helper, { helper } from 'ember-htmlbars/helper'; import { registerKeyword, resetKeyword } from 'ember-htmlbars/tests/utils'; import viewKeyword from 'ember-htmlbars/keywords/view'; import helpers from 'ember-htmlbars/helpers'; -var compile, makeBoundHelper; +var compile; compile = EmberHandlebars.compile; -makeBoundHelper = EmberHandlebars.makeBoundHelper; var makeViewHelper = EmberHandlebars.makeViewHelper; var App, registry, container, originalViewKeyword; -function reverseHelper(value) { - return arguments.length > 1 ? value.split('').reverse().join('') : '--'; -} - QUnit.module('Application Lifecycle - Helper Registration', { setup() { originalViewKeyword = registerKeyword('view', viewKeyword); @@ -78,7 +73,6 @@ QUnit.test('Unbound dashed helpers registered on the container can be late-invok ok(!helpers['x-borf'], 'Container-registered helper doesn\'t wind up on global helpers hash'); }); -// need to make `makeBoundHelper` for HTMLBars QUnit.test('Bound helpers registered on the container can be late-invoked', function() { Ember.TEMPLATES.application = compile('
{{x-reverse}} {{x-reverse foo}}
'); @@ -86,7 +80,10 @@ QUnit.test('Bound helpers registered on the container can be late-invoked', func registry.register('controller:application', Ember.Controller.extend({ foo: 'alex' })); - registry.register('helper:x-reverse', makeBoundHelper(reverseHelper)); + + registry.register('helper:x-reverse', helper(function([ value ]) { + return value ? value.split('').reverse().join('') : '--'; + })); }); equal(Ember.$('#wrapper').text(), '-- xela', 'The bound helper was invoked from the container'); @@ -121,7 +118,7 @@ if (isEnabled('ember-htmlbars-dashless-helpers')) { return 'OMG'; }); - registry.register('helper:yorp', makeBoundHelper(function(value) { + registry.register('helper:yorp', helper(function([ value ]) { return value; })); }, /Please use Ember.Helper.build to wrap helper functions./); @@ -142,7 +139,7 @@ if (isEnabled('ember-htmlbars-dashless-helpers')) { registry.register('helper:omg', function() { return 'OMG'; }); - registry.register('helper:yorp', makeBoundHelper(function() { + registry.register('helper:yorp', helper(function() { return 'YORP'; })); }); From 03de0677bfebb7516f889f1dbfbf9b622be22e32 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Sat, 25 Jul 2015 22:36:03 -0400 Subject: [PATCH 5/7] [BUGFIX release] Deprecate `Ember.Handlebars.registerBoundHelper`. --- .../lib/compat/register-bound-helper.js | 14 +++++++++++++- .../ember-htmlbars/tests/helpers/unbound_test.js | 7 +++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/ember-htmlbars/lib/compat/register-bound-helper.js b/packages/ember-htmlbars/lib/compat/register-bound-helper.js index 24491c56505..887ab59c36e 100644 --- a/packages/ember-htmlbars/lib/compat/register-bound-helper.js +++ b/packages/ember-htmlbars/lib/compat/register-bound-helper.js @@ -3,6 +3,7 @@ @submodule ember-htmlbars */ +import Ember from 'ember-metal/core'; import helpers from 'ember-htmlbars/helpers'; import { makeBoundHelper } from 'ember-htmlbars/compat/make-bound-helper'; @@ -118,9 +119,20 @@ var slice = [].slice; @param {String} dependentKeys* @private */ -export default function registerBoundHelper(name, fn) { + +export function registerBoundHelper(name, fn) { var boundHelperArgs = slice.call(arguments, 1); var boundFn = makeBoundHelper.apply(this, boundHelperArgs); helpers[name] = boundFn; } + +export default function deprecatedRegisterBoundHelper() { + Ember.deprecate( + '`Ember.Handlebars.registerBoundHelper` is deprecated. Please refactor to use `Ember.Helpers.helper`.', + false, + { id: 'ember-htmlbars.register-bound-helper', until: '2.0.0' } + ); + + return registerBoundHelper(...arguments); +} diff --git a/packages/ember-htmlbars/tests/helpers/unbound_test.js b/packages/ember-htmlbars/tests/helpers/unbound_test.js index e18b2762959..6fb9781833e 100644 --- a/packages/ember-htmlbars/tests/helpers/unbound_test.js +++ b/packages/ember-htmlbars/tests/helpers/unbound_test.js @@ -134,6 +134,8 @@ QUnit.module('ember-htmlbars: {{#unbound}} subexpression', { setup() { Ember.lookup = lookup = { Ember: Ember }; + expectDeprecation('`Ember.Handlebars.registerBoundHelper` is deprecated. Please refactor to use `Ember.Helpers.helper`.'); + registerBoundHelper('capitalize', function(value) { return value.toUpperCase(); }); @@ -179,6 +181,9 @@ QUnit.module('ember-htmlbars: {{#unbound}} subexpression - helper form', { setup() { Ember.lookup = lookup = { Ember: Ember }; + + expectDeprecation('`Ember.Handlebars.registerBoundHelper` is deprecated. Please refactor to use `Ember.Helpers.helper`.'); + registerBoundHelper('capitalize', function(value) { return value.toUpperCase(); }); @@ -230,6 +235,8 @@ QUnit.module('ember-htmlbars: {{#unbound boundHelper arg1 arg2... argN}} form: r Ember.lookup = lookup = { Ember: Ember }; expectDeprecationInHTMLBars(); + expectDeprecation('`Ember.Handlebars.registerBoundHelper` is deprecated. Please refactor to use `Ember.Helpers.helper`.'); + registerBoundHelper('surround', function(prefix, value, suffix) { return prefix + '-' + value + '-' + suffix; }); From 63da31f6d83be56cbfe0f71136b8c6872024948f Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Sat, 25 Jul 2015 22:40:03 -0400 Subject: [PATCH 6/7] [BUGFIX release] Deprecate `Ember.Handlebars.helper`. --- packages/ember-htmlbars/lib/compat/helper.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/ember-htmlbars/lib/compat/helper.js b/packages/ember-htmlbars/lib/compat/helper.js index 26372d69598..854379d1128 100644 --- a/packages/ember-htmlbars/lib/compat/helper.js +++ b/packages/ember-htmlbars/lib/compat/helper.js @@ -132,6 +132,12 @@ export function registerHandlebarsCompatibleHelper(name, value) { } export function handlebarsHelper(name, value) { + Ember.deprecate( + 'Ember.Handlebars.helper is deprecated, please refactor to Ember.Helper.helper', + false, + { id: 'ember-htmlbars.handlebars-helper', until: '2.0.0' } + ); + Ember.assert(`You tried to register a component named '${name}', but component names must include a '-'`, !Component.detect(value) || name.match(/-/)); From a3d268d6e290911b9f88581e016e91188310f426 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Sat, 25 Jul 2015 22:47:24 -0400 Subject: [PATCH 7/7] [BUGFIX release] Deprecate `Ember.Handlebars.registerHelper`. --- packages/ember-htmlbars/lib/compat/helper.js | 6 ++++ .../tests/compat/helper_test.js | 36 +++++++++++-------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/packages/ember-htmlbars/lib/compat/helper.js b/packages/ember-htmlbars/lib/compat/helper.js index 854379d1128..95970c8f45b 100644 --- a/packages/ember-htmlbars/lib/compat/helper.js +++ b/packages/ember-htmlbars/lib/compat/helper.js @@ -109,6 +109,12 @@ HandlebarsCompatibleHelper.prototype = { }; export function registerHandlebarsCompatibleHelper(name, value) { + Ember.deprecate( + 'Ember.Handlebars.registerHelper is deprecated, please refactor to Ember.Helper.helper.', + false, + { id: 'ember-htmlbars.handlebars-register-helper', until: '2.0.0' } + ); + if (value && value.isLegacyViewHelper) { registerKeyword(name, function(morph, env, scope, params, hash, template, inverse, visitor) { Ember.assert('You can only pass attributes (such as name=value) not bare ' + diff --git a/packages/ember-htmlbars/tests/compat/helper_test.js b/packages/ember-htmlbars/tests/compat/helper_test.js index 9759125fc27..b5964486bc7 100644 --- a/packages/ember-htmlbars/tests/compat/helper_test.js +++ b/packages/ember-htmlbars/tests/compat/helper_test.js @@ -1,5 +1,5 @@ import { - registerHandlebarsCompatibleHelper + registerHandlebarsCompatibleHelper as registerHelper } from 'ember-htmlbars/compat/helper'; import EmberView from 'ember-views/views/view'; @@ -18,6 +18,12 @@ import viewKeyword from 'ember-htmlbars/keywords/view'; var view, registry, container, originalViewKeyword; +function registerHandlebarsCompatibleHelper() { + expectDeprecation('Ember.Handlebars.registerHelper is deprecated, please refactor to Ember.Helper.helper.'); + + return registerHelper(...arguments); +} + QUnit.module('ember-htmlbars: compat - Handlebars compatible helpers', { setup() { originalViewKeyword = registerKeyword('view', viewKeyword); @@ -40,7 +46,7 @@ QUnit.module('ember-htmlbars: compat - Handlebars compatible helpers', { }); QUnit.test('wraps provided function so that original path params are provided to the helper', function() { - expect(2); + expect(3); function someHelper(param1, param2, options) { equal(param1, 'blammo'); @@ -60,7 +66,7 @@ QUnit.test('wraps provided function so that original path params are provided to }); QUnit.test('combines `env` and `options` for the wrapped helper', function() { - expect(1); + expect(2); function someHelper(options) { equal(options.data.view, view); @@ -79,7 +85,7 @@ QUnit.test('combines `env` and `options` for the wrapped helper', function() { }); QUnit.test('combines `env` and `options` for the wrapped helper', function() { - expect(1); + expect(2); function someHelper(options) { equal(options.data.view, view); @@ -122,7 +128,7 @@ QUnit.test('has the correct options.data.view within a components layout', funct }); QUnit.test('adds `hash` into options `options` for the wrapped helper', function() { - expect(1); + expect(2); function someHelper(options) { equal(options.hash.bestFriend, 'Jacquie'); @@ -141,7 +147,7 @@ QUnit.test('adds `hash` into options `options` for the wrapped helper', function }); QUnit.test('bound `hash` params are provided with their original paths', function() { - expect(1); + expect(2); function someHelper(options) { equal(options.hash.bestFriend, 'value'); @@ -160,7 +166,7 @@ QUnit.test('bound `hash` params are provided with their original paths', functio }); QUnit.test('bound ordered params are provided with their original paths', function() { - expect(2); + expect(3); function someHelper(param1, param2, options) { equal(param1, 'first'); @@ -181,7 +187,7 @@ QUnit.test('bound ordered params are provided with their original paths', functi }); QUnit.test('registering a helper created from `Ember.Handlebars.makeViewHelper` does not double wrap the helper', function() { - expect(2); + expect(3); var ViewHelperComponent = Component.extend({ layout: compile('woot!') @@ -204,7 +210,7 @@ QUnit.test('registering a helper created from `Ember.Handlebars.makeViewHelper` }); QUnit.test('makes helpful assertion when called with invalid arguments', function() { - expect(2); + expect(3); var ViewHelperComponent = Component.extend({ layout: compile('woot!') @@ -228,7 +234,7 @@ QUnit.test('makes helpful assertion when called with invalid arguments', functio }); QUnit.test('does not add `options.fn` if no block was specified', function() { - expect(1); + expect(2); function someHelper(options) { ok(!options.fn, '`options.fn` is not present when block is not specified'); @@ -247,7 +253,7 @@ QUnit.test('does not add `options.fn` if no block was specified', function() { }); QUnit.test('does not return helper result if block was specified', function() { - expect(1); + expect(2); function someHelper(options) { return 'asdf'; @@ -268,7 +274,7 @@ QUnit.test('does not return helper result if block was specified', function() { }); QUnit.test('allows usage of the template fn', function() { - expect(1); + expect(2); function someHelper(options) { options.fn(); @@ -289,7 +295,7 @@ QUnit.test('allows usage of the template fn', function() { }); QUnit.test('allows usage of the template inverse', function() { - expect(1); + expect(2); function someHelper(options) { options.inverse(); @@ -310,7 +316,7 @@ QUnit.test('allows usage of the template inverse', function() { }); QUnit.test('ordered param types are added to options.types', function() { - expect(3); + expect(4); function someHelper(param1, param2, param3, options) { equal(options.types[0], 'NUMBER'); @@ -332,7 +338,7 @@ QUnit.test('ordered param types are added to options.types', function() { }); QUnit.test('`hash` params are to options.hashTypes', function() { - expect(3); + expect(4); function someHelper(options) { equal(options.hashTypes.string, 'STRING');