Support for HTML values in widget hbs templates

This commit is contained in:
Robin Ward 2017-09-29 09:55:53 -04:00
parent f6c484881b
commit 0caf6a0f7d
4 changed files with 18 additions and 4 deletions

View File

@ -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')

View File

@ -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;
}

View File

@ -64,7 +64,12 @@ function mustacheValue(node, state) {
return `__iN("${icon}")`;
break;
default:
return `${resolve(path)}`;
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; }`;

View File

@ -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}}