ES6: Convert a view, adds a backwards compatibility layer with

deprecations for the old view helper names.
This commit is contained in:
Robin Ward 2014-06-05 14:26:59 -04:00
parent 2f706d084f
commit e65283ecf5
4 changed files with 47 additions and 7 deletions

View File

@ -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);
});
});
}
};

View File

@ -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);
});
});
}
};

View File

@ -7,7 +7,7 @@
<td style="width:80px" class="label"><label for='new-account-name'>{{i18n user.name.title}}</label></td>
<td style="width:496px">
{{textField value=accountName id="new-account-name" autofocus="autofocus"}}
&nbsp;{{inputTip validation=nameValidation}}
&nbsp;{{input-tip validation=nameValidation}}
</td>
</tr>
<tr class="instructions">
@ -19,7 +19,7 @@
<td class="label"><label for='new-account-email'>{{i18n user.email.title}}</label></td>
<td>
{{input value=accountEmail id="new-account-email" disabled=emailValidated}}
&nbsp;{{inputTip validation=emailValidation}}
&nbsp;{{input-tip validation=emailValidation}}
</td>
</tr>
<tr class="instructions">
@ -31,7 +31,7 @@
<td class="label"><label for='new-account-username'>{{i18n user.username.title}}</label></td>
<td>
{{input value=accountUsername id="new-account-username" maxlength="15"}}
&nbsp;{{inputTip validation=usernameValidation}}
&nbsp;{{input-tip validation=usernameValidation}}
</td>
</tr>
<tr class="instructions">
@ -44,7 +44,7 @@
<td class="label"><label for='new-account-password'>{{i18n user.password.title}}</label></td>
<td>
{{input type="password" value=accountPassword id="new-account-password"}}
&nbsp;{{inputTip validation=passwordValidation}}
&nbsp;{{input-tip validation=passwordValidation}}
</td>
</tr>
<tr class="instructions">

View File

@ -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);