您的位置:首页 > 其它

mustache模板引擎

2015-06-13 22:34 363 查看
Logic-less templates.github:http://mustache.github.com/ 文档:http://mustache.github.com/mustache.5.html http://mustache.github.ioJava
版 Mustache SVN 源码http://jmustache.googlecode.com/svnmustache 类似 freemark和valicity
模板引擎,不过mustache 更轻量级,支持语言: Ruby, JavaScript, Python,Erlang, node.js, PHP, Perl, Perl6, Objective-C, Java, C#/.NET, Android, C++, Go, Lua,ooc, ActionScript, ColdFusion, Scala, Clojure,Fantom, CoffeeScript, D, Haskell, XQuery,ASP, Io, Dart, Haxe, Delphi, Racket, Rust,OCaml, Swift,
and for Bashmustache 支持功能比较弱,不过我们可以建立在mustache 之上进行扩展实现。mustache的特点就是很语法很简单,主要语法如下{{ name }} 打印变量,默认是escape过的,如果不要escape,用3个分隔符 {{{ name }}},或者用 {{ &name }},这个和分隔符无关
{{#person}}…{{/person}} 区块,4种方式person是真假值,决定是否输出
person 是list of array,会循环展开 for x in person:section.render('xxx)
person 是匿名函数/object, 区块包裹的html 会作为参数传递进去
person 是dict,直接打印 dict[key]{{^person}}…{{/person},反向区块
{{!name }} 注释
{{> box }} 载入子模块Template:
{{#person?}}
Hi {{name}}!
{{/person?}}
Hash:
{
"person?": { "name": "Jon" }
}
Output:
Hi Jon!
Template:
{{#repo}}
<b>{{name}}</b>  JS-USE:{{#first}}++{{/first}}  JAVA-USE: first:{{-first}} last:{{-last}} index:{{-index}}
{{/repo}}
{{^repo}}
No repos :(
{{/repo}}
Hash:
{
"repo": []
}
Output:
No repos :(


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: