Migrated more helpers to ES6 preferred format
This commit is contained in:
parent
d010eee5d8
commit
3c26bca56a
|
@ -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({
|
export default DiscourseController.extend({
|
||||||
needs: ['topic'],
|
needs: ['topic'],
|
||||||
|
|
||||||
|
displayDate: function() {
|
||||||
|
return Discourse.Formatter.longDateNoYear(new Date(this.get('date')));
|
||||||
|
}.property('date'),
|
||||||
|
|
||||||
// Close the share controller
|
// Close the share controller
|
||||||
actions: {
|
actions: {
|
||||||
close: function() {
|
close: function() {
|
||||||
|
|
|
@ -45,16 +45,6 @@ Handlebars.registerHelper('raw-date', function(property, options) {
|
||||||
return Discourse.Formatter.longDate(dt);
|
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
|
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 }));
|
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>");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
});
|
|
@ -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>
|
<h3>{{view.title}}</h3>
|
||||||
|
|
||||||
{{#if date}}
|
{{#if date}}
|
||||||
<span class="date">{{bound-raw-date date}}</span>
|
<span class="date">{{displayDate}}</span>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<div><input type='text' /></div>
|
<div><input type='text' /></div>
|
||||||
|
|
Loading…
Reference in New Issue