From 8b51176f2e7e0596de27b3be8fc1b4bd04bc7dc6 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 18 Dec 2014 11:03:17 -0500 Subject: [PATCH] FIX: Category badges were missing stripes in some places --- .../components/category-group.js.es6 | 23 ++++--------------- .../helpers/bound-category-link.js.es6 | 3 --- .../discourse/helpers/category-badge.js.es6 | 2 +- .../helpers/category-link-raw.js.es6 | 5 ---- .../discourse/helpers/category-link.js.es6 | 19 ++++++++++++++- .../discourse/lib/html-builder.js.es6 | 16 ------------- .../category-group-autocomplete.raw.hbs | 7 ++++++ .../templates/discovery/categories.hbs | 2 +- .../templates/list/category-column.raw.hbs | 2 +- .../mobile/components/basic-topic-list.hbs | 2 +- .../templates/mobile/discovery/categories.hbs | 2 +- .../templates/mobile/list/topic_list_item.hbs | 2 +- .../discourse/templates/site_map.hbs | 2 +- 13 files changed, 37 insertions(+), 50 deletions(-) delete mode 100644 app/assets/javascripts/discourse/helpers/bound-category-link.js.es6 delete mode 100644 app/assets/javascripts/discourse/helpers/category-link-raw.js.es6 delete mode 100644 app/assets/javascripts/discourse/lib/html-builder.js.es6 create mode 100644 app/assets/javascripts/discourse/templates/category-group-autocomplete.raw.hbs diff --git a/app/assets/javascripts/discourse/components/category-group.js.es6 b/app/assets/javascripts/discourse/components/category-group.js.es6 index e6d719afe4d..32434e74a98 100644 --- a/app/assets/javascripts/discourse/components/category-group.js.es6 +++ b/app/assets/javascripts/discourse/components/category-group.js.es6 @@ -1,22 +1,8 @@ -// Compile and memoize a template -var compiled; -function templateFunction() { - compiled = compiled || Handlebars.compile("
" + - "" + - "
"); - return compiled; -} - export default Ember.Component.extend({ - didInsertElement: function(){ + _initializeAutocomplete: function(){ var self = this; + var template = this.container.lookup('template:category-group-autocomplete.raw'); this.$('input').autocomplete({ items: this.get('categories'), @@ -37,10 +23,11 @@ export default Ember.Component.extend({ }); self.set("categories", categories); }, - template: templateFunction(), + template: template, transformComplete: function(category) { return Discourse.HTML.categoryBadge(category, {allowUncategorized: true}); } }); - } + }.on('didInsertElement') + }); diff --git a/app/assets/javascripts/discourse/helpers/bound-category-link.js.es6 b/app/assets/javascripts/discourse/helpers/bound-category-link.js.es6 deleted file mode 100644 index ae8e87da12c..00000000000 --- a/app/assets/javascripts/discourse/helpers/bound-category-link.js.es6 +++ /dev/null @@ -1,3 +0,0 @@ -import { categoryLinkHTML } from 'discourse/lib/html-builder'; - -Ember.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 index 2055a573547..df98421f360 100644 --- a/app/assets/javascripts/discourse/helpers/category-badge.js.es6 +++ b/app/assets/javascripts/discourse/helpers/category-badge.js.es6 @@ -1,4 +1,4 @@ -import { categoryLinkHTML } from 'discourse/lib/html-builder'; +import { categoryLinkHTML } from 'discourse/helpers/category-badge'; import registerUnbound from 'discourse/helpers/register-unbound'; registerUnbound('category-badge', function(cat, 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 deleted file mode 100644 index b8e4df1ee24..00000000000 --- a/app/assets/javascripts/discourse/helpers/category-link-raw.js.es6 +++ /dev/null @@ -1,5 +0,0 @@ -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 index 0ce72e0919b..412a64df99e 100644 --- a/app/assets/javascripts/discourse/helpers/category-link.js.es6 +++ b/app/assets/javascripts/discourse/helpers/category-link.js.es6 @@ -1,4 +1,21 @@ -import { categoryLinkHTML } from 'discourse/lib/html-builder'; import registerUnbound from 'discourse/helpers/register-unbound'; +export function categoryLinkHTML(category, options) { + var categoryOptions = {}; + + // TODO: This is a compatibility layer with the old helper structure. + // Can be removed once we migrate to `registerUnbound` fully + if (options && options.hash) { options = options.hash; } + + if (options) { + if (options.allowUncategorized) { categoryOptions.allowUncategorized = true; } + if (options.showParent) { categoryOptions.showParent = true; } + if (options.onlyStripe) { categoryOptions.onlyStripe = true; } + if (options.link !== undefined) { categoryOptions.link = options.link; } + if (options.extraClasses) { categoryOptions.extraClasses = options.extraClasses; } + } + return new Handlebars.SafeString(Discourse.HTML.categoryBadge(category, categoryOptions)); +} + registerUnbound('category-link', categoryLinkHTML); +Ember.Handlebars.helper('bound-category-link', categoryLinkHTML); diff --git a/app/assets/javascripts/discourse/lib/html-builder.js.es6 b/app/assets/javascripts/discourse/lib/html-builder.js.es6 deleted file mode 100644 index 941a864327c..00000000000 --- a/app/assets/javascripts/discourse/lib/html-builder.js.es6 +++ /dev/null @@ -1,16 +0,0 @@ -export function categoryLinkHTML(category, options) { - var categoryOptions = {}; - - // TODO: This is a compatibility layer with the old helper structure. - // Can be removed once we migrate to `registerUnbound` fully - if (options && options.hash) { options = options.hash; } - - if (options) { - if (options.allowUncategorized) { categoryOptions.allowUncategorized = true; } - if (options.showParent) { categoryOptions.showParent = true; } - if (options.onlyStripe) { categoryOptions.onlyStripe = true; } - if (options.link !== undefined) { categoryOptions.link = options.link; } - if (options.extraClasses) { categoryOptions.extraClasses = options.extraClasses; } - } - return new Handlebars.SafeString(Discourse.HTML.categoryBadge(category, categoryOptions)); -} diff --git a/app/assets/javascripts/discourse/templates/category-group-autocomplete.raw.hbs b/app/assets/javascripts/discourse/templates/category-group-autocomplete.raw.hbs new file mode 100644 index 00000000000..f169dacf370 --- /dev/null +++ b/app/assets/javascripts/discourse/templates/category-group-autocomplete.raw.hbs @@ -0,0 +1,7 @@ +
+ +
diff --git a/app/assets/javascripts/discourse/templates/discovery/categories.hbs b/app/assets/javascripts/discourse/templates/discovery/categories.hbs index 6bcdb1f2cb1..691b4d04738 100644 --- a/app/assets/javascripts/discourse/templates/discovery/categories.hbs +++ b/app/assets/javascripts/discourse/templates/discovery/categories.hbs @@ -32,7 +32,7 @@ {{#if c.subcategories}}
{{#each s in c.subcategories}} - {{category-link s showParent=true onlyStripe=true}} + {{category-link s showParent="true" onlyStripe="true"}} {{#if s.unreadTopics}} {{unbound s.unreadTopics}} {{/if}} diff --git a/app/assets/javascripts/discourse/templates/list/category-column.raw.hbs b/app/assets/javascripts/discourse/templates/list/category-column.raw.hbs index 0527596b02f..c00d24f117b 100644 --- a/app/assets/javascripts/discourse/templates/list/category-column.raw.hbs +++ b/app/assets/javascripts/discourse/templates/list/category-column.raw.hbs @@ -1,3 +1,3 @@ {{#unless hideCategory}} -{{category-link category showParent=true}} +{{category-link category showParent="true"}} {{/unless}} diff --git a/app/assets/javascripts/discourse/templates/mobile/components/basic-topic-list.hbs b/app/assets/javascripts/discourse/templates/mobile/components/basic-topic-list.hbs index 2ba425fd3b2..e6e15e6e843 100644 --- a/app/assets/javascripts/discourse/templates/mobile/components/basic-topic-list.hbs +++ b/app/assets/javascripts/discourse/templates/mobile/components/basic-topic-list.hbs @@ -32,7 +32,7 @@
{{#unless controller.hideCategory}}
- {{category-link t.category showParent=true}} + {{category-link t.category showParent="true"}}
{{/unless}} {{#if controller.showParticipants}} diff --git a/app/assets/javascripts/discourse/templates/mobile/discovery/categories.hbs b/app/assets/javascripts/discourse/templates/mobile/discovery/categories.hbs index 793d36120b4..2256ea394f6 100644 --- a/app/assets/javascripts/discourse/templates/mobile/discovery/categories.hbs +++ b/app/assets/javascripts/discourse/templates/mobile/discovery/categories.hbs @@ -46,7 +46,7 @@
{{#each subcategory in c.subcategories}} - {{category-link subcategory showParent=true}} + {{category-link subcategory showParent="true"}} {{/each}}
diff --git a/app/assets/javascripts/discourse/templates/mobile/list/topic_list_item.hbs b/app/assets/javascripts/discourse/templates/mobile/list/topic_list_item.hbs index df38e557239..69f8c66ab04 100644 --- a/app/assets/javascripts/discourse/templates/mobile/list/topic_list_item.hbs +++ b/app/assets/javascripts/discourse/templates/mobile/list/topic_list_item.hbs @@ -23,7 +23,7 @@
{{#unless controller.hideCategory}}
- {{category-link category showParent=true}} + {{category-link category showParent="true"}}
{{/unless}} diff --git a/app/assets/javascripts/discourse/templates/site_map.hbs b/app/assets/javascripts/discourse/templates/site_map.hbs index c5f8a613db3..97dfcc57b90 100644 --- a/app/assets/javascripts/discourse/templates/site_map.hbs +++ b/app/assets/javascripts/discourse/templates/site_map.hbs @@ -43,7 +43,7 @@ {{#each c in categories itemController='site-map-category'}}
  • - {{category-link c allowUncategorized=true showParent=true}} + {{category-link c allowUncategorized="true" showParent="true"}} {{#if c.unreadTotal}} {{c.unreadTotal}}