上週的公司內部培訓的時候,瞭解到kite這個東西。聽上去滿不錯的。就下了研究了一下。
kite是google上的一個項目。原理也比較簡單。
kite的Test:效率還不錯。
Engine | Time | Speed | LOC |
---|---|---|---|
jQote2 | 180ms | 100% | 151 lines |
Kite | 530ms | 33.9% | 180 lines |
Mustache | 14170ms | 1.2% | 291 lines |
jQuery.tmpl() | 50030ms | 0.3% | 449 lines |
kite支持三種類型:
1.變量:支持格式化輸入內容
{{varname}} {{varname|formatname}}
2.循環(循環輸出section text,如果varname爲空就輸入alternative text)
{{#varname}} ... section text ... {{/varname}}
{{#varname}} ... section text ... {{^varname}} ... alternative text ... {{/varname}}
3.條件判斷(支持嵌套, “{{/?}}”可以省略)
{{? expr }} ... section text ... {{/?}}
{{? expr }} ... section text ... {{^?}} ... "else" section {{/?}}
{{? expr1 }} section1 {{? expr2}} section2 ... {{^?}} ... "else" section {{/?}}