New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

velocity-template

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

velocity-template

velocity template engine, it can run on browser and node side

latest
Source
npmnpm
Version
0.1.3
Version published
Maintainers
1
Created
Source

velocity-template engine.

velocity-template is the javascript implementation of the velocity template engine, it can run on browser and node side.

Features

  • Support both brwoser and node side.
  • Parsing and rendering separation.
  • Support for almost all syntax of the java velocity implementation.
  • Vim Syntax for vim.

Install

npm install velocity-template --save-dev

Get Started

Direct script tag include(it provides the Velocity as a global variable.)

or:

Via npm

import Velocity from "velocity-template"

Usage

var tpl = `
  #foreach($item in $items)
      <li>$item</li>
  #end
`
var asts = Velocity.parse(tpl);
var data = {
  items: ["a", "b", "c", "d"]
};
var html = (new Velocity.Compile(asts)).render(data);

API

render

Velocity.render(vm, context, macros);

  • vm {string} velocity string input
  • context {object} render context, data or function for vm
  • macros {object} such as #include('path/xxx') , you can define you inlcude macro function

parse and Complile

parse method can parse vm, and return ast tree of velocity.

Compile will render asts to result string.

parse

Velocity.parse(vm)

  • vm {string} string of velocity
  • blocks {object} self define blocks, such as #cms(1) hello #end, you can set {cms: true}
  • ignorespace {boolean} if set true, then ignore the newline trim

Compile

new Compile(asts[, config])

  • asts {array} array of vm asts tree
  • config {object} you can define some option for Compile
var Compile = Velocity.Compile;
var asts = Velocity.parse('string of velocity');
(new Compile(asts)).render(context, macros);

Syntax

Syntax you can find from velocity user guide

License

LICENSE MIT

FAQs

Package last updated on 14 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts