mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-28 01:56:01 -05:00
Convert category helpers to ES6.
This commit is contained in:
parent
a3863b52db
commit
8ac955247c
6 changed files with 33 additions and 50 deletions
|
@ -1,55 +1,5 @@
|
|||
var safe = Handlebars.SafeString;
|
||||
|
||||
/**
|
||||
Produces a link to a category given a category object and helper options
|
||||
|
||||
@method categoryLinkHTML
|
||||
@param {Discourse.Category} category to link to
|
||||
@param {Object} options standard from handlebars
|
||||
**/
|
||||
function categoryLinkHTML(category, options) {
|
||||
var categoryOptions = {};
|
||||
if (options.hash) {
|
||||
if (options.hash.allowUncategorized) { categoryOptions.allowUncategorized = true; }
|
||||
if (options.hash.showParent) { categoryOptions.showParent = true; }
|
||||
if (options.hash.onlyStripe) { categoryOptions.onlyStripe = true; }
|
||||
if (options.hash.link !== undefined) { categoryOptions.link = options.hash.link; }
|
||||
if (options.hash.extraClasses) { categoryOptions.extraClasses = options.hash.extraClasses; }
|
||||
if (options.hash.categories) {
|
||||
categoryOptions.categories = Em.Handlebars.get(this, options.hash.categories, options);
|
||||
}
|
||||
}
|
||||
return new safe(Discourse.HTML.categoryBadge(category, categoryOptions));
|
||||
}
|
||||
|
||||
/**
|
||||
Produces a link to a category
|
||||
|
||||
@method category-link
|
||||
@for Handlebars
|
||||
**/
|
||||
Handlebars.registerHelper('category-link', function(property, options) {
|
||||
return categoryLinkHTML(Ember.Handlebars.get(this, property, options), options);
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('category-link-raw', function(property, options) {
|
||||
return categoryLinkHTML(property, options);
|
||||
});
|
||||
|
||||
Handlebars.registerHelper('category-badge', function(property, options) {
|
||||
options.hash.link = false;
|
||||
return categoryLinkHTML(Ember.Handlebars.get(this, property, options), options);
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
Produces a bound link to a category
|
||||
|
||||
@method bound-category-link
|
||||
@for Handlebars
|
||||
**/
|
||||
Em.Handlebars.helper('bound-category-link', categoryLinkHTML);
|
||||
|
||||
/**
|
||||
Produces a link to a route with support for i18n on the title
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
import { categoryLinkHTML } from 'discourse/lib/html-builder';
|
||||
|
||||
Em.Handlebars.helper('bound-category-link', categoryLinkHTML);
|
|
@ -0,0 +1,6 @@
|
|||
import { categoryLinkHTML } from 'discourse/lib/html-builder';
|
||||
|
||||
Handlebars.registerHelper('category-badge', function(property, options) {
|
||||
options.hash.link = false;
|
||||
return categoryLinkHTML(Ember.Handlebars.get(this, property, options), options);
|
||||
});
|
|
@ -0,0 +1,5 @@
|
|||
import { categoryLinkHTML } from 'discourse/lib/html-builder';
|
||||
|
||||
Handlebars.registerHelper('category-link-raw', function(property, options) {
|
||||
return categoryLinkHTML(property, options);
|
||||
});
|
|
@ -0,0 +1,5 @@
|
|||
import { categoryLinkHTML } from 'discourse/lib/html-builder';
|
||||
|
||||
export default Handlebars.registerHelper('category-link', function(property, options) {
|
||||
return categoryLinkHTML(Ember.Handlebars.get(this, property, options), options);
|
||||
});
|
14
app/assets/javascripts/discourse/lib/html-builder.js.es6
Normal file
14
app/assets/javascripts/discourse/lib/html-builder.js.es6
Normal file
|
@ -0,0 +1,14 @@
|
|||
export function categoryLinkHTML(category, options) {
|
||||
var categoryOptions = {};
|
||||
if (options.hash) {
|
||||
if (options.hash.allowUncategorized) { categoryOptions.allowUncategorized = true; }
|
||||
if (options.hash.showParent) { categoryOptions.showParent = true; }
|
||||
if (options.hash.onlyStripe) { categoryOptions.onlyStripe = true; }
|
||||
if (options.hash.link !== undefined) { categoryOptions.link = options.hash.link; }
|
||||
if (options.hash.extraClasses) { categoryOptions.extraClasses = options.hash.extraClasses; }
|
||||
if (options.hash.categories) {
|
||||
categoryOptions.categories = Em.Handlebars.get(this, options.hash.categories, options);
|
||||
}
|
||||
}
|
||||
return new Handlebars.SafeString(Discourse.HTML.categoryBadge(category, categoryOptions));
|
||||
}
|
Loading…
Reference in a new issue