Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add dustjs template rendering sample

  • Loading branch information...
commit e305761aa8e8bb4643a6263e13180e17e13dadc0 1 parent a13a0cf
@blai authored
View
6 Gruntfile.js
@@ -40,8 +40,12 @@ module.exports = function(grunt) {
tasks: ['livereload']
},
trigger: {
- files: '.server', // touch this file to restart the express server, just an example
+ files: '.server',
tasks: 'express-restart:livereload'
+ },
+ express: {
+ files: 'app/templates/hello.dust',
+ tasks: 'livereload'
}
},
View
10 app/server.js
@@ -5,6 +5,12 @@ var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);
+var consolidate = require('consolidate');
+
+app.engine('dust', consolidate.dust);
+app.set('view engine', 'dust');
+app.set('views', './app/templates');
+
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
@@ -16,8 +22,8 @@ io.sockets.on('connection', function (socket) {
app.use(require('grunt-contrib-livereload/lib/utils').livereloadSnippet);
app.get('/hello', function(req, res){
- // res.send('hello!');
- res.send('bonjour!');
+ res.render('hello', {greeting: 'hello'});
+ // res.render('hello', {greeting: 'bonjour'});
});
exports = module.exports = server;
View
15 app/templates/hello.dust
@@ -0,0 +1,15 @@
+<html>
+<head>
+ <script src="/socket.io/socket.io.js"></script>
+ <script>
+ var socket = io.connect('http://localhost:9000');
+ socket.on('news', function (data) {
+ console.log(data);
+ socket.emit('my other event', { my: 'data' });
+ });
+ </script>
+</head>
+<body>
+ {greeting}!!!!
+</body>
+</html>
View
4 package.json
@@ -42,6 +42,8 @@
"dependencies": {
"express": "~3.1.0",
"socket.io": "~0.9.13",
- "grunt-contrib-livereload": "~0.1.2"
+ "grunt-contrib-livereload": "~0.1.2",
+ "consolidate": "~0.8.0",
+ "dustjs-linkedin": "~1.2.1"
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.