velocity.java

1.3.1 • Public • Published

velocity.java

NPM

Apache Velocity is a general purpose template engine.
This is a nodejs wrap for Apache Velocity.

Requirements

  • JRE 1.6 or higher

API

velocity.renderOnce(filename[, data][, root], callback)

  • filename String
  • data Object
  • root String | Array
  • callback Function

Render the template specified by filename with data.

root accepts multi-value. Root(s) from which the loader loads templates. Templates may live in subdirectories of this root. filename is the relative path to root.

Example:

var velocity = require("velocity.java");
velocity.renderOnce("example.vm", {}, "example/", function(err, data) {
    if (err) {
        console.error(err);
        return;
    }
    console.log(data.toString());
});

The callback is passed two arguments (err, data), where data is the buffer of the rendered template.

velocity.startServer([port][, callback])

  • port Number default = 12306
  • callback Function

callback, test whether the JRE exists. Then call the callback argument with either true or false.

velocity.stopServer()

velocity.render(filename[, data][, root], callback)

  • filename String
  • data Object
  • root String | Array
  • callback Function

Java startup time is often much slower, because a lot of classes must be loaded before being used. So, velocity.java provides one simple server to speed up rendering. render usually used after startServer. Example:

var velocity = require("velocity.java");
velocity.startServer(8000);
velocity.render("example.vm", {}, "example/", function(err, data) {
    if (err) {
        console.error(err);
        return;
    }
    console.log(data.toString());
    velocity.stopServer();
});

Package Sidebar

Install

npm i velocity.java

Weekly Downloads

30

Version

1.3.1

License

ISC

Last publish

Collaborators

  • icewhite