Deprecation: Use `Ember.Helper` for later versions of Ember

This commit is contained in:
Robin Ward 2016-05-10 13:45:58 -04:00
parent b3c24e50e3
commit 7c0fb41ec0
No known key found for this signature in database
GPG Key ID: 0E091E2B4ED1B83D
41 changed files with 111 additions and 113 deletions

View File

@ -1,3 +1,3 @@
Em.Handlebars.helper('human-size', function(size) {
return new Handlebars.SafeString(I18n.toHumanSize(size));
});
import { htmlHelper } from 'discourse/lib/helpers';
export default htmlHelper(size => I18n.toHumanSize(size));

View File

@ -1,3 +1,3 @@
Em.Handlebars.helper('preserve-newlines', str => {
return new Handlebars.SafeString(Discourse.Utilities.escapeExpression(str).replace(/\n/g, "<br>"));
});
import { htmlHelper } from 'discourse/lib/helpers';
export default htmlHelper(str => Discourse.Utilities.escapeExpression(str).replace(/\n/g, "<br>"));

View File

@ -1,4 +1,4 @@
import registerUnbound from 'discourse/helpers/register-unbound';
import { registerUnbound } from 'discourse/lib/helpers';
registerUnbound('value-at-tl', function(data, params) {
var tl = parseInt(params.level, 10);

View File

@ -32,7 +32,7 @@
</li>
<li class='toggle-maximize'>
<a {{action "toggleMaximize"}}>
{{fa-icon-bound maximizeIcon}}
<i class="fa fa-{{maximizeIcon}}"></i>
</a>
</li>
</ul>

View File

@ -16,7 +16,6 @@ function customTagArray(fieldName) {
export default Ember.Controller.extend(ModalFunctionality, {
loading: true,
viewMode: "side_by_side",
revisionsTextKey: "post.revisions.controls.comparing_previous_to_current_out_of_total",
_changeViewModeOnMobile: function() {
if (this.site.mobileView) { this.set("viewMode", "inline"); }
@ -25,6 +24,13 @@ export default Ember.Controller.extend(ModalFunctionality, {
previousTagChanges: customTagArray('model.tags_changes.previous'),
currentTagChanges: customTagArray('model.tags_changes.current'),
@computed('previousVersion', 'model.current_version', 'model.version_count')
revisionsText(previous, current, total) {
return I18n.t("post.revisions.controls.comparing_previous_to_current_out_of_total", {
previous, current, total
});
},
refresh(postId, postVersion) {
this.set("loading", true);

View File

@ -1,24 +1,8 @@
import registerUnbound from 'discourse/helpers/register-unbound';
import { registerUnbound } from 'discourse/lib/helpers';
import { longDate, autoUpdatingRelativeAge, number } from 'discourse/lib/formatter';
const safe = Handlebars.SafeString;
Em.Handlebars.helper('bound-avatar', (user, size) => {
if (Em.isEmpty(user)) {
return new safe("<div class='avatar-placeholder'></div>");
}
const avatar = Em.get(user, 'avatar_template');
return new safe(Discourse.Utilities.avatarImg({ size: size, avatarTemplate: avatar }));
}, 'username', 'avatar_template');
/*
* Used when we only have a template
*/
Em.Handlebars.helper('bound-avatar-template', (at, size) => {
return new safe(Discourse.Utilities.avatarImg({ size: size, avatarTemplate: at }));
});
registerUnbound('raw-date', dt => longDate(new Date(dt)));
registerUnbound('age-with-tooltip', dt => new safe(autoUpdatingRelativeAge(new Date(dt), {title: true})));

View File

@ -1,4 +1,3 @@
export default Ember.Handlebars.makeBoundHelper(function(value) {
return ("border-color: #" + value).htmlSafe();
});
import { htmlHelper } from 'discourse/lib/helpers';
export default htmlHelper(color => `border-color: #${color}`);

View File

@ -0,0 +1,5 @@
import { htmlHelper } from 'discourse/lib/helpers';
export default htmlHelper((avatarTemplate, size) => {
return Discourse.Utilities.avatarImg({ size, avatarTemplate });
});

View File

@ -0,0 +1,10 @@
import { htmlHelper } from 'discourse/lib/helpers';
export default htmlHelper((user, size) => {
if (Ember.isEmpty(user)) {
return "<div class='avatar-placeholder'></div>";
}
const avatarTemplate = Em.get(user, 'avatar_template');
return Discourse.Utilities.avatarImg({ size, avatarTemplate });
});

View File

@ -0,0 +1,4 @@
import { htmlHelper } from 'discourse/lib/helpers';
import { categoryLinkHTML } from 'discourse/helpers/category-link';
export default htmlHelper(categoryLinkHTML);

View File

@ -1,5 +1,4 @@
import { autoUpdatingRelativeAge } from 'discourse/lib/formatter';
import { htmlHelper } from 'discourse/lib/helpers';
export default Ember.Handlebars.makeBoundHelper(function(dt) {
return new Handlebars.SafeString(autoUpdatingRelativeAge(new Date(dt), {format: 'medium', title: true }));
});
export default htmlHelper(dt => autoUpdatingRelativeAge(new Date(dt), {format: 'medium', title: true }));

View File

@ -1,3 +0,0 @@
Ember.Handlebars.registerBoundHelper("boundI18n", function(property, options) {
return new Handlebars.SafeString(I18n.t(property, options.hash));
});

View File

@ -0,0 +1,3 @@
import { htmlHelper } from 'discourse/lib/helpers';
export default htmlHelper(str => str[0].toUpperCase() + str.slice(1));

View File

@ -1,3 +0,0 @@
Ember.Handlebars.registerBoundHelper("capitalize", function(str) {
return str[0].toUpperCase() + str.slice(1);
});

View File

@ -1,5 +1,5 @@
import { categoryLinkHTML } from 'discourse/helpers/category-link';
import registerUnbound from 'discourse/helpers/register-unbound';
import { registerUnbound } from 'discourse/lib/helpers';
registerUnbound('category-badge', function(cat, options) {
options.link = false;

View File

@ -1,4 +1,4 @@
import registerUnbound from 'discourse/helpers/register-unbound';
import { registerUnbound } from 'discourse/lib/helpers';
import { iconHTML } from 'discourse/helpers/fa-icon';
var get = Em.get,
@ -94,4 +94,3 @@ export function categoryLinkHTML(category, options) {
}
registerUnbound('category-link', categoryLinkHTML);
Ember.Handlebars.helper('bound-category-link', categoryLinkHTML);

View File

@ -1,4 +1,4 @@
import registerUnbound from 'discourse/helpers/register-unbound';
import { registerUnbound } from 'discourse/lib/helpers';
function daysSinceEpoch(dt) {
// 1000 * 60 * 60 * 24 = days since epoch

View File

@ -1,4 +1,4 @@
import registerUnbound from 'discourse/helpers/register-unbound';
import { registerUnbound } from 'discourse/lib/helpers';
registerUnbound('cook-text', function(text) {
return new Handlebars.SafeString(Discourse.Markdown.cook(text, {sanitize: true}));

View File

@ -1,3 +1,5 @@
import { registerHelper } from 'discourse/lib/helpers';
const _customizations = {};
export function getCustomHTML(key) {
@ -17,13 +19,14 @@ export function setCustomHTML(key, html) {
_customizations[key] = html;
}
Ember.HTMLBars._registerHelper('custom-html', function(params, hash, options, env) {
registerHelper('custom-html', function(params, hash, options, env) {
const name = params[0];
const html = getCustomHTML(name);
if (html) { return html; }
const contextString = params[1];
const container = (env || contextString).data.view.container;
const target = (env || contextString);
const container = target.container || target.data.view.container;
if (container.lookup('template:' + name)) {
return env.helpers.partial.helperFunction.apply(this, arguments);
}

View File

@ -1,3 +1,3 @@
export default Ember.Handlebars.makeBoundHelper(function(str) {
return Ember.isEmpty(str) ? new Handlebars.SafeString('&mdash;') : str;
});
import { htmlHelper } from 'discourse/lib/helpers';
export default htmlHelper(str => Ember.isEmpty(str) ? '&mdash;' : str);

View File

@ -1,4 +1,4 @@
import registerUnbound from 'discourse/helpers/register-unbound';
import { registerUnbound } from 'discourse/lib/helpers';
import renderTag from 'discourse/lib/render-tag';
export default registerUnbound('discourse-tag', function(name, params) {

View File

@ -1,5 +1,5 @@
import { h } from 'virtual-dom';
import registerUnbound from 'discourse/helpers/register-unbound';
import { registerUnbound } from 'discourse/lib/helpers';
function iconClasses(icon, params) {
var classes = "fa fa-" + icon;
@ -37,11 +37,6 @@ export function iconNode(icon, params) {
}
}
Ember.Handlebars.helper('fa-icon-bound', function(value, options) {
return new Handlebars.SafeString(iconHTML(value, options));
});
registerUnbound('fa-icon', function(icon, params) {
return new Handlebars.SafeString(iconHTML(icon, params));
});

View File

@ -1,5 +1,5 @@
import { autoUpdatingRelativeAge } from 'discourse/lib/formatter';
import registerUnbound from 'discourse/helpers/register-unbound';
import { registerUnbound } from 'discourse/lib/helpers';
registerUnbound('format-age', function(dt) {
dt = new Date(dt);

View File

@ -1,4 +1,4 @@
import registerUnbound from 'discourse/helpers/register-unbound';
import { registerUnbound } from 'discourse/lib/helpers';
import { autoUpdatingRelativeAge } from 'discourse/lib/formatter';
/**

View File

@ -1,4 +1,4 @@
import registerUnbound from 'discourse/helpers/register-unbound';
import { registerUnbound } from 'discourse/lib/helpers';
registerUnbound('i18n', function(key, params) {
return I18n.t(key, params);

View File

@ -1,9 +1,6 @@
export default Ember.Handlebars.makeBoundHelper(function(str) {
if (Ember.isEmpty(str)) { return ""; }
import { htmlHelper } from 'discourse/lib/helpers';
if (str.indexOf('fa-') === 0) {
return new Handlebars.SafeString("<i class='fa " + str + "'></i>");
} else {
return new Handlebars.SafeString("<img src='" + str + "'>");
}
export default htmlHelper(function(str) {
if (Ember.isEmpty(str)) { return ""; }
return (str.indexOf('fa-') === 0) ? `<i class='fa ${str}'></i>` : `<img src='${str}'>`;
});

View File

@ -1,3 +1,5 @@
import { htmlHelper } from 'discourse/lib/helpers';
function renderSpinner(cssClass) {
var html = "<div class='spinner";
if (cssClass) { html += ' ' + cssClass; }
@ -5,9 +7,9 @@ function renderSpinner(cssClass) {
}
var spinnerHTML = renderSpinner();
Ember.Handlebars.registerHelper('loading-spinner', function(params) {
export default htmlHelper(params => {
const hash = params.hash;
return new Handlebars.SafeString(renderSpinner((hash && hash.size) ? hash.size : undefined));
return renderSpinner((hash && hash.size) ? hash.size : undefined);
});
export { spinnerHTML, renderSpinner };

View File

@ -1,4 +1,4 @@
import registerUnbound from 'discourse/helpers/register-unbound';
import { registerUnbound } from 'discourse/lib/helpers';
registerUnbound('max-usernames', function(usernames, params) {
var maxLength = parseInt(params.max) || 3;

View File

@ -1,3 +1,5 @@
import { htmlHelper } from 'discourse/lib/helpers';
const TITLE_SUBS = {
all: 'all_time',
yearly: 'this_year',
@ -6,7 +8,7 @@ const TITLE_SUBS = {
daily: 'today',
};
export default Ember.Handlebars.makeBoundHelper(function (period, options) {
export default htmlHelper((period, options) => {
const title = I18n.t('filters.top.' + (TITLE_SUBS[period] || 'this_week'));
if (options.hash.showDateRange) {
var dateString = "";
@ -27,8 +29,9 @@ export default Ember.Handlebars.makeBoundHelper(function (period, options) {
dateString = moment().format(I18n.t('dates.full_no_year_no_time'));
break;
}
return new Handlebars.SafeString(title + " <span class='top-date-string'>" + dateString + "</span>");
return `${title} <span class='top-date-string'>${dateString}</span>`;
} else {
return new Handlebars.SafeString(title);
return title;
}
});

View File

@ -46,13 +46,7 @@
The list of disabled plugins is returned via the `Site` singleton.
**/
// TODO: Add all plugin-outlet names dynamically
const rewireableOutlets = [
'hamburger-admin'
];
const _rewires = {};
import { registerHelper } from 'discourse/lib/helpers';
let _connectorCache, _rawCache;
@ -73,14 +67,6 @@ function findOutlets(collection, callback) {
let outletName = segments[segments.length-2];
const uniqueName = segments[segments.length-1];
const outletRewires = _rewires[outletName];
if (outletRewires) {
const newOutlet = outletRewires[uniqueName];
if (newOutlet) {
outletName = newOutlet;
}
}
callback(outletName, res, uniqueName);
}
});
@ -144,7 +130,6 @@ function viewInjections(container) {
// unbound version of outlets, only has a template
Handlebars.registerHelper('plugin-outlet', function(name){
if (!_rawCache) { buildConnectorCache(); }
const functions = _rawCache[name];
@ -160,7 +145,7 @@ Handlebars.registerHelper('plugin-outlet', function(name){
});
Ember.HTMLBars._registerHelper('plugin-outlet', function(params, hash, options, env) {
registerHelper('plugin-outlet', function(params, hash, options, env) {
const connectionName = params[0];
if (!_connectorCache) { buildConnectorCache(); }
@ -190,11 +175,5 @@ Ember.HTMLBars._registerHelper('plugin-outlet', function(params, hash, options,
}
});
// Allow plugins to rewire outlets to new outlets if they exist. For example, the akismet
// plugin will use `hamburger-admin` if it exists, otherwise `site-menu-links`
export function rewire(uniqueName, outlet, wantedOutlet) {
if (rewireableOutlets.indexOf(wantedOutlet) !== -1) {
_rewires[outlet] = _rewires[outlet] || {};
_rewires[outlet][uniqueName] = wantedOutlet;
}
}
// No longer used
export function rewire() { }

View File

@ -1,4 +1,4 @@
import registerUnbound from 'discourse/helpers/register-unbound';
import { registerUnbound } from 'discourse/lib/helpers';
// see: https://github.com/emberjs/ember.js/issues/12634
var missingViews = {};

View File

@ -1,4 +1,4 @@
import registerUnbound from 'discourse/helpers/register-unbound';
import { registerUnbound } from 'discourse/lib/helpers';
registerUnbound('shorten-url', function(url) {
var matches = url.match(/\//g);

View File

@ -1,4 +1,4 @@
import registerUnbound from 'discourse/helpers/register-unbound';
import { registerUnbound } from 'discourse/lib/helpers';
registerUnbound('topic-link', function(topic) {
var title = topic.get('fancyTitle');

View File

@ -1,4 +1,4 @@
import registerUnbound from 'discourse/helpers/register-unbound';
import { registerUnbound } from 'discourse/lib/helpers';
function renderAvatar(user, options) {
options = options || {};

View File

@ -1,17 +1,16 @@
import { iconHTML } from 'discourse/helpers/fa-icon';
import { htmlHelper } from 'discourse/lib/helpers';
const Safe = Handlebars.SafeString;
export default Ember.Handlebars.makeBoundHelper(function(user, args) {
export default htmlHelper((user, args) => {
if (!user) { return; }
const name = Discourse.Utilities.escapeExpression(user.get('name'));
const currentUser = args.hash.currentUser;
if (currentUser && user.get('admin') && currentUser.get('staff')) {
return new Safe(iconHTML('shield', { label: I18n.t('user.admin', { user: name }) }));
return iconHTML('shield', { label: I18n.t('user.admin', { user: name }) });
}
if (user.get('moderator')) {
return new Safe(iconHTML('shield', { label: I18n.t('user.moderator', { user: name }) }));
return iconHTML('shield', { label: I18n.t('user.moderator', { user: name }) });
}
});

View File

@ -148,7 +148,8 @@
RawHandlebars.get = function(ctx, property, options){
if (options.types && options.data.view) {
return options.data.view.getStream(property).value();
var view = options.data.view;
return view.getStream ? view.getStream(property).value() : view.getAttr(property);
} else {
return Ember.get(ctx, property);
}

View File

@ -1,3 +1,20 @@
// `Ember.Helper` is only available in versions after 1.12
export function htmlHelper(fn) {
if (Ember.Helper) {
return Ember.Helper.helper(function() {
return new Handlebars.SafeString(fn.apply(this, Array.prototype.slice.call(arguments)));
});
} else {
return Ember.Handlebars.makeBoundHelper(function() {
return new Handlebars.SafeString(fn.apply(this, Array.prototype.slice.call(arguments)));
});
}
}
export function registerHelper(name, fn) {
Ember.HTMLBars._registerHelper(name, fn);
}
const get = Discourse.EmberCompatHandlebars.get;
function resolveParams(ctx, options) {
@ -21,7 +38,7 @@ function resolveParams(ctx, options) {
return params;
}
export default function registerUnbound(name, fn) {
export function registerUnbound(name, fn) {
const func = function(property, options) {
if (options.types && (options.types[0] === "ID" || options.types[0] === "PathExpression")) {
property = get(this, property, options);

View File

@ -5,7 +5,7 @@
{{d-button action="loadPreviousVersion" icon="backward" title="post.revisions.controls.previous" disabled=loadPreviousDisabled}}
<div id="revision-numbers" class="{{unless displayRevisions 'invisible'}}">
{{#conditional-loading-spinner condition=loading size="small"}}
{{boundI18n revisionsTextKey previous=previousVersion current=model.current_version total=model.version_count}}
{{{revisionsText}}}
{{/conditional-loading-spinner}}
</div>
{{d-button action="loadNextVersion" icon="forward" title="post.revisions.controls.next" disabled=loadNextDisabled}}

View File

@ -26,7 +26,7 @@
<li>
{{#link-to 'userPrivateMessages.group' group.name}}
<i class='glyph fa fa-group'></i>
{{capitalize group.name}}
{{capitalize-string group.name}}
{{/link-to}}
</li>
<li class='archive'>

View File

@ -14,14 +14,14 @@
//= require ./discourse/lib/debounce
//= require ./discourse/lib/quote
//= require ./discourse/lib/key-value-store
//= require ./discourse/lib/helpers
//= require ./discourse/helpers/i18n
//= require ./discourse/helpers/fa-icon
//= require ./discourse/helpers/register-unbound
//= require ./discourse/lib/ember_compat_handlebars
//= require ./discourse/lib/helpers
//= require ./discourse/lib/computed
//= require ./discourse/lib/formatter
//= require ./discourse/lib/eyeline
//= require ./discourse/helpers/register-unbound
//= require ./discourse/mixins/scrolling
//= require ./discourse/models/model
//= require ./discourse/models/rest
@ -88,7 +88,6 @@
//= require ./discourse/components/conditional-loading-spinner
//= require ./discourse/helpers/user-avatar
//= require ./discourse/helpers/cold-age-class
//= require ./discourse/helpers/capitalize
//= require ./discourse/helpers/loading-spinner
//= require ./discourse/helpers/category-link
//= require ./discourse/lib/export-result

View File

@ -24,7 +24,7 @@ export default Em.Component.extend({
options.forEach((option, i) => {
const percentage = percentages[i];
const style = new Ember.Handlebars.SafeString(`width: ${percentage}%`);
const style = new Handlebars.SafeString(`width: ${percentage}%`);
option.setProperties({
percentage,