From 32633a0efa9f788c4e90b31ac124fa59a79f7c5c Mon Sep 17 00:00:00 2001 From: Bharat Kishnani Date: Wed, 9 Dec 2015 17:07:33 +0530 Subject: [PATCH] Added doT js, Fixed nunjucks path --- .gitignore | 6 +++++- dot/index.html | 14 ++++++++++++++ dot/item_partial.def | 6 ++++++ dot/layout.def | 13 +++++++++++++ index.js | 20 ++++++++++++++++++++ nunjucks/index.html | 4 ++-- public/index.html | 1 + 7 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 dot/index.html create mode 100644 dot/item_partial.def create mode 100644 dot/layout.def diff --git a/.gitignore b/.gitignore index 3c3629e..5f9e8b0 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ -node_modules +/node_modules +*.iml +*.ipr +*.iws +/.idea \ No newline at end of file diff --git a/dot/index.html b/dot/index.html new file mode 100644 index 0000000..d15c7b9 --- /dev/null +++ b/dot/index.html @@ -0,0 +1,14 @@ +{{##def.content: + {{ function todos_macro(items) { }} + + {{ } }} + + + {{ todos_macro(it.todos); }} + +#}} +{{#def['layout'] || (def['layout'] = def.loadFile('/layout.def'))}} \ No newline at end of file diff --git a/dot/item_partial.def b/dot/item_partial.def new file mode 100644 index 0000000..b04f188 --- /dev/null +++ b/dot/item_partial.def @@ -0,0 +1,6 @@ +
  • + +
  • diff --git a/dot/layout.def b/dot/layout.def new file mode 100644 index 0000000..84c6209 --- /dev/null +++ b/dot/layout.def @@ -0,0 +1,13 @@ + + + + + + +

    doT Template Example

    + + {{#def.content }} + +

    back

    + + diff --git a/index.js b/index.js index 51b585b..157bb71 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ var mustache = require('mustache'); var dust = require('dustjs-linkedin'); var ejs = require('ejs'); var nunjucks = require('nunjucks'); +var dot = require('dot'); var app = express(); @@ -79,5 +80,24 @@ app.get('/ejs', function(req, res) { res.send(ejs.render(template, options)); }); + + +app.get('/dot', function(req, res) { + var template = fs.readFileSync('./dot/index.html', 'utf8'); + + var dot_render = dot.template(template,undefined, + { + loadFile : function(path) { + return fs.readFileSync(__dirname +"/dot"+ path); + } + }); + + var options = { + filename: './dot/index.html', + todos: todos + }; + res.send(dot_render(options)); +}); + app.listen(3000); console.log('Example is listening on http://127.0.0.1:3000'); diff --git a/nunjucks/index.html b/nunjucks/index.html index 289f476..635018f 100644 --- a/nunjucks/index.html +++ b/nunjucks/index.html @@ -1,9 +1,9 @@ -{% extends "./nunjucks/layout.html" %} +{% extends "./layout.html" %} {% macro todos_macro(items) %} {% endmacro %} diff --git a/public/index.html b/public/index.html index 7d14f96..42050be 100644 --- a/public/index.html +++ b/public/index.html @@ -11,6 +11,7 @@

    Template Examples

  • Dust.js
  • Nunjucks
  • EJS
  • +
  • doT
  • \ No newline at end of file