分享

数据模板的JScript.net实现 - lint的专栏

 accesine 2005-10-12
数据模板的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./tpl.rar
解压得到tpl.dll

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

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多