A Javascript template engine by @Elvis
Why I want to create this wheel? I get inspiration from peg.js which is a generator for parser. But it seems complex to use because it's grammar isn't easy to understand, so I try to write a parser use pure javascript code.
And I named it stouts, it's just a kind of beer. I love it's strong flavour and dark color.
You can get Stouts via npm.
$ npm install stouts --save
Below is a quick example how to use stouts:
var view = {
names: [{
name: 'Elvis'
}, {
name: 'Joe'
}, {
name: 'Tank'
}],
age: 24
};
var output = Stout.render("Name are: {{#names}}{{name}},{{/names}} age is {{age}}", view);
- Stouts.render(template, view)
- Stouts.parse(template);
- {{variable}} -> Raw value
- {{{variable}}} -> Escape value
- {{#names}}{{name}}{{/names}} -> Loop
Install dependencies.
$ npm install
Then run the tests.
$ npm install stouts --save
Follow http://jamesknelson.com/using-es6-in-the-browser-with-babel-6-and-webpack/
Follow http://jamesknelson.com/testing-in-es6-with-mocha-and-babel-6/
Follow https://github.com/trwalker/javascript-es6-styleguide
File naming: One Class per File, Only one class should be declared per file and the file name should match the class name. If the class is named "Car" then the file should be named "car.js".