mustache-expressions
v0.0.37
Published
A hack of the mustache templating library to support Angular expressions to handle logic statements within templates.
Downloads
228
Readme
A hack of the mustache templating library to support Angular style expressions in your templates so you can use logic statements. See for a complete reference of all possibilities of angularjs parsing: http://teropa.info/blog/2014/03/23/angularjs-expressions-cheatsheet.html.
Example usage
var expressions = require("angular-expressions");
var mustpressions = require("mustache-expressions");
var s = { name: "Luke" };
// Example filter
expressions.filters.upper = function(input) {
// This condition should be used to make sure that if your input is undefined, your output will be undefined as well and will not throw an error
if(!input) return input;
return input.toUpperCase();
}
// Use the angular expressions engine
mustpressions.parser = function(tag, data) {
if (!data) { data = s; }
if (!tag || !data) return false;
return ((expressions.compile(tag)(data) == undefined) ? false : expressions.compile(tag)(data));
};
var rendered = mustpressions.render("Hello.{{#name == 'Luke'}} I'm {{name | upper}},{{/}} what is your name?", s);
console.log(rendered);
// OUTPUT: Hello. I'm LUKE, what is your name?