Revert "Convert html.js to ES6 module format"
This reverts commit 60523d8e02
.
This commit is contained in:
parent
60523d8e02
commit
649dfd8d23
|
@ -1,7 +1,5 @@
|
||||||
import { getCustomHTML } from 'discourse/lib/html';
|
|
||||||
|
|
||||||
Handlebars.registerHelper('custom-html', function(name, contextString, options) {
|
Handlebars.registerHelper('custom-html', function(name, contextString, options) {
|
||||||
var html = getCustomHTML(name);
|
var html = Discourse.HTML.getCustomHTML(name);
|
||||||
if (html) { return html; }
|
if (html) { return html; }
|
||||||
|
|
||||||
var container = (options || contextString).data.view.container;
|
var container = (options || contextString).data.view.container;
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
|
@ -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;
|
|
|
@ -1,13 +1,14 @@
|
||||||
module("Discourse.HTML");
|
module("Discourse.HTML");
|
||||||
|
|
||||||
import { getCustomHTML, setCustomHTML } from 'discourse/lib/html';
|
var html = Discourse.HTML;
|
||||||
|
|
||||||
test("customHTML", function() {
|
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');
|
html.setCustomHTML('evil', 'trout');
|
||||||
equal(getCustomHTML('evil'), 'trout', 'it retrieves the custom html');
|
equal(html.getCustomHTML('evil'), 'trout', 'it retrieves the custom html');
|
||||||
|
|
||||||
PreloadStore.store('customHTML', {cookie: 'monster'});
|
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');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue