Convert some application helpers to ES6 format.

This commit is contained in:
Robin Ward
2014-09-03 13:30:22 -04:00
parent 0b6c84e292
commit e9600d7cb1
10 changed files with 28 additions and 50 deletions

View File

@@ -68,9 +68,9 @@
<td>{{#link-to 'adminUser' this}}{{avatar this imageSize="small"}}{{/link-to}}</td>
<td>{{#link-to 'adminUser' this}}{{unbound username}}{{/link-to}}</td>
{{#if active}}
<td>{{shorten email}}</td>
<td>{{shorten-text email}}</td>
{{else}}
<td title="{{i18n admin.users.not_verified}}">{{shorten email}}</td>
<td title="{{i18n admin.users.not_verified}}">{{shorten-text email}}</td>
{{/if}}
<td>{{{unbound last_emailed_age}}}</td>
<td>{{{unbound last_seen_age}}}</td>

View File

@@ -1,28 +1,5 @@
var safe = Handlebars.SafeString;
/**
Truncates long strings
@method shorten
@for Handlebars
**/
Handlebars.registerHelper('shorten', function(property, options) {
return Ember.Handlebars.get(this, property, options).substring(0,35);
});
/**
Produces a link to a topic
@method topic-link
@for Handlebars
**/
Handlebars.registerHelper('topic-link', function(property, options) {
var topic = Ember.Handlebars.get(this, property, options),
title = topic.get('fancy_title');
return "<a href='" + topic.get('lastUnreadUrl') + "' class='title'>" + title + "</a>";
});
/**
Produces a link to a category given a category object and helper options
@@ -91,25 +68,6 @@ Handlebars.registerHelper('titled-link-to', function(name, object) {
}
});
/**
Shorten a URL for display by removing common components
@method shortenUrl
@for Handlebars
**/
Handlebars.registerHelper('shorten-url', function(property, options) {
var url, matches;
url = Ember.Handlebars.get(this, property, options);
// Remove trailing slash if it's a top level URL
matches = url.match(/\//g);
if (matches && matches.length === 3) {
url = url.replace(/\/$/, '');
}
url = url.replace(/^https?:\/\//, '');
url = url.replace(/^www\./, '');
return url.substring(0,80);
});
/**
Bound avatar helper.

View File

@@ -0,0 +1,3 @@
export default Handlebars.registerHelper('shorten-text', function(property, options) {
return Ember.Handlebars.get(this, property, options).substring(0,35);
});

View File

@@ -0,0 +1,12 @@
export default Handlebars.registerHelper('shorten-url', function(property, options) {
var url = Ember.Handlebars.get(this, property, options),
matches = url.match(/\//g);
if (matches && matches.length === 3) {
url = url.replace(/\/$/, '');
}
url = url.replace(/^https?:\/\//, '');
url = url.replace(/^www\./, '');
return url.substring(0, 80);
});

View File

@@ -0,0 +1,6 @@
export default Handlebars.registerHelper('topic-link', function(property, options) {
var topic = Ember.Handlebars.get(this, property, options),
title = topic.get('fancy_title');
return new Handlebars.SafeString("<a href='" + topic.get('lastUnreadUrl') + "' class='title'>" + title + "</a>");
});

View File

@@ -3,6 +3,6 @@
<ul class='topics'>
{{#each similarTopics}}
<li>{{{topic-link this}}} <span class='posts-count'>({{{i18n topic.filters.n_posts count="posts_count"}}})</span></li>
<li>{{topic-link this}} <span class='posts-count'>({{{i18n topic.filters.n_posts count="posts_count"}}})</span></li>
{{/each}}
</ul>

View File

@@ -12,7 +12,7 @@
<td class='main-link clearfix' {{bind-attr colspan="titleColSpan"}}>
{{topic-status topic=this.model}}
{{{topic-link this}}}
{{topic-link this}}
{{topic-post-badges unread=unread newPosts=displayNewPosts unseen=unseen url=lastUnreadUrl}}
{{#if hasExcerpt}}

View File

@@ -6,8 +6,7 @@
<td>
<div class='main-link clearfix'>
{{topic-status topic=this}}
{{{topic-link this}}}
{{topic-link this}}
{{topic-post-badges unread=unread
newPosts=topic.new_posts
unseen=topic.unseen

View File

@@ -20,7 +20,7 @@
<td class='main-link'>
<div class='topic-inset'>
{{topic-status topic=this}}
{{{topic-link this}}}
{{topic-link this}}
{{topic-post-badges unread=unread newPosts=new_posts unseen=unseen url=lastUnreadUrl}}
{{#if hasExcerpt}}

View File

@@ -1,7 +1,7 @@
<td>
<div class='main-link clearfix'>
{{topic-status topic=this}}
{{{topic-link this}}}
{{topic-link this}}
{{topic-post-badges unread=unread
newPosts=displayNewPosts
unseen=unseen