mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Convert some application helpers to ES6 format.
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export default Handlebars.registerHelper('shorten-text', function(property, options) {
|
||||
return Ember.Handlebars.get(this, property, options).substring(0,35);
|
||||
});
|
||||
12
app/assets/javascripts/discourse/helpers/shorten-url.js.es6
Normal file
12
app/assets/javascripts/discourse/helpers/shorten-url.js.es6
Normal 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);
|
||||
});
|
||||
|
||||
@@ -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>");
|
||||
});
|
||||
@@ -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>
|
||||
|
||||
@@ -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}}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user