public void loopAgain() { ConsoleTitleUtil.ShowTestTitle( "loopAgain" ); string looppage = @" <table> <!-- BEGIN newphotos --> <tr><td>#{Title}</td><td>#{CreateTime}</td></tr> <tr><td colspan=2><!-- BEGIN item --> #{Name} <!-- END item --></td></tr> <!-- END newphotos --> </table> "; //TReg.Init(); Template t = new Template(); t.InitContent( looppage ); IBlock block = t.GetBlock( "newphotos" ); for( int i=0;i<5;i++ ) { block.Set( "Title", "mytitle" + i ); block.Set( "CreateTime", "190"+i ); IBlock block2 = block.GetBlock( "item" ); for( int k=0;k<5;k++ ) { block2.Set( "Name", "nameis"+k); block2.Next(); } block.Next(); } Console.WriteLine( t ); }
public static void BindTemplate( Template template, IList list, String categoryName, String actionUrl ) { template.Set( "settingCategory.Name", categoryName ); template.Set( "ActionUrl", actionUrl ); IBlock block = template.GetBlock( "list" ); foreach (ISetting setting in list) { block.Set( "setting.Id", setting.Id ); block.Set( "setting.Title", setting.Name ); SetInput( block, setting ); SetNote( block, setting ); block.Next(); } }
public void testBlockShow() { string html = "这是相关内容<!-- BEGIN list --><div>需要显示的内容</div><!-- END list -->"; wojilu.Web.ITemplate tpl2 = new Template().InitContent( html ); wojilu.Web.IBlock block2 = tpl2.GetBlock( "list" ); Assert.AreEqual( "这是相关内容", tpl2.ToString() ); wojilu.Web.ITemplate tpl3 = new Template().InitContent( html ); wojilu.Web.IBlock block3 = tpl3.GetBlock( "list" ); block3.Next(); Assert.AreEqual( "这是相关内容<div>需要显示的内容</div>", tpl3.ToString() ); }
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 loop() { ConsoleTitleUtil.ShowTestTitle( "loop" ); string looppage = @" <table><!-- BEGIN newphotos --> <tr><td>#{Title}</td><td>#{CreateTime}</td></tr><!-- END newphotos --> </table> "; Template loopTemplate = new Template(); loopTemplate.InitContent( looppage ); // 给循环块设值 IBlock loopBlock = loopTemplate.GetBlock( "newphotos" ); for( int i=0;i<5;i++ ) { loopBlock.Set( "Title", "一百航的诗篇"+i ); loopBlock.Set( "CreateTime", DateTime.Now.ToString() ); loopBlock.Next(); } Console.WriteLine( loopTemplate ); }
private string getEditPage( EntityInfo ei, bool isEdit ) { Template template = new Template(); template.InitContent( viewTemplate.GetAddView() ); template.Set( "mName", ei.Label ); IBlock block = template.GetBlock( "list" ); foreach (EntityPropertyInfo info in ei.SavedPropertyList) { string rule = ""; string msg = ""; string valid = ""; string tip = ""; if (!info.Name.Equals( "Id" )) { block.Set( "m.Label", info.Label ); block.Set( "m.InputBox", this.getInputBox( info, isEdit, ref valid, ref rule, ref msg, ref tip ).ToString().Replace( "name=", tip + " name=" ) + this.setValid( valid, msg, rule ) ); block.Next(); } } return template.ToString(); }
//----------------------------------------layout-------------------------------------------------------------------------------------------------- private void makeLayoutController() { Template template = new Template(); template.InitContent( LayoutTemplate.GetAdminLayoutAction() ); IBlock block = template.GetBlock( "list" ); foreach (DictionaryEntry entry in MappingClass.Instance.ClassList) { EntityInfo ei = entry.Value as EntityInfo; String lmName = strUtil.GetCamelCase( ei.Name ); block.Set( "mName", ei.Name ); block.Set( "lmName", lmName ); block.Next(); } wojilu.IO.File.Write( Path.Combine( this.controllerPath, "LayoutController.cs" ), template.ToString() ); }
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 ); }
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 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 ); }
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 ); }
private void makeLayoutView() { Template template = new Template(); template.InitContent( viewTemplate.GetLayoutView() ); IBlock block = template.GetBlock( "list" ); foreach (KeyValuePair<String, EntityInfo> kv in MappingClass.Instance.ClassList) { EntityInfo ei = kv.Value as EntityInfo; String lmName = strUtil.GetCamelCase( ei.Name ); block.Set( "m.Name", ei.Label ); block.Set( "m.LName", lmName ); block.Set( "m.AdminLink", "#{" + lmName + ".AdminLink}" ); block.Next(); } String path = Path.Combine( this.viewPath, "Layout" ); if (!Directory.Exists( path )) Directory.CreateDirectory( path ); wojilu.IO.File.Write( Path.Combine( path, "Layout.html" ), template.ToString() ); }
private string getEditPage( EntityInfo ei, bool isEdit ) { Template template = new Template(); template.InitContent( CrudViewTemplate.GetAddView() ); template.Set( "mName", ei.Label ); IBlock block = template.GetBlock( "list" ); foreach (EntityPropertyInfo info in ei.SavedPropertyList) { if (!info.Name.Equals( "Id" )) { block.Set( "m.Label", info.Label ); block.Set( "m.InputBox", this.getInputBox( info, isEdit ) ); block.Next(); } } return template.ToString(); }
public void testGlobalVar() { string html = @"页面开头 <!-- BEGIN category -->#{category}<!-- BEGIN list --><div>#{category}:#{title}<br/>#{body}</div><!-- END list --> <!-- END category -->"; wojilu.Web.ITemplate tpl = new Template().InitContent( html ); IBlock block = tpl.GetBlock( "category" ); for (int i = 0; i < 2; i++) { block.Set( "category", "大门"+i ); IBlock list = block.GetBlock( "list" ); for (int x = 20; x < 22; x++) { list.Set( "title", "标题"+x ); list.Set( "body", "内容" + x ); list.Next(); } block.Next(); } string result = tpl.ToString(); string target = @"页面开头 大门0<div>大门0:标题20<br/>内容20</div><div>大门0:标题21<br/>内容21</div> 大门1<div>大门1:标题20<br/>内容20</div><div>大门1:标题21<br/>内容21</div> "; Console.WriteLine( "" ); Console.WriteLine( "-----------------------------------------------------------------" ); Console.WriteLine( result ); Assert.AreEqual( target, result ); }
private void makeView_Action_List( string modelControllerDir, EntityInfo ei ) { Template template = new Template(); template.InitContent( viewTemplate.GetListView() ); template.Set( "m.Name", ei.Label ); IBlock block = template.GetBlock( "header" ); IBlock block2 = template.GetBlock( "row" ); int columnCount = this.setPropertyList( block, ei, true ); this.setPropertyList( block2, ei, false ); template.Set( "loopBegin", "<!-- BEGIN list -->" ); template.Set( "loopEnd", "<!-- END list -->" ); template.Set( "columnCount", columnCount ); wojilu.IO.File.Write( Path.Combine( modelControllerDir, "List.html" ), template.ToString() ); }
private string getEditCode( EntityInfo ei ) { Template template = new Template(); template.InitContent( controllerTemplate.GetEditAction() ); template.Set( "m.Name", ei.Name ); String eiName = strUtil.GetCamelCase( ei.Name ); template.Set( "domainCamelName", eiName ); String entityProperty = ""; IBlock block = template.GetBlock( "editor" ); foreach (EntityPropertyInfo ep in ei.SavedPropertyList) { if (ep.IsLongText) { block.Set( "Name", "x." + ep.Name ); block.Set( "PName", ep.Name ); block.Next(); } else if (ep.IsEntity) { String epName = getEntityNameSimple( ep ); if (epName != null) { entityProperty += string.Format( tab3 + "dropList( \"x.{0}\", {1}.findAll(), \"{2}=Id\", data.{3}.Id );" + Environment.NewLine, ep.Name, ep.EntityInfo.Name, epName, ep.Name ); } } } template.Set( "entityProperty", entityProperty ); return template.ToString(); }
public void loopThird() { ConsoleTitleUtil.ShowTestTitle( "loopThird" ); string looppage = @" <table> <!-- BEGIN newphotos --> <tr><td>#{Title}</td><td>#{CreateTime}</td></tr> <tr><td colspan=2><!-- BEGIN item --> #{Name} <!-- BEGIN suitem --> #{SubName}<br/><!-- END suitem --> <!-- END item --></td></tr> <!-- END newphotos --> </table> "; Template t = new Template(); t.InitContent( looppage ); IBlock block = t.GetBlock( "newphotos" ); for( int i=0;i<3;i++ ) { block.Set( "Title", "mytitle" + i ); block.Set( "CreateTime", "190"+i ); IBlock block2 = block.GetBlock( "item" ); for( int k=0;k<3;k++ ) { block2.Set( "Name", "nameis"+k); IBlock subblock = block2.GetBlock( "suitem" ); for( int j=0;j<3;j++ ) { subblock.Set( "SubName", "xxsub"+j ); subblock.Next(); } block2.Next(); } block.Next(); } Console.WriteLine( t ); }
private void makeOneController( EntityInfo ei ) { String[] arrTypeItem = ei.FullName.Split( '.' ); String domainNamespace = strUtil.TrimEnd( ei.FullName, "." + arrTypeItem[arrTypeItem.Length - 1] ); string codeList = this.getListCode( ei ); string codeAdd = this.getAddCode( ei ); string codeCreate = this.getCreateCode( ei ); string codeEdit = this.getEditCode( ei ); string codeUpdate = this.getUpdateCode( ei ); string codeDel = this.getDeleteCode( ei ); Template template = new Template(); template.InitContent( CrudActionTemplate.GetController() ); template.Set( "domainNamespace", domainNamespace ); template.Set( "namespace", this.namespaceName ); template.Set( "controllerName", ei.Name ); template.Set( "domainCamelName", strUtil.GetCamelCase( ei.Name ) ); IBlock setList = template.GetBlock( "setList" ); foreach (EntityPropertyInfo ep in ei.SavedPropertyList) { setList.Set( "propertyName", ep.Name ); if (ep.IsLongText) { if (rft.GetAttribute( ep.Property, typeof( HtmlTextAttribute ) ) == null) { setList.Set( "propertyValue", "strUtil.CutString( data." + ep.Name + ", 30 )" ); } else { setList.Set( "propertyValue", "strUtil.ParseHtml( data." + ep.Name + ", 50 )" ); } } else if (ep.IsEntity) { String entityName = getEntityName( ep ); setList.Set( "propertyValue", "data." + entityName ); } else { setList.Set( "propertyValue", "data." + ep.Name ); } setList.Next(); } template.Set( "listCode", codeList ); template.Set( "addCode", codeAdd ); template.Set( "createCode", codeCreate ); template.Set( "editCode", codeEdit ); template.Set( "updateCode", codeUpdate ); template.Set( "deleteCode", codeDel ); wojilu.IO.File.Write( Path.Combine( this.controllerPath, string.Format( "{0}Controller.cs", ei.Name ) ), template.ToString() ); }
//---------------------------layout------------------------------------------------ private void makeLayoutController() { Template template = new Template(); template.InitContent( controllerTemplate.GetLayoutController() ); IBlock block = template.GetBlock( "list" ); foreach (KeyValuePair<String, EntityInfo> kv in MappingClass.Instance.ClassList) { EntityInfo ei = kv.Value; String lmName = strUtil.GetCamelCase( ei.Name ); block.Set( "mName", ei.Name ); block.Set( "lmName", lmName ); block.Next(); } wojilu.IO.File.Write( Path.Combine( this.controllerPath, "LayoutController.cs" ), template.ToString() ); }
private string getAddCode( EntityInfo ei ) { Template template = new Template(); template.InitContent( CrudActionTemplate.GetAddAction() ); IBlock block = template.GetBlock( "editor" ); String eiName = strUtil.GetCamelCase( ei.Name ); String entityProperty = ""; foreach (EntityPropertyInfo ep in ei.SavedPropertyList) { if (ep.IsLongText) { block.Set( "Name", eiName + "." + ep.Name ); block.Next(); } else if (ep.IsEntity) { String epName = getEntityNameSimple( ep ); if (epName != null) { entityProperty += string.Format( tab3 + "dropList( \"{0}.{1}\", {2}.findAll(), \"{3}=Id\", null );" + Environment.NewLine, eiName, ep.Name, ep.EntityInfo.Name, epName ); } } } template.Set( "entityProperty", entityProperty ); return template.ToString(); }