diff --git a/app/assets/javascripts/discourse/helpers/custom-html.js.es6 b/app/assets/javascripts/discourse/helpers/custom-html.js.es6 index 1728963bf..42155096d 100644 --- a/app/assets/javascripts/discourse/helpers/custom-html.js.es6 +++ b/app/assets/javascripts/discourse/helpers/custom-html.js.es6 @@ -1,7 +1,5 @@ -import { getCustomHTML } from 'discourse/lib/html'; - Handlebars.registerHelper('custom-html', function(name, contextString, options) { - var html = getCustomHTML(name); + var html = Discourse.HTML.getCustomHTML(name); if (html) { return html; } var container = (options || contextString).data.view.container; diff --git a/app/assets/javascripts/discourse/lib/html.js b/app/assets/javascripts/discourse/lib/html.js new file mode 100644 index 000000000..ccb807d6a --- /dev/null +++ b/app/assets/javascripts/discourse/lib/html.js @@ -0,0 +1,28 @@ +var customizations = {}; + +Discourse.HTML = { + + /** + Return a custom fragment of HTML by key. It can be registered via a plugin + using `setCustomHTML(key, html)`. This is used by a handlebars helper to find + the HTML content it wants. It will also check the `PreloadStore` for any server + side preloaded HTML. + **/ + getCustomHTML: function(key) { + var c = customizations[key]; + if (c) { + return new Handlebars.SafeString(c); + } + + var html = PreloadStore.get("customHTML"); + if (html && html[key] && html[key].length) { + return new Handlebars.SafeString(html[key]); + } + }, + + // Set a fragment of HTML by key. It can then be looked up with `getCustomHTML(key)`. + setCustomHTML: function(key, html) { + customizations[key] = html; + } + +}; diff --git a/app/assets/javascripts/discourse/lib/html.js.es6 b/app/assets/javascripts/discourse/lib/html.js.es6 deleted file mode 100644 index f839b5ea5..000000000 --- a/app/assets/javascripts/discourse/lib/html.js.es6 +++ /dev/null @@ -1,32 +0,0 @@ -var _customizations = {}; - -/** - Return a custom fragment of HTML by key. It can be registered via a plugin - using `setCustomHTML(key, html)`. This is used by a handlebars helper to find - the HTML content it wants. It will also check the `PreloadStore` for any server - side preloaded HTML. -**/ -export function getCustomHTML(key) { - var c = _customizations[key]; - if (c) { - return new Handlebars.SafeString(c); - } - - var html = PreloadStore.get("customHTML"); - if (html && html[key] && html[key].length) { - return new Handlebars.SafeString(html[key]); - } -} - -// Set a fragment of HTML by key. It can then be looked up with `getCustomHTML(key)`. -export function setCustomHTML(key, html) { - _customizations[key] = html; -} - -var HTML = { - getCustomHTML: getCustomHTML, - setCustomHTML: setCustomHTML -}; - -Discourse.HTML = HTML; -export default HTML; diff --git a/test/javascripts/lib/html-test.js.es6 b/test/javascripts/lib/html-test.js.es6 index 835b3f1e6..07ef2906a 100644 --- a/test/javascripts/lib/html-test.js.es6 +++ b/test/javascripts/lib/html-test.js.es6 @@ -1,13 +1,14 @@ module("Discourse.HTML"); -import { getCustomHTML, setCustomHTML } from 'discourse/lib/html'; +var html = Discourse.HTML; test("customHTML", function() { - blank(getCustomHTML('evil'), "there is no custom HTML for a key by default"); + blank(html.getCustomHTML('evil'), "there is no custom HTML for a key by default"); - setCustomHTML('evil', 'trout'); - equal(getCustomHTML('evil'), 'trout', 'it retrieves the custom html'); + html.setCustomHTML('evil', 'trout'); + equal(html.getCustomHTML('evil'), 'trout', 'it retrieves the custom html'); PreloadStore.store('customHTML', {cookie: 'monster'}); - equal(getCustomHTML('cookie'), 'monster', 'it returns HTML fragments from the PreloadStore'); + equal(html.getCustomHTML('cookie'), 'monster', 'it returns HTML fragments from the PreloadStore'); + });