premasagar / tim

A tiny, secure JavaScript micro-templating script.
251 stars 26 forks source link

export to nodejs and AMD loaders #8

Closed millermedeiros closed 11 years ago

millermedeiros commented 13 years ago

right now library assumes the browser environment. it's better to create a wrapper that will avoid creating global variables if an AMD loader is detected and also if running on nodejs...

based on the current implementation it's actually easy to create a wrapper that would run on multiple environments:

(function(global){

    // YOUR CODE GOES HERE //

    //exports to multiple environments
    if(typeof define === 'function' && define.amd){ //AMD
        define('tim', [], tim);
    } else if (typeof module !== 'undefined' && module.exports){ //node
        module.exports = tim;
    } else { //browser
        //use string because of Google closure compiler ADVANCED_MODE
        global['tim'] = tim;
    }

}(this));

for a wrapper that would run on other CJS environments besides nodejs check second example of this gist.

premasagar commented 11 years ago

Fixed in 1ca52eced9e72ad879170291e2903ea2d6c4fa9c