Ability to decorate after post cooked, and rawHtml helper

This commit is contained in:
Robin Ward 2016-02-23 12:10:04 -05:00
parent f2db1a27cf
commit ef079004da
4 changed files with 9 additions and 4 deletions

View File

@ -23,7 +23,6 @@ class PluginApi {
constructor(version, container) { constructor(version, container) {
this.version = version; this.version = version;
this.container = container; this.container = container;
this._currentUser = container.lookup('current-user:main'); this._currentUser = container.lookup('current-user:main');
} }

View File

@ -1,6 +1,7 @@
import Connector from 'discourse/widgets/connector'; import Connector from 'discourse/widgets/connector';
import { h } from 'virtual-dom'; import { h } from 'virtual-dom';
import PostCooked from 'discourse/widgets/post-cooked'; import PostCooked from 'discourse/widgets/post-cooked';
import RawHtml from 'discourse/widgets/raw-html';
class DecoratorHelper { class DecoratorHelper {
constructor(widget, attrs, state) { constructor(widget, attrs, state) {
@ -17,6 +18,10 @@ class DecoratorHelper {
return this.widget.findAncestorModel(); return this.widget.findAncestorModel();
} }
rawHtml(html) {
return new RawHtml({ html });
}
cooked(cooked) { cooked(cooked) {
return new PostCooked({ cooked }); return new PostCooked({ cooked });
} }

View File

@ -1,5 +1,5 @@
import PostCooked from 'discourse/widgets/post-cooked'; import PostCooked from 'discourse/widgets/post-cooked';
import { createWidget } from 'discourse/widgets/widget'; import { createWidget, applyDecorators } from 'discourse/widgets/widget';
import { iconNode } from 'discourse/helpers/fa-icon'; import { iconNode } from 'discourse/helpers/fa-icon';
import { transformBasicPost } from 'discourse/lib/transform-post'; import { transformBasicPost } from 'discourse/lib/transform-post';
import { h } from 'virtual-dom'; import { h } from 'virtual-dom';
@ -251,7 +251,8 @@ createWidget('post-contents', {
}, },
html(attrs, state) { html(attrs, state) {
const result = [new PostCooked(attrs, new DecoratorHelper(this))]; let result = [new PostCooked(attrs, new DecoratorHelper(this))];
result = result.concat(applyDecorators(this, 'after-cooked', attrs, state));
if (attrs.cooked_hidden) { if (attrs.cooked_hidden) {
result.push(this.attach('expand-hidden', attrs)); result.push(this.attach('expand-hidden', attrs));

View File

@ -22,7 +22,7 @@ export function decorateWidget(widgetName, cb) {
_decorators[widgetName].push(cb); _decorators[widgetName].push(cb);
} }
function applyDecorators(widget, type, attrs, state) { export function applyDecorators(widget, type, attrs, state) {
const decorators = _decorators[`${widget.name}:${type}`] || []; const decorators = _decorators[`${widget.name}:${type}`] || [];
if (decorators.length) { if (decorators.length) {