FEATURE: allow plugins to transform, the transformed post

This allows plugins to amend posts prior to rendering.
This commit is contained in:
Sam
2017-03-07 17:12:31 -05:00
parent 8d80a5d97e
commit 0c03ccb01e
2 changed files with 37 additions and 1 deletions

View File

@ -17,9 +17,10 @@ import { addDiscoveryQueryParam } from 'discourse/controllers/discovery-sortable
import { addTagsHtmlCallback } from 'discourse/lib/render-tags';
import { addUserMenuGlyph } from 'discourse/widgets/user-menu';
import { addPostClassesCallback } from 'discourse/widgets/post';
import { addPostTransformCallback } from 'discourse/widgets/post-stream';
// If you add any methods to the API ensure you bump up this number
const PLUGIN_API_VERSION = '0.8.4';
const PLUGIN_API_VERSION = '0.8.5';
class PluginApi {
constructor(version, container) {
@ -438,6 +439,24 @@ class PluginApi {
addPostClassesCallback(callback) {
addPostClassesCallback(callback);
}
/**
*
* Adds a callback to be executed on the "transformed" post that is passed to the post
* widget.
*
* This allows you to apply transformations on the actual post that is about to be rendered.
*
* Example:
*
* addPostTransformCallback((t)=>{
* // post number 7 is overrated, don't show it ever
* if (t.post_number === 7) { t.cooked = ""; }
* })
*/
addPostTransformCallback(callback) {
addPostTransformCallback(callback);
}
}
let _pluginv01;