Exemplo n.º 1
0
        public void testFunction()
        {
            // 多个函数测试
            String html = @"
<%@ Page Language=""C#"" %>

<%@ Import Namespace=""wojilu"" %>
<%@ Import Namespace=""System.Collections.Generic"" %>

<% List<TVUser> userList=v.data(""ulist"") as List<TVUser> %>

<script runat=""server"">
public String getTitle( String title, int count ) {
    return strUtil.CutString( title, count )+""--ztitle"";
}
public String getUser( String title, int count ) {
    return strUtil.CutString( title, count )+""--zuser"";
}
</script>

<div>数据循环显示</div>
<%foreach( TVUser user in userList ) {%>

    <div>用户:<%= getUser(user.Name,5) %></div>

    <%foreach( TVPage page in user.Pages ) {%>
        <div>页面:<%= page.Info %></div>
        <%foreach( TVPost post in page.Posts ) {%>
            <div>帖子:<%= getTitle(post.Title,10) %></div>
        <%}%>

    <%}%>

<%}%>
";

            wojilu.Web.Template tpl = new Template().InitContent(html) as Template;

            // 必须使用 Bind
            tpl.Bind("ulist", getUserList());

            // 不能使用BindList,因为这是传统区块模式
            //tpl.BindList( "ulist", "x", getUserList() );


            ITemplateResult x = tpl.Compile();

            Console.WriteLine(x.GetResult());
        }
Exemplo n.º 2
0
        public void testLoop()
        {
            String html = @"
<%@ Page Language=""C#"" %>

<%@ Import Namespace=""wojilu"" %>
<%@ Import Namespace=""System.Collections.Generic"" %>

<% List<TVUser> userList=v.data(""ulist"") as List<TVUser> %>

<div>数据循环显示</div>
<%foreach( TVUser user in userList ) {%>

    <div>用户:<%= user.Name %></div>

    <%foreach( TVPage page in user.Pages ) {%>
        <div>页面:<%= page.Info %></div>
        <%foreach( TVPost post in page.Posts ) {%>
            <div>帖子:<%= post.Title %></div>
        <%}%>

    <%}%>

<%}%>
";

            wojilu.Web.Template tpl = new Template().InitContent(html) as Template;

            // 必须使用 Bind
            tpl.Bind("ulist", getUserList());

            // 不能使用BindList,因为这是传统区块模式
            //tpl.BindList( "ulist", "x", getUserList() );


            ITemplateResult x = tpl.Compile();

            Console.WriteLine(x.GetResult());
        }
Exemplo n.º 3
0
        public void testCode()
        {
            string html = @"

<%@ Page Language=""C#"" %>

<%@ Import Namespace=""wojilu"" %>
<%@ Import Namespace=""System.Collections.Generic"" %>
<%@   Import    Namespace="" wojilu.Test.Orm.Entities ""   %>

<%
html.show( ""这是第一行"" );
html.showLine( ""这是第2行"" );
html.show( ""这是第3行"" );
html.showLine( html.encode( ""<script>"" ) );
List<TVPost> posts = v.data(""post"") as List<TVPost>;
TVPage p = v.data(""p"") as TVPage;
%>
<div>文章列表:</div>
<div>页面信息:#{p.Info},审核:#{p.User.Name}</div>
<div>页面信息(此行必须先强类型转换):<%=p.Info%>,审核:<%=p.User.Name %></div>


<script runat=""server"">
        public String getTitle( String title, int count ) {
            return strUtil.CutString( title, count )+""--ztitle"";
        }
</script>

<% if( posts.Count==0 ) { %>
    <div>没有数据#{msg}</div>
<% } else {%>
    <div>数据总共 <%= posts.Count %> 条。#{tip}</div>

    <% for( int i=0;i<posts.Count;i++ ) {%>
        <div>编号:<%=i%>, 标题:<%= getTitle(posts[i].Title,5) %>,作者:<%= posts[i].User.Name %></div>
    <%}%>

<%}%>
<div>---------传统的循环标记-----------</div>
<!-- BEGIN list -->
    <div>没有数据#{x.Title}</div>
<!-- END list -->

<div>---------调用ORM-----------</div>
<%
List<TArticle> articles = db.find<TArticle>( """" ).list();
%>
<% for( int i=0;i<articles.Count;i++ ) { %>
    <div>编号:<%=i%>, 博客:<%= articles[i].Title %>,作者:<%= articles[i].Member.Name %></div>
<%}%>
";
            TVUser u1   = new TVUser {
                Name = "孙中山1"
            };
            TVUser u2 = new TVUser {
                Name = "袁世凯2"
            };

            TVPage p = new TVPage {
                Info = "页面info", User = u2
            };

            List <TVPost> list = new List <TVPost> {
                new TVPost {
                    Title = "标题111", User = u1
                },
                new TVPost {
                    Title = "标题222", User = u2
                }
            };


            wojilu.Web.Template tpl = new Template().InitContent(html) as Template;

            //tpl.Set( "post", list ); // 这种是错误的
            tpl.Bind("post", list);   // 绑定对象,必须使用bind
            tpl.Bind("p", p);
            tpl.Set("msg", "--");
            tpl.Set("postId", 8);
            tpl.Set("tip", "{这是动态提示}");

            tpl.BindList("list", "x", list);



            ITemplateResult x = tpl.Compile();

            Console.WriteLine(x.GetResult());
            Console.ReadLine();
        }