dbashford / mimosa

A lightning-fast, modular, next generation browser development tool.
http://mimosa.io/
519 stars 34 forks source link

Where is the proper location to place dust-js helpers? #417

Closed ghost closed 9 years ago

ghost commented 9 years ago

Hi,

Where would I put a custom dust-js helper, such as:

dust.helpers.iterate = function(chunk, context, bodies, params) {
        var obj = params['for'] || context.current();

        for (var k in obj) {
            chunk = chunk.render(bodies.block, context.push({key: k, value: obj[k]}));
        }
        return chunk;
    };

I also tried adding a require('dustjs-helpers') to my express server.coffee but that didn't seem to have any effect.

dbashford commented 9 years ago

Guessing you are running dust on the server rather than in the client?

ghost commented 9 years ago

Yes, only using server side templates.

dbashford commented 9 years ago

I am guessing, because I can't test this right now, that the problem is that you are requiring in the helpers before anything requires in dust. If you try this...

require('dustjs-linkedin');
require('dustjs-helpers');

...does that work?

Keep in mind that Mimosa is primarily a browser development tool. I've made it so that mimosa new delivers to you a basic server for Express, but all Mimosa does is call startServer and allow for some basic configuration to help get things started a bit faster. Once you start diverging from that basic setup, you sort of stop being really all that involved with Mimosa and really start taking ownership of the server code... which is a good thing!

ghost commented 9 years ago

Thanks for the reply! I just had to npm install dustjs-helpers. Using the "require" lines actually stops the helpers for loading for some reason.

dbashford commented 9 years ago

All set then? This closeable?

ghost commented 9 years ago

Yes, thank you David.