mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
Ability to decorate after post cooked, and rawHtml helper
This commit is contained in:
parent
f2db1a27cf
commit
ef079004da
4 changed files with 9 additions and 4 deletions
|
@ -23,7 +23,6 @@ class PluginApi {
|
|||
constructor(version, container) {
|
||||
this.version = version;
|
||||
this.container = container;
|
||||
|
||||
this._currentUser = container.lookup('current-user:main');
|
||||
}
|
||||
|
||||
|
|
|
@ -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 });
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue