mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 17:02:45 +08:00
Migrated more helpers to ES6 preferred format
This commit is contained in:
parent
d010eee5d8
commit
3c26bca56a
3
app/assets/javascripts/admin/helpers/human-size.js.es6
Normal file
3
app/assets/javascripts/admin/helpers/human-size.js.es6
Normal file
|
@ -0,0 +1,3 @@
|
|||
Em.Handlebars.helper('human-size', function(size) {
|
||||
return new Handlebars.SafeString(I18n.toHumanSize(size));
|
||||
});
|
|
@ -3,6 +3,10 @@ import DiscourseController from 'discourse/controllers/controller';
|
|||
export default DiscourseController.extend({
|
||||
needs: ['topic'],
|
||||
|
||||
displayDate: function() {
|
||||
return Discourse.Formatter.longDateNoYear(new Date(this.get('date')));
|
||||
}.property('date'),
|
||||
|
||||
// Close the share controller
|
||||
actions: {
|
||||
close: function() {
|
||||
|
|
|
@ -45,16 +45,6 @@ Handlebars.registerHelper('raw-date', function(property, options) {
|
|||
return Discourse.Formatter.longDate(dt);
|
||||
});
|
||||
|
||||
/**
|
||||
Nicely format a bound date without returning HTML
|
||||
|
||||
@method bound-raw-date
|
||||
@for Handlebars
|
||||
**/
|
||||
Em.Handlebars.helper('bound-raw-date', function (date) {
|
||||
return Discourse.Formatter.longDateNoYear(new Date(date));
|
||||
});
|
||||
|
||||
/**
|
||||
Live refreshing age helper
|
||||
|
||||
|
@ -138,46 +128,3 @@ Em.Handlebars.helper('bound-date', function(dt) {
|
|||
return new safe(Discourse.Formatter.autoUpdatingRelativeAge(new Date(dt), {format: 'medium', title: true }));
|
||||
});
|
||||
|
||||
/**
|
||||
Look for custom html content using `Discourse.HTML`. If none exists, look for a template
|
||||
to render with that name.
|
||||
|
||||
@method custom-html
|
||||
@for Handlebars
|
||||
**/
|
||||
Handlebars.registerHelper('custom-html', function(name, contextString, options) {
|
||||
var html = Discourse.HTML.getCustomHTML(name);
|
||||
if (html) { return html; }
|
||||
|
||||
var container = (options || contextString).data.keywords.controller.container;
|
||||
|
||||
if (container.lookup('template:' + name)) {
|
||||
return Ember.Handlebars.helpers.partial.apply(this, arguments);
|
||||
}
|
||||
});
|
||||
|
||||
Em.Handlebars.helper('human-size', function(size) {
|
||||
return new safe(I18n.toHumanSize(size));
|
||||
});
|
||||
|
||||
/**
|
||||
Renders the domain for a link if it's not internal and has a title.
|
||||
|
||||
@method link-domain
|
||||
@for Handlebars
|
||||
**/
|
||||
Handlebars.registerHelper('link-domain', function(property, options) {
|
||||
var link = Em.get(this, property, options);
|
||||
if (link) {
|
||||
var internal = Em.get(link, 'internal'),
|
||||
hasTitle = (!Em.isEmpty(Em.get(link, 'title')));
|
||||
if (hasTitle && !internal) {
|
||||
var domain = Em.get(link, 'domain');
|
||||
if (!Em.isEmpty(domain)) {
|
||||
var s = domain.split('.');
|
||||
domain = s[s.length-2] + "." + s[s.length-1];
|
||||
return new safe("<span class='domain'>" + domain + "</span>");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
10
app/assets/javascripts/discourse/helpers/custom-html.js.es6
Normal file
10
app/assets/javascripts/discourse/helpers/custom-html.js.es6
Normal file
|
@ -0,0 +1,10 @@
|
|||
Handlebars.registerHelper('custom-html', function(name, contextString, options) {
|
||||
var html = Discourse.HTML.getCustomHTML(name);
|
||||
if (html) { return html; }
|
||||
|
||||
var container = (options || contextString).data.keywords.controller.container;
|
||||
|
||||
if (container.lookup('template:' + name)) {
|
||||
return Ember.Handlebars.helpers.partial.apply(this, arguments);
|
||||
}
|
||||
});
|
15
app/assets/javascripts/discourse/helpers/link-domain.js.es6
Normal file
15
app/assets/javascripts/discourse/helpers/link-domain.js.es6
Normal file
|
@ -0,0 +1,15 @@
|
|||
Handlebars.registerHelper('link-domain', function(property, options) {
|
||||
var link = Em.get(this, property, options);
|
||||
if (link) {
|
||||
var internal = Em.get(link, 'internal'),
|
||||
hasTitle = (!Em.isEmpty(Em.get(link, 'title')));
|
||||
if (hasTitle && !internal) {
|
||||
var domain = Em.get(link, 'domain');
|
||||
if (!Em.isEmpty(domain)) {
|
||||
var s = domain.split('.');
|
||||
domain = s[s.length-2] + "." + s[s.length-1];
|
||||
return new Handlebars.SafeString("<span class='domain'>" + domain + "</span>");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
|
@ -1,7 +1,7 @@
|
|||
<h3>{{view.title}}</h3>
|
||||
|
||||
{{#if date}}
|
||||
<span class="date">{{bound-raw-date date}}</span>
|
||||
<span class="date">{{displayDate}}</span>
|
||||
{{/if}}
|
||||
|
||||
<div><input type='text' /></div>
|
||||
|
|
Loading…
Reference in New Issue
Block a user