0.1.3 • Published 11 years ago
jayce v0.1.3
Jayce
Another simple template engine. Just a little different.
Usage
npm install jaycevar jayce = require('jayce')
var render = jayce.compile(fs.readFileSync('path/to/your/template'))
var data = { ... }
var html = render(data)Or render directly (recommend)
var jayce = require('jayce')
var data = { ... }
var html = jayce.render(data)In browser, you can use jayce.min.js, support AMD, CMD, or global mode.
Syntax
Variable
Wrap with {}, and end with $.
<div>{content$}</div>Filters
Make up your filter for variables like this:
jayce.filter('format', function (str) {
// Your code here
})<div>{content | format $}</div>Condition
Wrap with {} too. And more like this:
<p>
{user < 0?}
negative
{user == 0:?}
zero
{:?}
positive
{/?}
</p>Traverse
Really simple: (Also support object)
<ul>
{list, item, key@}
<li>{key$}:{item$}</li>
{/@}
</ul>Html Entities encode
Default, all html entities in variables will be encoded. You can cancel by #:
<div>{#content$}</div>Incorrect type
<div>{:?}</div>Will not throw error, it will output:
<div>{:?}</div>Develop
Now there are some simple test cases in ./test. Run:
npm testTODO
- Easier to debug.
- Functional features.
- More test.
- More Benchmarks.
- High preformance.