mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 12:42:16 +08:00
REFACTOR: Remove Discourse.__widget_helpers
It's now a variable in the context where the templates are created.
This commit is contained in:
parent
792bd3faff
commit
7df57b35da
|
@ -99,3 +99,4 @@
|
|||
//= require_tree ./discourse/app/services
|
||||
|
||||
//= require_tree ./discourse/app/widgets
|
||||
//= require ./widget-runtime
|
||||
|
|
|
@ -89,11 +89,6 @@ export function convertIconClass(icon) {
|
|||
.trim();
|
||||
}
|
||||
|
||||
// TODO: Improve how helpers are registered for vdom compliation
|
||||
if (typeof Discourse !== "undefined") {
|
||||
Discourse.__widget_helpers.iconNode = iconNode;
|
||||
}
|
||||
|
||||
export function registerIconRenderer(renderer) {
|
||||
_renderers.unshift(renderer);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ const _pluginCallbacks = [];
|
|||
|
||||
const Discourse = Application.extend({
|
||||
rootElement: "#main",
|
||||
__widget_helpers: {},
|
||||
|
||||
customEvents: {
|
||||
paste: "paste"
|
||||
|
|
|
@ -17,11 +17,6 @@ export function dateNode(dt) {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: Improve how helpers are registered for vdom compliation
|
||||
if (typeof Discourse !== "undefined") {
|
||||
Discourse.__widget_helpers.dateNode = dateNode;
|
||||
}
|
||||
|
||||
export function numberNode(num, opts) {
|
||||
opts = opts || {};
|
||||
num = parseInt(num, 10);
|
||||
|
|
|
@ -64,11 +64,6 @@ export function avatarFor(wanted, attrs) {
|
|||
);
|
||||
}
|
||||
|
||||
// TODO: Improve how helpers are registered for vdom compliation
|
||||
if (typeof Discourse !== "undefined") {
|
||||
Discourse.__widget_helpers.avatar = avatarFor;
|
||||
}
|
||||
|
||||
createWidget("select-post", {
|
||||
tagName: "div.select-posts",
|
||||
|
||||
|
|
|
@ -22,8 +22,3 @@ export default class RawHtml {
|
|||
}
|
||||
|
||||
RawHtml.prototype.type = "Widget";
|
||||
|
||||
// TODO: Improve how helpers are registered for vdom compliation
|
||||
if (typeof Discourse !== "undefined") {
|
||||
Discourse.__widget_helpers.rawHtml = RawHtml;
|
||||
}
|
||||
|
|
11
app/assets/javascripts/widget-runtime.js
Normal file
11
app/assets/javascripts/widget-runtime.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
// discourse-skip-module
|
||||
|
||||
(function(context) {
|
||||
// register widget helpers for compiled `hbs`
|
||||
context.__widget_helpers = {
|
||||
avatar: require("discourse/widgets/post").avatarFor,
|
||||
dateNode: require("discourse/helpers/node").dateNode,
|
||||
iconNode: require("discourse-common/lib/icon-library").iconNode,
|
||||
rawHtml: require("discourse/widgets/raw-html").default
|
||||
};
|
||||
})(this);
|
|
@ -283,7 +283,7 @@ function compile(template) {
|
|||
|
||||
Object.keys(compiler.state.helpersUsed).forEach(h => {
|
||||
let id = compiler.state.helpersUsed[h];
|
||||
imports += `var __h${id} = Discourse.__widget_helpers.${h}; `;
|
||||
imports += `var __h${id} = __widget_helpers.${h}; `;
|
||||
});
|
||||
|
||||
return `function(attrs, state) { ${imports}var _r = [];\n${code}\nreturn _r; }`;
|
||||
|
|
|
@ -6,6 +6,7 @@ template = <<~HBS
|
|||
{{actions-summary-item attrs=as}}
|
||||
{{attach widget="actions-summary-item" attrs=as}}
|
||||
{{testing value="hello"}}
|
||||
{{date "today"}}
|
||||
HBS
|
||||
|
||||
ctx = MiniRacer::Context.new(timeout: 15000)
|
||||
|
|
Loading…
Reference in New Issue
Block a user