Coder Social home page Coder Social logo

node-pate's Introduction

logo

About

Pâté is a simple XPath-oriented, express-compatible template engine for Node.js

Installation

npm install node-pate

Dependencies

Pâté depends on libxmljs, thus compilation is needed via node-gyp

Dependencies source:

Basic usage

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)

Express example

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

Status

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.

Limitations

  • No array support
  • No support for namespaces

Inspirations

https://github.com/dnewcome/jath

License

Pâté is provided under the MIT free software license. See the file LICENSE for the full text.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.