-
Notifications
You must be signed in to change notification settings - Fork 0
/
engine.js
38 lines (28 loc) · 1.05 KB
/
engine.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// CoffeeKup Template Engine wrapper for SocketStream 0.3
var ck = require('coffeekup');
exports.init = function(ss, config) {
return {
name: 'CoffeeKup',
// Opening code to use when a CoffeeKup template is called for the first time
prefix: function() {
return '<script type="text/javascript">(function(){var t=require(\'socketstream\').tmpl;'
},
// Closing code once all CoffeeKup templates have been written into the <script> tag
suffix: function() {
return '}).call(this);</script>';
},
// Compile template into a function and attach it to ss.tmpl
process: function(template, path, id) {
var compiledTemplate;
try {
compiledTemplate = ck.compile(template).toString();
} catch (e) {
var message = '! Error compiling the ' + path + ' template into CoffeeKup';
console.log(String.prototype.hasOwnProperty('red') && message.red || message);
throw new Error(e);
compiledTemplate = '';
}
return 't[\'' + id + '\']=' + compiledTemplate + ';';
}
}
}