underscorePez
underscorePez

Reputation: 897

Using Dust in require.js

Sorry for posting another "how do you use * with require.js" question, but I can't seem to get dust.js working in my require project. I've googled around and other people are definitely getting dust to work with require. My configuration is fairly standard, but I can't find anyone having the same problems as I'm seeing.

I'm using the version of dust 0.3.0 from here: https://github.com/akdubya/dustjs/blob/master/dist/dust-core-0.3.0.js

here is my config:

requirejs.config({
//exceptions:
paths: {
    'jquery' : 'lib/require-jquery.1.9.1',
    'jquery.mockjax' : 'lib/jquery.mockjax.1.5.1',
    'dust' : 'lib/dust.0.3.0'

},
//Shims are required for jQuery plugins.
shim: {
     'jquery.mockjax': {
     deps: ['jquery'],
     exports: 'jQuery.fn.mockjax'
     },
     'dust': {
     exports: 'dust'
     }
}

});

this is how I include dust in my module:

define( function( require ) {
   var _d = require('dust')
   , _template1 = require('text!template/basicmodal.html');


   function render(key,callback){

            var compiled = _d.compile("Hello {name}!", key);
            _d.loadSource(compiled);
            _d.render(key, {name: "Fred"}, callback);

   }

   return {
   render : render,

If I set a breakpoint within the render function I can see that _d does contain the dust object, but for some reason it doesn't have all its methods. In particular its 'compile' method is missing which causes my code to fail.

Does anyone with a better understanding of dust know what I might be missing here?

Upvotes: 3

Views: 2126

Answers (3)

marcopolo
marcopolo

Reputation: 2042

You can precompile the template and have it wrapped in a define call using this npm module:

https://npmjs.org/package/grunt-dust-require

Upvotes: 0

Kalip
Kalip

Reputation: 106

Dust is now supported by Linkedin. If you want to compile some dust template, maybe this might help you https://github.com/linkedin/dustjs/wiki/Dust-Tutorial#compiling-a-dust-template.

I am not an expert in JS but it could be useful to use Backbone in addition to dust + require. Chek out this (I don't have enough reputation to put more links) : http://weatherlabs.com/2012/10/12/backbone-underscore-and-dust/

Upvotes: 0

Ian Lim
Ian Lim

Reputation: 4284

Please see if using https://github.com/akdubya/dustjs/blob/master/dist/dust-full-0.3.0.js instead helps you.

Upvotes: 1

Related Questions