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 testSetVarEmpty() { string html = "<div>#{title}<br/>#{body}(时间:#{created})</div>"; wojilu.Web.ITemplate tpl = new Template().InitContent( html ); tpl.Set( "title", "我是标题" ); tpl.Set( "body", null ); tpl.Set( "created", string.Empty ); string result = tpl.ToString(); Assert.AreEqual( "<div>我是标题<br/>(时间:)</div>", result ); }
public void testSetVarSimple() { string html = "<div>#{title}</div>"; wojilu.Web.ITemplate tpl = new Template().InitContent( html ); tpl.Set( "title", "我是标题" ); string result = tpl.ToString(); Assert.AreEqual( "<div>我是标题</div>", result ); }
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( controllerTemplate.GetController() ); template.Set( "domainNamespace", domainNamespace ); template.Set( "namespace", this.namespaceName ); template.Set( "controllerName", ei.Name ); template.Set( "domainCamelName", strUtil.GetCamelCase( ei.Name ) ); 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() ); }
public void testSetVar() { string html = "<div>#{title}<br/>#{body}#{created}</div>"; wojilu.Web.ITemplate tpl = new Template().InitContent( html ); tpl.Set( "title", "我是标题" ); tpl.Set( "body", "我是内容" ); tpl.Set( "created", "2008-6-4" ); string result = tpl.ToString(); Assert.AreEqual( "<div>我是标题<br/>我是内容2008-6-4</div>", 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 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(); }
private string getListCode( EntityInfo ei ) { Template template = new Template(); template.InitContent( controllerTemplate.GetListAction() ); template.Set( "model.Name", ei.Name ); template.Set( "model.LName", strUtil.GetCamelCase( ei.Name ) ); return template.ToString(); }
private void populateTemplate( EntityInfo ei, Template t ) { StringBuilder reqBuilder = new StringBuilder(); StringBuilder validBuilder = new StringBuilder(); StringBuilder setBuilder = new StringBuilder(); foreach (EntityPropertyInfo info in ei.SavedPropertyList) { if (info.Name.Equals( "Id" )) { continue; } if (info.Type == typeof( string )) { reqBuilder.Append( this.tab3 ); reqBuilder.AppendFormat( "string {0} = ctx.Post(\"{1}\");", strUtil.GetCamelCase( info.Name ), info.Name ); reqBuilder.Append( Environment.NewLine ); validBuilder.Append( this.tab3 ); validBuilder.AppendFormat( "if ( strUtil.IsNullOrEmpty( {0} ) )", strUtil.GetCamelCase( info.Name ) ); validBuilder.Append( Environment.NewLine ); validBuilder.Append( this.tab4 ); validBuilder.AppendFormat( "errors.Add( \"请填写{0}\" );", info.Label ); validBuilder.Append( Environment.NewLine ); setBuilder.Append( this.tab3 ); setBuilder.AppendFormat( "data.{0} = {1};", info.Name, strUtil.GetCamelCase( info.Name ) ); setBuilder.Append( Environment.NewLine ); } else if (info.Type == typeof( int )) { reqBuilder.Append( this.tab3 ); reqBuilder.AppendFormat( "int {0} = ctx.PostInt(\"{1}\");", strUtil.GetCamelCase( info.Name ), info.Name ); reqBuilder.Append( Environment.NewLine ); setBuilder.Append( this.tab3 ); setBuilder.AppendFormat( "data.{0} = {1};", info.Name, strUtil.GetCamelCase( info.Name ) ); setBuilder.Append( Environment.NewLine ); } else if (info.Type == typeof( DateTime )) { reqBuilder.Append( this.tab3 ); reqBuilder.AppendFormat( "DateTime {0} = ctx.PostTime(\"{1}\");", strUtil.GetCamelCase( info.Name ), info.Name ); reqBuilder.Append( Environment.NewLine ); setBuilder.Append( this.tab3 ); setBuilder.AppendFormat( "data.{0} = {1};", info.Name, strUtil.GetCamelCase( info.Name ) ); setBuilder.Append( Environment.NewLine ); } } t.Set( "setPostValue", reqBuilder.ToString() ); t.Set( "validPostValue", validBuilder.ToString() ); t.Set( "setValue", setBuilder.ToString() ); t.Set( "m.Name", ei.Name ); }
private string getDeleteCode( EntityInfo ei ) { Template template = new Template(); template.InitContent( controllerTemplate.GetDeleteAction() ); template.Set( "m.Name", ei.Name ); return 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 single() { ConsoleTitleUtil.ShowTestTitle( "single" ); string a = @" <h4> #{Title}</h4> <b>#{CreateTime}</b><br /> "; SpeedUtil.Start(); Template t = new Template(); t.InitContent( a ); t.Set( "Title", "一百航的诗篇" ); t.Set( "CreateTime", "今年的时间 " + DateTime.Now ); Console.WriteLine( t ); SpeedUtil.Stop(); }
public void single() { ConsoleTitleUtil.ShowTestTitle( "single" ); string a = @" <h4> {#Title#}</h4> <b>{#CreateTime#}</b><br /> "; SpeedUtil.Start(); Template t = new Template(); t.InitContent( a ); t.Set( "Title", "һ�ٺ���ʫƪ" ); t.Set( "CreateTime", "�����ʱ�� " + DateTime.Now ); Console.WriteLine( t ); SpeedUtil.Stop(); }
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() ); }
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(); }
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(); }