Migrate more helpers to ES6 format.

This commit is contained in:
Robin Ward 2014-09-12 14:27:34 -04:00
parent 6f149edecc
commit 1de9c3b04a
20 changed files with 52 additions and 63 deletions

View File

@ -19,7 +19,7 @@
{{#each model}} {{#each model}}
<tr> <tr>
<td>{{date created_at}}</td> <td>{{format-date created_at}}</td>
<td> <td>
{{#if user}} {{#if user}}
{{#link-to 'adminUser' user}}{{avatar user imageSize="tiny"}}{{/link-to}} {{#link-to 'adminUser' user}}{{avatar user imageSize="tiny"}}{{/link-to}}

View File

@ -19,7 +19,7 @@
{{#each model}} {{#each model}}
<tr> <tr>
<td>{{date created_at}}</td> <td>{{format-date created_at}}</td>
<td> <td>
{{#if user}} {{#if user}}
{{#link-to 'adminUser' user}}{{avatar user imageSize="tiny"}}{{/link-to}} {{#link-to 'adminUser' user}}{{avatar user imageSize="tiny"}}{{/link-to}}

View File

@ -19,7 +19,7 @@
{{#each model}} {{#each model}}
<tr> <tr>
<td>{{date created_at}}</td> <td>{{format-date created_at}}</td>
<td> <td>
{{#if user}} {{#if user}}
{{#link-to 'adminUser' user}}{{avatar user imageSize="tiny"}}{{/link-to}} {{#link-to 'adminUser' user}}{{avatar user imageSize="tiny"}}{{/link-to}}

View File

@ -66,7 +66,7 @@
{{#link-to 'adminUser' user}} {{#link-to 'adminUser' user}}
{{user.username}} {{user.username}}
{{/link-to}} {{/link-to}}
{{age flaggedAt}} {{format-age flaggedAt}}
<br /> <br />
{{flagType}} {{flagType}}
</td> </td>
@ -88,7 +88,7 @@
{{/link-to}} {{/link-to}}
</td> </td>
<td> <td>
{{age disposedAt}} {{format-age disposedAt}}
{{{dispositionIcon}}} {{{dispositionIcon}}}
{{#if tookAction}} {{#if tookAction}}
<i class='fa fa-gavel' title='{{i18n admin.flags.took_action}}'></i> <i class='fa fa-gavel' title='{{i18n admin.flags.took_action}}'></i>

View File

@ -45,17 +45,6 @@ Handlebars.registerHelper('raw-date', function(property, options) {
return Discourse.Formatter.longDate(dt); return Discourse.Formatter.longDate(dt);
}); });
/**
Live refreshing age helper
@method age
@for Handlebars
**/
Handlebars.registerHelper('age', function(property, options) {
var dt = new Date(Ember.Handlebars.get(this, property, options));
return new safe(Discourse.Formatter.autoUpdatingRelativeAge(dt));
});
/** /**
Live refreshing age helper, with a tooltip showing the date and time Live refreshing age helper, with a tooltip showing the date and time
@ -98,33 +87,3 @@ Handlebars.registerHelper('number', function(property, options) {
return new safe(result); return new safe(result);
}); });
/**
Display logic for dates. It is unbound in Ember but will use jQuery to
update the dates on a regular interval.
@method date
@for Handlebars
**/
Handlebars.registerHelper('date', function(property, options) {
var leaveAgo;
if (property.hash) {
if (property.hash.leaveAgo) {
leaveAgo = property.hash.leaveAgo === "true";
}
if (property.hash.path) {
property = property.hash.path;
}
}
var val = Ember.Handlebars.get(this, property, options);
if (val) {
var date = new Date(val);
return new safe(Discourse.Formatter.autoUpdatingRelativeAge(date, {format: 'medium', title: true, leaveAgo: leaveAgo}));
}
});
Em.Handlebars.helper('bound-date', function(dt) {
return new safe(Discourse.Formatter.autoUpdatingRelativeAge(new Date(dt), {format: 'medium', title: true }));
});

View File

@ -0,0 +1,3 @@
export default Ember.Handlebars.makeBoundHelper(function(dt) {
return new Handlebars.SafeString(Discourse.Formatter.autoUpdatingRelativeAge(new Date(dt), {format: 'medium', title: true }));
});

View File

@ -0,0 +1,4 @@
Handlebars.registerHelper('format-age', function(property, options) {
var dt = new Date(Ember.Handlebars.get(this, property, options));
return new Handlebars.SafeString(Discourse.Formatter.autoUpdatingRelativeAge(dt));
});

View File

@ -0,0 +1,21 @@
/**
Display logic for dates. It is unbound in Ember but will use jQuery to
update the dates on a regular interval.
**/
Handlebars.registerHelper('format-date', function(property, options) {
var leaveAgo;
if (property.hash) {
if (property.hash.leaveAgo) {
leaveAgo = property.hash.leaveAgo === "true";
}
if (property.hash.path) {
property = property.hash.path;
}
}
var val = Ember.Handlebars.get(this, property, options);
if (val) {
var date = new Date(val);
return new Handlebars.SafeString(Discourse.Formatter.autoUpdatingRelativeAge(date, {format: 'medium', title: true, leaveAgo: leaveAgo}));
}
});

View File

@ -10,7 +10,9 @@ var deprecatedViewHelpers = {
}; };
var renamedHelpers = { var renamedHelpers = {
icon: "fa-icon" icon: "fa-icon",
date: "format-date",
age: "format-age"
}; };
export default { export default {

View File

@ -25,7 +25,7 @@
{{avatar user imageSize="large"}} {{avatar user imageSize="large"}}
<div class="details"> <div class="details">
<span class="username">{{user.username}}</span> <span class="username">{{user.username}}</span>
{{date granted_at}} {{format-date granted_at}}
</div> </div>
{{/link-to}} {{/link-to}}

View File

@ -10,14 +10,14 @@
<a href='{{unbound topic.url}}'> <a href='{{unbound topic.url}}'>
<h4>{{i18n created_lowercase}}</h4> <h4>{{i18n created_lowercase}}</h4>
{{avatar details.created_by imageSize="tiny"}} {{avatar details.created_by imageSize="tiny"}}
{{date topic.created_at}} {{format-date topic.created_at}}
</a> </a>
</li> </li>
<li> <li>
<a {{bind-attr href="topic.lastPostUrl"}}> <a {{bind-attr href="topic.lastPostUrl"}}>
<h4>{{i18n last_post_lowercase}}</h4> <h4>{{i18n last_post_lowercase}}</h4>
{{avatar details.last_poster imageSize="tiny"}} {{avatar details.last_poster imageSize="tiny"}}
{{date topic.last_posted_at}} {{format-date topic.last_posted_at}}
</a> </a>
</li> </li>
<li> <li>

View File

@ -53,11 +53,11 @@
{{#if controller.latestTopicOnly}} {{#if controller.latestTopicOnly}}
<div class='last-user-info'> <div class='last-user-info'>
{{i18n categories.latest_by}} <a href="{{{unbound lastPosterUrl}}}">{{unbound last_poster.username}}</a> {{i18n categories.latest_by}} <a href="{{{unbound lastPosterUrl}}}">{{unbound last_poster.username}}</a>
<a href="{{unbound lastPostUrl}}">{{age last_posted_at}}</a> <a href="{{unbound lastPostUrl}}">{{format-age last_posted_at}}</a>
</div> </div>
{{else}} {{else}}
&nbsp; &nbsp;
<a href="{{unbound lastPostUrl}}" class="last-posted-at">{{age last_posted_at}}</a> <a href="{{unbound lastPostUrl}}" class="last-posted-at">{{format-age last_posted_at}}</a>
{{/if}} {{/if}}
</div> </div>
{{/each}} {{/each}}

View File

@ -3,7 +3,7 @@
<div class='item'> <div class='item'>
<div class='clearfix info'> <div class='clearfix info'>
{{#link-to 'user' user class="avatar-link"}}<div class='avatar-wrapper'>{{avatar user imageSize="large" extraClasses="actor" ignoreTitle="true"}}</div>{{/link-to}} {{#link-to 'user' user class="avatar-link"}}<div class='avatar-wrapper'>{{avatar user imageSize="large" extraClasses="actor" ignoreTitle="true"}}</div>{{/link-to}}
<span class='time'>{{date path="created_at" leaveAgo="true"}}</span> <span class='time'>{{format-date path="created_at" leaveAgo="true"}}</span>
<span class="title"> <span class="title">
<a href="{{unbound url}}">{{unbound title}}</a> <a href="{{unbound url}}">{{unbound title}}</a>
</span> </span>

View File

@ -37,7 +37,7 @@
</div> </div>
</td> </td>
<td class='num posts'>{{number posts_count}}</td> <td class='num posts'>{{number posts_count}}</td>
<td class='num age'><span class="{{cold-age-class created_at}}" title='{{raw-date created_at}}'>{{{age created_at}}}</span></td> <td class='num age'><span class="{{cold-age-class created_at}}" title='{{raw-date created_at}}'>{{{format-age created_at}}}</span></td>
</tr> </tr>
{{/each}} {{/each}}

View File

@ -4,7 +4,7 @@
</span> </span>
{{#unless controller.site.mobileView}} {{#unless controller.site.mobileView}}
<span class='blurb'> <span class='blurb'>
{{age created_at}} - {{{unbound blurb}}} {{format-age created_at}} - {{{unbound blurb}}}
</span> </span>
{{/unless}} {{/unless}}
</a> </a>

View File

@ -26,8 +26,8 @@
{{#if user}} {{#if user}}
<div class="metadata"> <div class="metadata">
{{#if user.location}}<h3>{{fa-icon "map-marker"}} {{user.location}}</h3>{{/if}} {{#if user.location}}<h3>{{fa-icon "map-marker"}} {{user.location}}</h3>{{/if}}
<h3>{{i18n last_post}} {{date path="user.last_posted_at" leaveAgo="true"}}</h3> <h3>{{i18n last_post}} {{format-date path="user.last_posted_at" leaveAgo="true"}}</h3>
<h3>{{i18n joined}} {{date path="user.created_at" leaveAgo="true"}}</h3> <h3>{{i18n joined}} {{format-date path="user.created_at" leaveAgo="true"}}</h3>
{{groups-list groups=user.custom_groups}} {{groups-list groups=user.custom_groups}}
</div> </div>

View File

@ -36,9 +36,9 @@
{{#link-to 'user' invite.user}}{{avatar invite.user imageSize="tiny"}}{{/link-to}} {{#link-to 'user' invite.user}}{{avatar invite.user imageSize="tiny"}}{{/link-to}}
{{#link-to 'user' invite.user}}{{invite.user.username}}{{/link-to}} {{#link-to 'user' invite.user}}{{invite.user.username}}{{/link-to}}
</td> </td>
<td>{{date invite.redeemed_at}}</td> <td>{{format-date invite.redeemed_at}}</td>
{{#if can_see_invite_details}} {{#if can_see_invite_details}}
<td>{{date invite.user.last_seen_at}}</td> <td>{{format-date invite.user.last_seen_at}}</td>
<td>{{number invite.user.topics_entered}}</td> <td>{{number invite.user.topics_entered}}</td>
<td>{{number invite.user.posts_read_count}}</td> <td>{{number invite.user.posts_read_count}}</td>
<td>{{{unbound invite.user.time_read}}}</td> <td>{{{unbound invite.user.time_read}}}</td>

View File

@ -12,7 +12,7 @@
<div {{bind-attr class=":item :notification read::unread"}}> <div {{bind-attr class=":item :notification read::unread"}}>
{{notification-item notification=this scope=scope}} {{notification-item notification=this scope=scope}}
<span class="time"> <span class="time">
{{date path="created_at" leaveAgo="true"}} {{format-date path="created_at" leaveAgo="true"}}
</span> </span>
</div> </div>
{{/each}} {{/each}}

View File

@ -7,7 +7,7 @@
</div> </div>
</a> </a>
<span class="time"> <span class="time">
{{date path="created_at" leaveAgo="true"}} {{format-date path="created_at" leaveAgo="true"}}
</span> </span>
<span class="title"> <span class="title">
<a href="{{unbound url}}">{{unbound topic_title}}</a> <a href="{{unbound url}}">{{unbound topic_title}}</a>
@ -17,7 +17,7 @@
</span> </span>
{{#if deleted}} {{#if deleted}}
<span class="delete-info"> <span class="delete-info">
<i class="fa fa-trash-o"></i> {{avatar deleted_by imageSize="tiny" extraClasses="actor" ignoreTitle="true"}} {{date path="deleted_at" leaveAgo="true"}} <i class="fa fa-trash-o"></i> {{avatar deleted_by imageSize="tiny" extraClasses="actor" ignoreTitle="true"}} {{format-date path="deleted_at" leaveAgo="true"}}
</span> </span>
{{/if}} {{/if}}
</div> </div>

View File

@ -2,7 +2,7 @@
<div {{bind-attr class=":item hidden deleted moderator_action"}}> <div {{bind-attr class=":item hidden deleted moderator_action"}}>
<div class='clearfix info'> <div class='clearfix info'>
<a href="{{unbound userUrl}}" data-user-expand="{{unbound username}}" class='avatar-link'><div class='avatar-wrapper'>{{avatar this imageSize="large" extraClasses="actor" ignoreTitle="true"}}</div></a> <a href="{{unbound userUrl}}" data-user-expand="{{unbound username}}" class='avatar-link'><div class='avatar-wrapper'>{{avatar this imageSize="large" extraClasses="actor" ignoreTitle="true"}}</div></a>
<span class='time'>{{date path="created_at" leaveAgo="true"}}</span> <span class='time'>{{format-date path="created_at" leaveAgo="true"}}</span>
<span class="title"> <span class="title">
<a href="{{unbound postUrl}}">{{unbound title}}</a> <a href="{{unbound postUrl}}">{{unbound title}}</a>
</span> </span>