コード例 #1
0
        public void testLoopTwice()
        {
            string html = @"<!-- BEGIN category -->#{category.Name}<!-- BEGIN list --><div>#{title}<br/>#{body}</div><!-- END list --><!-- END category -->";

            wojilu.Web.ITemplate tpl           = new Template().InitContent(html);
            wojilu.Web.IBlock    categoryBlock = tpl.GetBlock("category");
            for (int k = 1; k < 3; k++)
            {
                categoryBlock.Set("category.Name", "分类" + k);

                wojilu.Web.IBlock block = categoryBlock.GetBlock("list");
                for (int i = 1; i < 3; i++)
                {
                    block.Set("title", "我是标题" + k + "_" + i);
                    block.Set("body", "我是内容" + k + "_" + i);
                    block.Next();
                }

                categoryBlock.Next();
            }

            string result   = tpl.ToString();
            string expected = @"分类1<div>我是标题1_1<br/>我是内容1_1</div><div>我是标题1_2<br/>我是内容1_2</div>分类2<div>我是标题2_1<br/>我是内容2_1</div><div>我是标题2_2<br/>我是内容2_2</div>";

            Assert.AreEqual(expected, result);
        }
コード例 #2
0
        public void testLoop()
        {
            string html = "<!-- BEGIN list --><div>#{title}<br/>#{body}</div><!-- END list -->";

            wojilu.Web.ITemplate tpl   = new Template().InitContent(html);
            wojilu.Web.IBlock    block = tpl.GetBlock("list");
            for (int i = 1; i < 3; i++)
            {
                block.Set("title", "我是标题" + i);
                block.Set("body", "我是内容" + i);
                block.Next();
            }
            string result = tpl.ToString();

            Assert.AreEqual("<div>我是标题1<br/>我是内容1</div><div>我是标题2<br/>我是内容2</div>", result);
        }
コード例 #3
0
        public void testSameVar()
        {
            string html = @"第一个listing<!-- BEGIN list --><div>#{title}<br/>#{body}</div><!-- END list -->
第二个listing2<!-- BEGIN list2 --><div>#{title}<br/>#{body}</div><!-- END list2 -->
第三个listing3<!-- BEGIN list3 --><div>#{title}<br/>#{body}</div><!-- END list3 -->";

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

            wojilu.Web.IBlock block  = tpl.GetBlock("list");
            wojilu.Web.IBlock block2 = tpl.GetBlock("list2");
            wojilu.Web.IBlock block3 = tpl.GetBlock("list3");

            for (int i = 1; i < 3; i++)
            {
                block.Set("title", "我是标题" + i);
                block.Set("body", "我是内容" + i);
                block.Next();
            }

            for (int i = 1; i < 3; i++)
            {
                block2.Set("title", "我是2标题" + i);
                block2.Set("body", "我是2内容" + i);
                block2.Next();
            }

            for (int i = 1; i < 3; i++)
            {
                block3.Set("title", "我是3标题" + i);
                block3.Set("body", "我是3内容" + i);
                block3.Next();
            }

            string result = tpl.ToString();

            Console.WriteLine("");
            Console.WriteLine("-----------------------------------------------------------------");
            Console.WriteLine(result);

            string target = @"第一个listing<div>我是标题1<br/>我是内容1</div><div>我是标题2<br/>我是内容2</div>
第二个listing2<div>我是2标题1<br/>我是2内容1</div><div>我是2标题2<br/>我是2内容2</div>
第三个listing3<div>我是3标题1<br/>我是3内容1</div><div>我是3标题2<br/>我是3内容2</div>";

            Assert.AreEqual(target, result);
        }
コード例 #4
0
        public void testLoopThird()
        {
            string html = @"
<!-- BEGIN page -->【#{page.Name}】
<!-- BEGIN category -->#{category.Name}
<!-- BEGIN list --><div>#{title}<br/>#{body}</div>
<!-- END list -->
<!-- END category -->
<!-- END page -->
";

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

            wojilu.Web.IBlock pageBlock = tpl.GetBlock("page");
            for (int j = 1; j < 4; j++)
            {
                pageBlock.Set("page.Name", "页面" + j);

                wojilu.Web.IBlock categoryBlock = pageBlock.GetBlock("category");
                for (int k = 1; k < 3; k++)
                {
                    categoryBlock.Set("category.Name", "分类" + k);

                    wojilu.Web.IBlock block = categoryBlock.GetBlock("list");
                    for (int i = 1; i < 3; i++)
                    {
                        block.Set("title", "我是标题" + k + "_" + i);
                        block.Set("body", "我是内容" + k + "_" + i);
                        block.Next();
                    }

                    categoryBlock.Next();
                }

                pageBlock.Next();
            }

            string result = tpl.ToString();

            Console.WriteLine("");
            Console.WriteLine("-----------------------------------------------------------------");
            Console.WriteLine(result);
        }
コード例 #5
0
        public void testGetSubBlock()
        {
            string html = @"cc
<!-- BEGIN page -->【#{page.Name}】
    <!-- BEGIN category -->#{category.Name}<!-- END category -->
    <!-- BEGIN list --><div>#{title}<br/>#{body}</div><!-- END list -->
<!-- END page -->
aa
";

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

            wojilu.Web.IBlock pageBlock = tpl.GetBlock("page");

            for (int j = 1; j < 4; j++)
            {
                pageBlock.Set("page.Name", "页面" + j);

                wojilu.Web.IBlock categoryBlock = pageBlock.GetBlock("category");
                wojilu.Web.IBlock listBlock     = pageBlock.GetBlock("list");

                for (int k = 1; k < 3; k++)
                {
                    categoryBlock.Set("category.Name", "分类" + k);
                    categoryBlock.Next();
                }

                for (int x = 1; x < 3; x++)
                {
                    listBlock.Set("title", "title" + x);
                    listBlock.Set("body", "body" + x);
                    listBlock.Next();
                }

                pageBlock.Next();
            }

            string result = tpl.ToString();

            Console.WriteLine("");
            Console.WriteLine("-----------------------------------------------------------------");
            Console.WriteLine(result);
        }