Last active
August 29, 2015 13:55
-
-
Save totherik/8699430 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'), | |
engine = require('view-engine'); | |
var renderer, app; | |
renderer = engine.create('dust', require('dustjs-linkedin')); | |
app = express(); | |
app.set('view-engine', renderer); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function middleware(req, res) { | |
var engine, context; | |
engine = req.app.get('view-engine'); | |
context = engine.createContext(res); | |
context.add({ name: 'Frank' }); | |
engine.render('my-template', context).pipe(res); | |
// possibly redundant. use `render` for both streaming and non-streaming? | |
// engine.stream('./my-templates', context).pipe(res); | |
// engine.json(context).pipe(res); | |
// engine.jsonp(context).pipe(res); | |
// engine.binary('').pipe(res); | |
// engine.send('').pipe(res); // auto-negotiate mime-type | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
exports.create = function (ext, renderer) { | |
return { | |
createContext: function (base) { | |
// special-case express for app & res locals? | |
var context = base || {}; | |
return { | |
add: function (data) { | |
util.merge(context, data); | |
return this; | |
} | |
}; | |
}, | |
render: function (name, context) { | |
// create renderer stream wrapper | |
return renderer.stream(name, context); | |
}, | |
json: function (context) { | |
return { | |
pipe: function () { | |
} | |
} | |
}, | |
jsonp: function (context) { | |
}, | |
binary: function (buffer) { | |
}, | |
send: function (obj) { | |
} | |
}; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment