mustache模板引擎

Logic-less templates.

githubhttp://mustache.github.com/ 
文档:http://mustache.github.com/mustache.5.html 

http://mustache.github.io

Java 版 Mustache SVN 源码 
http://jmustache.googlecode.com/svn   

mustache 类似  freemark和valicity 模板引擎,不过mustache 更轻量级,支持语言: RubyJavaScriptPython,Erlangnode.jsPHPPerlPerl6Objective-CJavaC#/.NETAndroidC++GoLua,oocActionScriptColdFusionScalaClojure,FantomCoffeeScriptDHaskellXQuery,ASPIoDartHaxeDelphiRacketRust,OCamlSwift, and for Bash

 mustache 支持功能比较弱,不过我们可以建立在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 :(


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值