jbj-template
JBJ template module: advanced use of variables within strings
Last updated 4 years ago by touv .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install jbj-template 
SYNC missed versions from official npm registry.

JBJ template module

JBJ template module: advanced use of variables within strings (compute, template)

Contributors

Installation

$ npm install jbj-template

Usage

This JBJ module cannot be used alone. JBJ has to be installed.

var JBJ = require('jbj');
JBJ.use(require('jbj-template'));

Tests

Use mocha to run the tests.

$ npm install
$ npm test

Actions

Once the module is declared as used for JBJ, you can use the following actions:

template: mustacheTemplate | [mustacheTemplate, mustacheTemplate, ...]

Build a string with mustache template and input

    var stylesheet = {
        "set" : {
            "a" : {
                "b" : "hello"
            },
            "c" : "world"
        },
        "template": "I say {{a.b}} to the {{c}}"
    };
    // output : I say hello to the world

compute: expression

Compute an expression with all variables of the input. Use the filtrex syntax. Note : this variable contains input

    var stylesheet = {
        "set" : {
            "a" : 20,
            "b" : 3,
            "c" : 5,
            "d" : 8
        },
        "$x" : {
            "compute#1": "a / b",
            "compute#2": "round(this)",
            "cast": "number"
        },
        "$y" : {
            "path": "b",
            "cast": "number"
        },
        "$z" : {
            "compute": "x + y",
        }
    };
    // output : 10

Examples

See unit tests : https://github.com/Inist-CNRS/node-jbj-template/tree/master/test

Try it

http://Inist-CNRS.github.io/node-jbj/

License

MIT

Current Tags

  • 2.0.0                                ...           latest (4 years ago)

2 Versions

  • 2.0.0                                ...           4 years ago
  • 1.0.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 2
Dependencies (3)
Dev Dependencies (2)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |