Cooking text in plugin .es6.js / .hbs?


(Chris Beach) #1

I’d like my plugin to render some marked-up text that the admin is able to customise:

Here’s what I’ve tried so far:

assets/javascripts/controllers/advertise.js.es6:

import { default as PrettyText } from 'pretty-text/pretty-text';

export default Ember.Controller.extend({
    init() {
        this._super();

        this.set('cooked_spiel', new Handlebars.SafeString(new PrettyText().cook(I18n.t('discourse_stripe.advertise_spiel'))));
    }
});

assets/javascripts/discourse/templates/advertise.hbs:

<h1 class="advertise">Advertise</h1>

<p>{{cooked_spiel}}</p>

{{checkout-button}}

<p><a href="/">{{i18n 'topic.timeline.back'}}</a></p>

When I visit the page I get an error:

discourse/routes/application:74 Error: Could not find module pretty-text/engines/discourse-markdown/helpers

Full Error
discourse/routes/application:74 Error: Could not find module pretty-text/engines/discourse-markdown/helpers
    at missingModule (discourse-loader:134)
    at require (discourse-loader:149)
    at setup (pretty-text/engines/discourse-markdown-it:242)
    at buildOptions (pretty-text/pretty-text:110)
    at new _default (pretty-text/pretty-text:120)
    at Class.init (javascripts/discourse/controllers/advertise:11)
    at Class.superWrapper [as init] (ember:42834)
    at new Class (ember:38507)
    at Function._ClassMixinProps.create (ember:38704)
    at FactoryManager.create (ember:3766)
error @ discourse/routes/application:74
ember:30889 Error while processing route: advertise Could not find module pretty-text/engines/discourse-markdown/helpers Error: Could not find module pretty-text/engines/discourse-markdown/helpers
    at missingModule (discourse-loader:134:11)
    at require (discourse-loader:149:17)
    at setup (pretty-text/engines/discourse-markdown-it:242:26)
    at buildOptions (pretty-text/pretty-text:110:36)
    at new _default (pretty-text/pretty-text:120:16)
    at Class.init (javascripts/discourse/controllers/advertise:11:64)
    at Class.superWrapper [as init] (ember:42834:22)
    at new Class (ember:38507:19)
    at Function._ClassMixinProps.create (ember:38704:12)
    at FactoryManager.create (ember:3766:25)
logError @ ember:30889
ember:19818 Error: Could not find module pretty-text/engines/discourse-markdown/helpers
    at missingModule (discourse-loader:134)
    at require (discourse-loader:149)
    at setup (pretty-text/engines/discourse-markdown-it:242)
    at buildOptions (pretty-text/pretty-text:110)
    at new _default (pretty-text/pretty-text:120)
    at Class.init (javascripts/discourse/controllers/advertise:11)
    at Class.superWrapper [as init] (ember:42834)
    at new Class (ember:38507)
    at Function._ClassMixinProps.create (ember:38704)
    at FactoryManager.create (ember:3766)
defaultDispatch @ ember:19818

Would appreciate a nudge in the right direction please!


(Sam Saffron) #2

Yeah you are going to have to use the cook-text component:

It takes care of loading pretty-text bundle and cooking in a deferred way.

We do not ship the bundle down until it is needed.