From 1c0549cd5d2fa73361ffe40bc6a345c3be6c13e9 Mon Sep 17 00:00:00 2001 From: Sylvain MINA Date: Tue, 24 Mar 2015 18:11:51 +0100 Subject: [PATCH] Add missing cross-version helper registration --- addon/helper.js | 10 ++-------- addon/register-helper.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 addon/register-helper.js diff --git a/addon/helper.js b/addon/helper.js index c9ad097..8e9f876 100644 --- a/addon/helper.js +++ b/addon/helper.js @@ -1,18 +1,12 @@ import Ember from 'ember'; import EmberListView from './list-view'; import EmberVirtualListView from './virtual-list-view'; - +import registerHelper from './register-helper'; + export var EmberVirtualList = createHelper(EmberVirtualListView); export var EmberList = createHelper(EmberListView); export function registerListViewHelpers() { - var registerHelper; - if (Ember.HTMLBars) { - // registerHelper was used for some 1.10-beta's and _registerHelper is for 1.10.0 final. - registerHelper = Ember.HTMLBars._registerHelper || Ember.HTMLBars.registerHelper; - } else { - registerHelper = Ember.Handlebars.registerHelper; - } registerHelper('ember-list', EmberList); registerHelper('ember-virtual-list', EmberVirtualList); } diff --git a/addon/register-helper.js b/addon/register-helper.js new file mode 100644 index 0000000..e7aaedf --- /dev/null +++ b/addon/register-helper.js @@ -0,0 +1,33 @@ +import Ember from 'ember'; + +function registerHelperIteration1(name, helperFunction) { + //earlier versions of ember with htmlbars used this + Ember.HTMLBars.helpers[name] = helperFunction; +} + +function registerHelperIteration2(name, helperFunction) { + //registerHelper has been made private as _registerHelper + //this is kept here if anyone is using it + Ember.HTMLBars.registerHelper(name, helperFunction); +} + +function registerHelperIteration3(name, helperFunction) { + //latest versin of ember uses this + Ember.HTMLBars._registerHelper(name, helperFunction); +} + +export default function registerHelper(name, helperFunction) { + if (Ember.HTMLBars) { + if (Ember.HTMLBars._registerHelper) { + if (Ember.HTMLBars.helpers) { + registerHelperIteration1(name, helperFunction); + } else { + registerHelperIteration3(name, helperFunction); + } + } else if (Ember.HTMLBars.registerHelper) { + registerHelperIteration2(name, helperFunction); + } + } else if (Ember.Handlebars) { + Ember.Handlebars.helper(name, helperFunction); + } +}