liteParse !
Fast and easy template parser for javascript
features
- Fast
- Easy
- File parsing
- Uses JSON for templating data
- Accessing from command line
- Fast!
installation
Installing npm (node package manager)
curl http://npmjs.org/install.sh | sh
Installing liteParse
$ [sudo] npm install liteParse -g
For accessing liteParse from command line via
litepar
command, Add-g
when installing liteParse with npm
Usage
There are two ways to use liteParse: through the command line interface, or by requiring the liteParse module in your own code
Using liteParse from command line
You can use liteParse to parse any template files you have, With some data s that are saved in another file
example :
there is a file named toparse.tpl
:
{students} Name : {name} Grade : {grade} {/students}
and there is another file named data.json
:
{ "students" : [ { "name" : "John", "grade" : "6" }, { "name" : "micheal", "grade" : "8" } ]}
we want to parse the toparse.tpl file with the data s which are stored in data.json file
$ [sudo] litepar parse toparse.tpl data.json
And then the parsed html page will print in command line interface
To store the parsed html in a file, Do :
$ [sudo] litepar parse toparse.tpl data.json -t 'name-of-a-file-to-store'
If you want to see the parsed html that will save in the file, Do :
$ [sudo] litepar parse toparse.tpl data.json -t 'name-of-a-file-to-store' -p
help of liteParse command line
$ litepar --helpUsage: litepar parse <file> <data file> [options]Commands:parse <file> <datafile>Parse a file with the JSON data of the given data fileOptions:-h, --help output usage information-V, --version output the version number-s, --show Show the parsed string-e, --encoding <value> File parsing encoding-t, --tofile <value> Save the parsed file to another file-l, --leftdelim <value> Determine the left delimeter-r, --rightdelim <value> Determine the right delimeter
Delimeters : the character or string which liteParse uses for parsing, in
{students}
the character{
is left delimeter and}
is right delimeter. These two characters are default delimeters For changing the delimeters use-l 'delim'
and '-r 'delim'' commands.
Using liteParse as Node.js module
A good example for understanding everything :
var lp = ;/*** liteParse have 5 functions :*/// -------------------------------------------------------------------------------------------/*** 1- liteParse.parse* @param* @param* @return*/var parsedTemplate1 = lp;/* parsedTemplate1 = 'my name is Hamidreza and your name is Juliet' */// -------------------------------------------------------------------------------------------/*** 2- liteParse.setDelimeters* @param* @param*/lp;var parsedTemplate2 = lp;// parsedTemplate2 = 'my name is Ryan'// -------------------------------------------------------------------------------------------/*** 3- leftDelim 4- rightDelim* @return*/var nowLeftDelim = lp;// nowLeftDelim = '{{'lp;var nowRightDelim = lp;// nowRightDelim = '}'// -------------------------------------------------------------------------------------------/*** 5- fileParsing** @param* @return* and false if there is a problem*/var parsedTemplate = lp;// -------------------------------------------------------------------------------------------