数据模板的JScript.net实现

最近玩.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.vicp.net/tpl.rar
解压得到tpl.dll

jsc /r:tpl.dll test.js
生成test.exe
运行test即可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值