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) {
this.version = version;
this.container = container;
this._currentUser = container.lookup('current-user:main');
}

View file

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

View file

@ -1,5 +1,5 @@
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 { transformBasicPost } from 'discourse/lib/transform-post';
import { h } from 'virtual-dom';
@ -251,7 +251,8 @@ createWidget('post-contents', {
},
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) {
result.push(this.attach('expand-hidden', attrs));

View file

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