最近玩.NET和JSCRIPT
把基于JSCRIPT 的trimpath的TEMPLATE封装到了服务端。 下列程序需要.NET环境支持。 import lint; import System; var data = { products : [ { name: "mac", desc: "computer", price: 1000, quantity: 100, alert:null }, { name: "ipod", desc: "music player", price: 200, quantity: 200, alert:"on sale now!" }, { name: "cinema display", desc: "screen", price: 800, quantity: 300, alert:"best deal!" } ], customer : { first: "John", last: "Public", level: "gold" } }; var cart_jst= "Hello ${customer.first} ${customer.last}.<br/>\ Your shopping cart has ${products.length} item(s):\ <table>\ <tr><td>Name</td><td>Description</td>\ <td>Price</td><td>Quantity & Alert</td></tr>\ {for p in products}\ <tr><td>${p.name|capitalize}</td><td>${p.desc}</td>\ <td>$${p.price}</td><td>${p.quantity} : ${p.alert|default:\"\"|capitalize}</td>\ </tr>\ {forelse}\ <tr><td colspan=\"4\">No products in your cart.</tr>\ {/for}\ </table>\ {if customer.level == \"gold\"}\ We love you! Please check out our Gold Customer specials!\ {else}\ Become a Gold Customer by buying more stuff here.\ {/if}" var str = lint.Tpl.parseTemplate(cart_jst).process(data); Console.WriteLine(str); http://info95./tpl.rar 解压得到tpl.dll jsc /r:tpl.dll test.js 生成test.exe 运行test即可。 |
|