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); }
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); }
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); }