From 62c9e4228d0456eea0b4b42098b0e97da26b9c5e Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 9 Sep 2014 17:29:05 -0400 Subject: [PATCH] Rename `{{icon}}` helper to `{{fa-icon}}` for future Ember compatibility. --- .../admin/templates/flags.js.handlebars | 2 +- .../discourse/helpers/application_helpers.js | 19 ------------------- .../discourse/helpers/category-link.js.es6 | 2 +- .../discourse/helpers/fa-icon.js.es6 | 12 ++++++++++++ .../discourse/helpers/shorten-text.js.es6 | 2 +- .../discourse/helpers/shorten-url.js.es6 | 3 +-- .../discourse/helpers/topic-link.js.es6 | 2 +- .../initializers/deprecations.js.es6 | 13 +++++++++++++ .../discourse/templates/header.js.handlebars | 14 +++++++------- .../discourse/templates/topic.js.handlebars | 2 +- 10 files changed, 38 insertions(+), 33 deletions(-) create mode 100644 app/assets/javascripts/discourse/helpers/fa-icon.js.es6 diff --git a/app/assets/javascripts/admin/templates/flags.js.handlebars b/app/assets/javascripts/admin/templates/flags.js.handlebars index 77e830f40..fdd1b627a 100644 --- a/app/assets/javascripts/admin/templates/flags.js.handlebars +++ b/app/assets/javascripts/admin/templates/flags.js.handlebars @@ -42,7 +42,7 @@

{{#if flaggedPost.topic.isPrivateMessage}} - {{icon envelope}} + {{fa-icon envelope}} {{/if}} {{topic-status topic=flaggedPost.topic}} {{flaggedPost.topic.title}} diff --git a/app/assets/javascripts/discourse/helpers/application_helpers.js b/app/assets/javascripts/discourse/helpers/application_helpers.js index f34ab5cb2..4de1ceea7 100644 --- a/app/assets/javascripts/discourse/helpers/application_helpers.js +++ b/app/assets/javascripts/discourse/helpers/application_helpers.js @@ -199,22 +199,3 @@ Handlebars.registerHelper('link-domain', function(property, options) { } } }); - -/** - Renders a font-awesome icon with an optional i18n string as hidden text for - screen readers. - - @method icon - @for Handlebars -**/ -Handlebars.registerHelper('icon', function(icon, options) { - var labelKey, html; - if (options.hash) { labelKey = options.hash.label; } - html = ""; - } - return new safe(html); -}); diff --git a/app/assets/javascripts/discourse/helpers/category-link.js.es6 b/app/assets/javascripts/discourse/helpers/category-link.js.es6 index 7a7c73a2d..f206a4a98 100644 --- a/app/assets/javascripts/discourse/helpers/category-link.js.es6 +++ b/app/assets/javascripts/discourse/helpers/category-link.js.es6 @@ -1,5 +1,5 @@ import { categoryLinkHTML } from 'discourse/lib/html-builder'; -export default Handlebars.registerHelper('category-link', function(property, options) { +Handlebars.registerHelper('category-link', function(property, options) { return categoryLinkHTML(Ember.Handlebars.get(this, property, options), options); }); diff --git a/app/assets/javascripts/discourse/helpers/fa-icon.js.es6 b/app/assets/javascripts/discourse/helpers/fa-icon.js.es6 new file mode 100644 index 000000000..25ac7aebc --- /dev/null +++ b/app/assets/javascripts/discourse/helpers/fa-icon.js.es6 @@ -0,0 +1,12 @@ +Handlebars.registerHelper('fa-icon', function(icon, options) { + var labelKey; + if (options.hash) { labelKey = options.hash.label; } + + var html = ""; + } + return new Handlebars.SafeString(html); +}); diff --git a/app/assets/javascripts/discourse/helpers/shorten-text.js.es6 b/app/assets/javascripts/discourse/helpers/shorten-text.js.es6 index cfa0f8d96..fb1c18be7 100644 --- a/app/assets/javascripts/discourse/helpers/shorten-text.js.es6 +++ b/app/assets/javascripts/discourse/helpers/shorten-text.js.es6 @@ -1,3 +1,3 @@ -export default Handlebars.registerHelper('shorten-text', function(property, options) { +Handlebars.registerHelper('shorten-text', function(property, options) { return Ember.Handlebars.get(this, property, options).substring(0,35); }); diff --git a/app/assets/javascripts/discourse/helpers/shorten-url.js.es6 b/app/assets/javascripts/discourse/helpers/shorten-url.js.es6 index 77744acbb..9548f47c4 100644 --- a/app/assets/javascripts/discourse/helpers/shorten-url.js.es6 +++ b/app/assets/javascripts/discourse/helpers/shorten-url.js.es6 @@ -1,4 +1,4 @@ -export default Handlebars.registerHelper('shorten-url', function(property, options) { +Handlebars.registerHelper('shorten-url', function(property, options) { var url = Ember.Handlebars.get(this, property, options), matches = url.match(/\//g); @@ -9,4 +9,3 @@ export default Handlebars.registerHelper('shorten-url', function(property, optio url = url.replace(/^www\./, ''); return url.substring(0, 80); }); - diff --git a/app/assets/javascripts/discourse/helpers/topic-link.js.es6 b/app/assets/javascripts/discourse/helpers/topic-link.js.es6 index f4264647c..fcbeaeb35 100644 --- a/app/assets/javascripts/discourse/helpers/topic-link.js.es6 +++ b/app/assets/javascripts/discourse/helpers/topic-link.js.es6 @@ -1,4 +1,4 @@ -export default Handlebars.registerHelper('topic-link', function(property, options) { +Handlebars.registerHelper('topic-link', function(property, options) { var topic = Ember.Handlebars.get(this, property, options), title = topic.get('fancy_title'); diff --git a/app/assets/javascripts/discourse/initializers/deprecations.js.es6 b/app/assets/javascripts/discourse/initializers/deprecations.js.es6 index 4227e2f62..e13f63c92 100644 --- a/app/assets/javascripts/discourse/initializers/deprecations.js.es6 +++ b/app/assets/javascripts/discourse/initializers/deprecations.js.es6 @@ -9,6 +9,10 @@ var deprecatedViewHelpers = { 'discourse-activity-filter': 'activity-filter' }; +var renamedHelpers = { + icon: "fa-icon" +}; + export default { name: 'deprecations', initialize: function(container) { @@ -24,5 +28,14 @@ export default { return Ember.Handlebars.helpers.view.call(this, helper, options); }); }); + + Ember.keys(renamedHelpers).forEach(function(old) { + var newName = renamedHelpers[old]; + Ember.Handlebars.registerHelper(old, function() { + Em.warn("The `" + old +"` helper is deprecated. Use `" + newName + "` instead."); + var newHelper = container.lookupFactory('helper:' + newName); + return newHelper.apply(this, Array.prototype.slice.call(arguments)); + }); + }); } }; diff --git a/app/assets/javascripts/discourse/templates/header.js.handlebars b/app/assets/javascripts/discourse/templates/header.js.handlebars index 179869774..71e4ad357 100644 --- a/app/assets/javascripts/discourse/templates/header.js.handlebars +++ b/app/assets/javascripts/discourse/templates/header.js.handlebars @@ -11,7 +11,7 @@ {{/if}}

{{#if showPrivateMessageGlyph}} - {{icon envelope}} + {{fa-icon envelope}} {{/if}} {{#if topic.category.parentCategory}} {{bound-category-link topic.category.parentCategory}} @@ -40,14 +40,14 @@ {{/if}} {{/unless}}