Skip to content

Commit

Permalink
Merge branch 'master' of github.com:fishbar/liteview
Browse files Browse the repository at this point in the history
  • Loading branch information
fishbar committed Feb 21, 2012
2 parents 3b95ba2 + c30879e commit 69566d9
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,70 @@
##liteview

a NodeJS template engine!

example:

var view = require('liteview');
view.init(tpl_base); // set template base to view
view.debug(true); //if needed, set debug ,view will console.log the debug info
view.render('test.html',{
name:'liteview',
version:'v x.x.x'
version:'v x.x.x',
list:[
{name:'fish',address:'abc'},
{name:'cat',address:'def',child:[{item:'apple'},{item:'orange'}]},
{name:'dog',address:'ghi',array:['a','b','c']},
]
});

============== tpl test.html =============
<html>
<head></head>
<body>
#{if(#list)}
<ul>
#{foreach(#list)}
<li>
#{[-]} : #{[name]} - #{[address]}
#{foreach(#[child])}
<span>#{[item]}</span>
#{end}
#{foreach(#[array])}
<i>#{[_]}</i>
#{end}
</li>
#{end}
</ul>
#{end}
</body>
</html>

features:

* simple syntax,type less , do more;
* cache template into mem, so run more faster;

syntax:

* variable
#{var} #var
* if else
#{if(#var)} #{elseif(#var1)} #{else} #{end}
* foreach
#{foreach(#var)} #{end}
variable in foreach using #{[xxx]} , #[xxx]
magic var : #{[-]} , #{[_]} , #{[%]} // array index , array item , array length
* expression
#{(#a+1)}
#{(func(#a+1))}
api:

* init(base); init template base
* debug(bool); set debug
* handler(name,func); regist functions that called in the tpl
* tpl(tpl); pre-compile the tpl file, and tpl will be cached ,so when cal render, no more compile;
* render(tpl,data); return string (usually html code);

... to be contine

next update ,template run in browser

0 comments on commit 69566d9

Please sign in to comment.