diff --git a/README.md b/README.md index 5e97e79..b932080 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ - [Jade](https://github.com/visionmedia/jade) v0.28.1 ([website](http://jade-lang.com/)) - [Swig](https://github.com/paularmstrong/swig) v0.13.5 - [Underscore](https://github.com/documentcloud/underscore) v1.4.4 ([website](http://underscorejs.org/)) +- [Marko](https://github.com/marko-js/marko) v4.5.2([website](http://markojs.com/)) ## Test environment @@ -25,6 +26,11 @@ ## Results Rendering 100000 templates: + + Marko + Escaped : 1086ms + Unescaped : 152ms + Total : 1238ms ECT Escaped : 2180ms @@ -100,6 +106,7 @@ Escaped : 18330ms Unescaped : 12095ms Total : 30425ms + ## Usage diff --git a/benchmark.js b/benchmark.js index 9dac2ad..b62a076 100644 --- a/benchmark.js +++ b/benchmark.js @@ -1,6 +1,7 @@ var data = require('./data'); var count = 100000; +var marko = require('./marko/marko.js'); var ect = require('./ect/ect.js'); var ejs = require('./ejs/ejs.js'); var ejsWithoutWith = require('./ejs-without-with/ejs.js'); @@ -54,7 +55,7 @@ var testUnescaped = function(name, sample, cb) { }; var samples = [ - + { name : 'Marko', sample : marko }, { name : 'Jade', sample : jade }, { name : 'CoffeeKup', sample : coffeekup }, { name : 'Jade without `with`', sample : jadeWithoutWith }, diff --git a/marko/marko.js b/marko/marko.js new file mode 100644 index 0000000..f15d7fd --- /dev/null +++ b/marko/marko.js @@ -0,0 +1,23 @@ +var fs = require('fs'); +var markoCompiler = require('marko/compiler'); +markoCompiler.configure({ writeToDisk: false }); +var marko = require('marko'); +var compiled; +var tplData; + +module.exports.prepare = function (data, done) { + compiled = marko.load(require.resolve('./tpl_escaped.marko')); + tplData = data; + done(); +}; + +module.exports.prepareUnescaped = function (data, done) { + compiled = marko.load(require.resolve('./tpl_unescaped.marko')); + tplData = data; + done(); +}; + +module.exports.step = function (done) { + var html = compiled.renderSync(tplData).toString(); + done(undefined, html); +}; \ No newline at end of file diff --git a/marko/tpl_escaped.marko b/marko/tpl_escaped.marko new file mode 100644 index 0000000..6b75a59 --- /dev/null +++ b/marko/tpl_escaped.marko @@ -0,0 +1,10 @@ +html + head + title -- ${input.title} + body + p -- ${input.text} + if(input.projects.length) + a for(project in input.projects) -- ${project.name} + p -- ${project.description} + else + -- No Projects \ No newline at end of file diff --git a/marko/tpl_unescaped.marko b/marko/tpl_unescaped.marko new file mode 100644 index 0000000..864f048 --- /dev/null +++ b/marko/tpl_unescaped.marko @@ -0,0 +1,10 @@ +html + head + title -- $!{input.title} + body + p -- $!{input.text} + if(input.projects.length) + a for(project in input.projects) -- $!{project.name} + p -- $!{project.description} + else + -- No Projects \ No newline at end of file diff --git a/package.json b/package.json index 3bc3c3b..29280d1 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "handlebars": "1.0.9", "coffeekup": "0.3.1", "underscore": "1.4.4", - "gaikan": "1.3.4" + "gaikan": "1.3.4", + "marko": "4.5.2" } }