diff --git a/app/assets/javascripts/discourse/helpers/application_helpers.js b/app/assets/javascripts/discourse/helpers/application_helpers.js index 7cefe3e63..f34ab5cb2 100644 --- a/app/assets/javascripts/discourse/helpers/application_helpers.js +++ b/app/assets/javascripts/discourse/helpers/application_helpers.js @@ -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 diff --git a/app/assets/javascripts/discourse/helpers/bound-category-link.js.es6 b/app/assets/javascripts/discourse/helpers/bound-category-link.js.es6 new file mode 100644 index 000000000..abcf0f140 --- /dev/null +++ b/app/assets/javascripts/discourse/helpers/bound-category-link.js.es6 @@ -0,0 +1,3 @@ +import { categoryLinkHTML } from 'discourse/lib/html-builder'; + +Em.Handlebars.helper('bound-category-link', categoryLinkHTML); diff --git a/app/assets/javascripts/discourse/helpers/category-badge.js.es6 b/app/assets/javascripts/discourse/helpers/category-badge.js.es6 new file mode 100644 index 000000000..d7c7a12db --- /dev/null +++ b/app/assets/javascripts/discourse/helpers/category-badge.js.es6 @@ -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); +}); diff --git a/app/assets/javascripts/discourse/helpers/category-link-raw.js.es6 b/app/assets/javascripts/discourse/helpers/category-link-raw.js.es6 new file mode 100644 index 000000000..b8e4df1ee --- /dev/null +++ b/app/assets/javascripts/discourse/helpers/category-link-raw.js.es6 @@ -0,0 +1,5 @@ +import { categoryLinkHTML } from 'discourse/lib/html-builder'; + +Handlebars.registerHelper('category-link-raw', function(property, options) { + return categoryLinkHTML(property, options); +}); diff --git a/app/assets/javascripts/discourse/helpers/category-link.js.es6 b/app/assets/javascripts/discourse/helpers/category-link.js.es6 new file mode 100644 index 000000000..7a7c73a2d --- /dev/null +++ b/app/assets/javascripts/discourse/helpers/category-link.js.es6 @@ -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); +}); diff --git a/app/assets/javascripts/discourse/lib/html-builder.js.es6 b/app/assets/javascripts/discourse/lib/html-builder.js.es6 new file mode 100644 index 000000000..7e11356c1 --- /dev/null +++ b/app/assets/javascripts/discourse/lib/html-builder.js.es6 @@ -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)); +}