npm install ak-templateak-template
===========
Micro-template engine.
Using John Resig's micro-template specs.
template(str)Returns compiled template.
N.B: templates are cached.
- str String
String representing the template.
Using John Resig's micro-template format.
function (locals) {}
You can pass an Object as a parameter, it will be accessible within the template through the variable locals.
See example for more details.
template.globals ObjectDefine globals: keys are defaulted with locals.
Think of it more as global defaults. Useful for sharing helper functions.
See example for more details.
template.escape(str)Escape function, replaces <, >, &, ", ' by their equivalent HTML entity.
Can be overridden.
``javascript
var template = require('ak-template');
template.globals.title = 'JavaScript FTW!';
template.globals.upper = function (str) {
return (str + '').toUpperCase();
};
// replace
template('
// using plain JS
template('<% if (locals.foo) { %>
// escape
template('<%- locals.word %>')({'word': ''}); // -> <script>do_evil()</script>
template('<%= locals.word %>')({'word': ''}); // ->
template.escape = function (str) {
return str.toUpperCase();
};
template('<%- locals.word %>')({'word': ''}); // ->
template('<%= locals.word %>')({'word': ''}); // ->
`
and not using with?with` is evil.