From e65283ecf592e47a4689b6eda02ef62d620fce70 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 5 Jun 2014 14:26:59 -0400 Subject: [PATCH] ES6: Convert a view, adds a backwards compatibility layer with deprecations for the old view helper names. --- .../initializers/deprecations.js.es6 | 21 +++++++++++++++++++ .../initializers/view-helpers.js.es6 | 21 +++++++++++++++++++ .../modal/create_account.js.handlebars | 8 +++---- .../{input_tip_view.js => input-tip.js.es6} | 4 +--- 4 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 app/assets/javascripts/discourse/initializers/deprecations.js.es6 create mode 100644 app/assets/javascripts/discourse/initializers/view-helpers.js.es6 rename app/assets/javascripts/discourse/views/{input_tip_view.js => input-tip.js.es6} (83%) diff --git a/app/assets/javascripts/discourse/initializers/deprecations.js.es6 b/app/assets/javascripts/discourse/initializers/deprecations.js.es6 new file mode 100644 index 00000000000..f25c7ec1002 --- /dev/null +++ b/app/assets/javascripts/discourse/initializers/deprecations.js.es6 @@ -0,0 +1,21 @@ +var deprecatedViewHelpers = { + inputTip: 'input-tip' +}; + +export default { + name: 'deprecations', + initialize: function(container) { + Ember.keys(deprecatedViewHelpers).forEach(function(old) { + var newName = deprecatedViewHelpers[old]; + Ember.Handlebars.registerHelper(old, function(options) { + Em.warn("The `" + old +"` helper is deprecated. Use `" + newName + "` instead."); + var helper = container.lookupFactory('view:' + newName); + var hash = options.hash, + types = options.hashTypes; + + Discourse.Utilities.normalizeHash(hash, types); + return Ember.Handlebars.helpers.view.call(this, helper, options); + }); + }); + } +}; diff --git a/app/assets/javascripts/discourse/initializers/view-helpers.js.es6 b/app/assets/javascripts/discourse/initializers/view-helpers.js.es6 new file mode 100644 index 00000000000..97ab6e9116f --- /dev/null +++ b/app/assets/javascripts/discourse/initializers/view-helpers.js.es6 @@ -0,0 +1,21 @@ +var helpers = ['input-tip']; + +/** + Creates view helpers for some views. Many of these should probably be converted + into components in the long term as it's a better fit. +**/ +export default { + name: 'view-hlpers', + initialize: function(container) { + helpers.forEach(function(h) { + Ember.Handlebars.registerHelper(h, function(options) { + var helper = container.lookupFactory('view:' + h); + var hash = options.hash, + types = options.hashTypes; + + Discourse.Utilities.normalizeHash(hash, types); + return Ember.Handlebars.helpers.view.call(this, helper, options); + }); + }); + } +}; diff --git a/app/assets/javascripts/discourse/templates/modal/create_account.js.handlebars b/app/assets/javascripts/discourse/templates/modal/create_account.js.handlebars index 0c0ecf277a4..4dfa9d191ae 100644 --- a/app/assets/javascripts/discourse/templates/modal/create_account.js.handlebars +++ b/app/assets/javascripts/discourse/templates/modal/create_account.js.handlebars @@ -7,7 +7,7 @@ {{textField value=accountName id="new-account-name" autofocus="autofocus"}} -  {{inputTip validation=nameValidation}} +  {{input-tip validation=nameValidation}} @@ -19,7 +19,7 @@ {{input value=accountEmail id="new-account-email" disabled=emailValidated}} -  {{inputTip validation=emailValidation}} +  {{input-tip validation=emailValidation}} @@ -31,7 +31,7 @@ {{input value=accountUsername id="new-account-username" maxlength="15"}} -  {{inputTip validation=usernameValidation}} +  {{input-tip validation=usernameValidation}} @@ -44,7 +44,7 @@ {{input type="password" value=accountPassword id="new-account-password"}} -  {{inputTip validation=passwordValidation}} +  {{input-tip validation=passwordValidation}} diff --git a/app/assets/javascripts/discourse/views/input_tip_view.js b/app/assets/javascripts/discourse/views/input-tip.js.es6 similarity index 83% rename from app/assets/javascripts/discourse/views/input_tip_view.js rename to app/assets/javascripts/discourse/views/input-tip.js.es6 index 5976092051f..b2d0709c912 100644 --- a/app/assets/javascripts/discourse/views/input_tip_view.js +++ b/app/assets/javascripts/discourse/views/input-tip.js.es6 @@ -6,7 +6,7 @@ @namespace Discourse @module Discourse **/ -Discourse.InputTipView = Discourse.View.extend({ +export default Discourse.View.extend({ classNameBindings: [':tip', 'good', 'bad'], shouldRerender: Discourse.View.renderIfChanged('validation'), @@ -21,5 +21,3 @@ Discourse.InputTipView = Discourse.View.extend({ } } }); - -Discourse.View.registerHelper('inputTip', Discourse.InputTipView); \ No newline at end of file