Support for HTML values in widget hbs templates
This commit is contained in:
parent
f6c484881b
commit
0caf6a0f7d
|
@ -99,7 +99,6 @@ export default Ember.Component.extend(AddArchetypeClass, Scrolling, {
|
|||
// this happens after route exit, stuff could have trickled in
|
||||
this.appEvents.trigger('header:hide-topic');
|
||||
this.appEvents.off('post:highlight');
|
||||
|
||||
},
|
||||
|
||||
@observes('Discourse.hasFocus')
|
||||
|
|
|
@ -4,7 +4,7 @@ export default class RawHtml {
|
|||
}
|
||||
|
||||
init() {
|
||||
const $html = $(this.html);
|
||||
const $html = $.parseHTML(this.html);
|
||||
this.decorate($html);
|
||||
return $html[0];
|
||||
}
|
||||
|
@ -20,3 +20,8 @@ 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;
|
||||
}
|
||||
|
|
|
@ -64,7 +64,12 @@ function mustacheValue(node, state) {
|
|||
return `__iN("${icon}")`;
|
||||
break;
|
||||
default:
|
||||
if (node.escaped) {
|
||||
return `${resolve(path)}`;
|
||||
} else {
|
||||
state.helpersUsed.rawHtml = true;
|
||||
return `new __rH({ html: '<span>' + ${resolve(path)} + '</span>'})`;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -180,7 +185,10 @@ function compile(template) {
|
|||
|
||||
let imports = '';
|
||||
if (compiler.state.helpersUsed.iconNode) {
|
||||
imports = "var __iN = Discourse.__widget_helpers.iconNode; ";
|
||||
imports += "var __iN = Discourse.__widget_helpers.iconNode; ";
|
||||
}
|
||||
if (compiler.state.helpersUsed.rawHtml) {
|
||||
imports += "var __rH = Discourse.__widget_helpers.rawHtml; ";
|
||||
}
|
||||
|
||||
return `function(attrs, state) { ${imports}var _r = [];\n${code}\nreturn _r; }`;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
template = <<~HBS
|
||||
{{attach widget="widget-name" attrs=attrs}}
|
||||
{{a}}
|
||||
{{{htmlValue}}}
|
||||
{{#if state.category}}
|
||||
{{attach widget="category-display" attrs=(hash category=state.category)}}
|
||||
{{/if}}
|
||||
|
|
Loading…
Reference in New Issue