0.0.37 • Published 2 years ago

mustache-expressions v0.0.37

Weekly downloads
1
License
MIT
Repository
-
Last release
2 years ago

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?
0.0.33

2 years ago

0.0.34

2 years ago

0.0.35

2 years ago

0.0.36

2 years ago

0.0.37

2 years ago

0.0.32

5 years ago

0.0.31

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago