Skip to content

Instantly share code, notes, and snippets.

@realistschuckle
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save realistschuckle/9165608 to your computer and use it in GitHub Desktop.

Select an option

Save realistschuckle/9165608 to your computer and use it in GitHub Desktop.

Revisions

  1. Curtis Schlak revised this gist Feb 23, 2014. 1 changed file with 38 additions and 38 deletions.
    76 changes: 38 additions & 38 deletions jade.server.js
    Original file line number Diff line number Diff line change
    @@ -1,41 +1,41 @@
    /*jslint anon:true, sloppy:true, nomen:true, white:true*/
    YUI.add('addons-viewengine-jade', function(Y, NAME) {
    var jade = require('jade')
    , fs = require('fs')
    , cache = YUI.namespace('Env.Mojito.Jade')
    ;
    function JadeAdapter(config) {
    this.config = config || {};
    }
    var jade = require('jade')
    , fs = require('fs')
    , cache = YUI.namespace('Env.Mojito.Jade')
    ;
    function JadeAdapter(config) {
    this.config = config || {};
    }

    JadeAdapter.prototype = {
    render: function(data, mojitType, tmpl, adapter, meta, more) {
    var engine = this
    , tmplpath = tmpl['content-path']
    ;
    this.compile(tmplpath, function(e, compiled) {
    if(more) {
    adapter.flush(compiled(data), meta);
    } else {
    adapter.done(compiled(data), meta);
    }
    });
    }
    , compile: function(tmplpath, callback) {
    var cacheTemplates = (this.config.cacheTemplates === false)? false : true
    ;
    if(!cacheTemplates || !cache[tmplpath]) {
    fs.readFile(tmplpath, 'utf8', function(e, data) {
    var jade = require('jade')
    , compiled = jade.compile(data, {filename: tmplpath})
    ;
    cache[tmplpath] = compiled;
    callback(e, compiled);
    });
    } else {
    callback(null, cache[tmplpath]);
    }
    }
    };
    Y.namespace('mojito.addons.viewEngines').jade = JadeAdapter;
    }, "0.1.0");
    JadeAdapter.prototype = {
    render: function(data, mojitType, tmpl, adapter, meta, more) {
    var engine = this
    , tmplpath = tmpl['content-path']
    ;
    this.compile(tmplpath, function(e, compiled) {
    if(more) {
    adapter.flush(compiled(data), meta);
    } else {
    adapter.done(compiled(data), meta);
    }
    });
    }
    , compile: function(tmplpath, callback) {
    var cacheTemplates = (this.config.cacheTemplates === false)? false : true
    ;
    if(!cacheTemplates || !cache[tmplpath]) {
    fs.readFile(tmplpath, 'utf8', function(e, data) {
    var jade = require('jade')
    , compiled = jade.compile(data, {filename: tmplpath})
    ;
    cache[tmplpath] = compiled;
    callback(e, compiled);
    });
    } else {
    callback(null, cache[tmplpath]);
    }
    }
    };
    Y.namespace('mojito.addons.viewEngines').jade = JadeAdapter;
    }, "0.0.1");
  2. Curtis Schlak created this gist Feb 23, 2014.
    41 changes: 41 additions & 0 deletions jade.server.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    /*jslint anon:true, sloppy:true, nomen:true, white:true*/
    YUI.add('addons-viewengine-jade', function(Y, NAME) {
    var jade = require('jade')
    , fs = require('fs')
    , cache = YUI.namespace('Env.Mojito.Jade')
    ;
    function JadeAdapter(config) {
    this.config = config || {};
    }

    JadeAdapter.prototype = {
    render: function(data, mojitType, tmpl, adapter, meta, more) {
    var engine = this
    , tmplpath = tmpl['content-path']
    ;
    this.compile(tmplpath, function(e, compiled) {
    if(more) {
    adapter.flush(compiled(data), meta);
    } else {
    adapter.done(compiled(data), meta);
    }
    });
    }
    , compile: function(tmplpath, callback) {
    var cacheTemplates = (this.config.cacheTemplates === false)? false : true
    ;
    if(!cacheTemplates || !cache[tmplpath]) {
    fs.readFile(tmplpath, 'utf8', function(e, data) {
    var jade = require('jade')
    , compiled = jade.compile(data, {filename: tmplpath})
    ;
    cache[tmplpath] = compiled;
    callback(e, compiled);
    });
    } else {
    callback(null, cache[tmplpath]);
    }
    }
    };
    Y.namespace('mojito.addons.viewEngines').jade = JadeAdapter;
    }, "0.1.0");