Pâté is a simple XPath-oriented, express-compatible template engine for Node.js
npm install node-pate
Pâté depends on libxmljs, thus compilation is needed via node-gyp
Dependencies source:
- Python
- Unix: Python v2.7
- Windows: v2.7.3
- C/C++ Compiler
- Unix: GCC
- Windows: Visual Studio C++ 2010 Express
var pate = require('node-pate');
var formatter = require('./format_lib.js');
var options = {
tpl: '{{ bread/@name }} price: $[[ formatMoney({{ bread/@price }}) ]] ([[ moneyToWords({{ bread/@price }}) ]])',
xml: '<data><row><bread name="Bretzel" price="42.56" /></row></data>',
xpath: '/*/*',
format_lib: formatter
};
pate.parse(options, function (err, data) {
console.log(data);
});
Output:
Bretzel price: $42.56 (CUARENTA Y DOS PESOS CON 56/100)
Application:
var express = require('express');
var app = express();
var router = express.Router();
var pate = require('node-pate');
var formatter = require('./format_lib.js')
// view engine setup
app.engine('html', pate.__express);
app.set('views', path.join(__dirname, 'views'));
...
router.get('/test', function(req, res, next) {
res.render('templates/test.html', {
xml: '<data><row><bread name="Bretzel" price="42.56" /></row></data>',
xpath: '/*/*',
format_lib: formatter
});
});
Test:
cd test-express && node bin/www
Go to: http://localhost:3000/test
This software is still evolving. There are likely cases that it cannot handle, so file a feature request in github if there is something you think it should do.
- No array support
- No support for namespaces
https://github.com/dnewcome/jath
Pâté is provided under the MIT free software license. See the file LICENSE for the full text.