gulp-velocity

0.0.2 • Public • Published

gulp-velocity

A gulp plugin for rendering velocity template, based on the node module velocity.

node velocity

Bug and suggestion


0. introduce

This plugin is written based on the node module velocity, it's core function is done by the "velocity" module, this plugin is just a wrapper of it.

1. Installment

$ npm install gulp-velocity
or
$ git clone https://github.com/winnieBear/gulp-velocity.git 

2. Quick Start

An example is ready for you:

$ git clone https://github.com/winnieBear/gulp-velocity.git 
$ cd gulp-velocity/example/
$ npm install
$ gulp tpl

the introduce of dir

src
|-- tpl  
|   |-- direc
|   |   |-- define.vm
|   |   `-- ... 
|   |
|   `-- index.vm 
|-- data
|   |-- direc
|   |   |-- define.js
|   |    `-- ... 
|   |   
|   `-- index.js 
`-- tmp
        |
 		`-- index.html

  • tpl directory to store the template file

  • data directory to store the simulating data, one data file is corresponding to a template file, the data file format look like literal object in javascript.

  • tmp directory to store the rendered result file, which is rendered based on the template file and the corresponding simulating data file.

3. Config

var velocity = require('gulp-velocity');

var config ={
        "root":"./src/tpl/",// tpl root path 
        "encoding":"utf-8", // optional,tpl encoding format
        "macro":"./src/tpl/global-macro/macro.vm", //global macro defined file, more macro file can saved in array, e.g. ["macro_file_1","macro_file_2",...]
        "globalMacroPath":"./src/tpl/global-macro", //global macro defined root path
        "dataPath":"./src/data/" // simulating data root path
    }

you can use it as below:

...
    .pipe(
        velocity(config)
        .on('error', gutil.log)
    )
...


4. Special instructions

why use gulp-plumber

The plugin of gulp-plumber is used in my example for the usage scenario in which your template file has a syntax error and gulp-velocity will throw an error, which will break the gulp event stream, some discussions is here. To continue the stream when error happens, you can use the plugin of gulp-plumber.

Package Sidebar

Install

npm i gulp-velocity

Weekly Downloads

4

Version

0.0.2

License

none

Last publish

Collaborators

  • winniebear