コード例 #1
0
        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 );
        }
コード例 #2
0
        public void testBlockExist()
        {
            string html = "<div>#{title}<br/>#{body}<!-- BEGIN mylist --><p>kkkk</p><!-- END mylist --></div>";

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

            Assert.IsFalse( tpl.HasBlock( "list" ) );
            Assert.IsTrue( tpl.HasBlock( "mylist" ) );
        }
コード例 #3
0
 public void testImgPath()
 {
     string html = "<div><img src=\"~img/doc.gif\" /></div>";
     wojilu.Web.ITemplate tpl = new Template().InitContent( html );
     string result = tpl.ToString();
     Console.WriteLine( result );
     //~img/
     //=>
     //#{path.img}
     Assert.AreEqual( "<div><img src=\"#{path.img}doc.gif\" /></div>", result );
 }
コード例 #4
0
 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();
     }
 }
コード例 #5
0
        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() );
        }
コード例 #6
0
        public void testErrorPath()
        {
            // 只支持26个英文字母(包括大写)

            // 不支持数字
            string html = "<div><img src=\"~xpath1/doc.gif\" /></div>";
            wojilu.Web.ITemplate tpl = new Template().InitContent( html );
            string result = tpl.ToString();
            Console.WriteLine( result );

            Assert.AreEqual( html, result );

            // 不支持特殊符号,比如<
            html = "<div>~</div>";
            tpl = new Template().InitContent( html );
            result = tpl.ToString();
            Console.WriteLine( result );
            Assert.AreEqual( html, result );
        }
コード例 #7
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 );
        }
コード例 #8
0
        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 );
        }
コード例 #9
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 );
        }
コード例 #10
0
        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 );
        }
コード例 #11
0
 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 );
 }
コード例 #12
0
 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 );
 }
コード例 #13
0
 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 );
 }
コード例 #14
0
 private string getUpdateCode( EntityInfo ei ) {
     Template t = new Template();
     t.InitContent( controllerTemplate.GetUpdateAction() );
     this.populateTemplate( ei, t );
     return t.ToString();
 }
コード例 #15
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 );
        }
コード例 #16
0
        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 );
        }
コード例 #17
0
 public void testStaticPathSlash()
 {
     string html = "<div><img src=\"~/static/doc.gif\" /></div>";
     wojilu.Web.ITemplate tpl = new Template().InitContent( html );
     string result = tpl.ToString();
     Console.WriteLine( result );
     //~/static/
     //=>
     //#{patha.static}
     Assert.AreEqual( "<div><img src=\"#{patha.static}doc.gif\" /></div>", result );
 }
コード例 #18
0
        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() );
        }
コード例 #19
0
        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();
        }
コード例 #20
0
        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() );
        }
コード例 #21
0
        //---------------------------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() );
        }
コード例 #22
0
        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();
        }
コード例 #23
0
        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() );
        }
コード例 #24
0
        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 );
        }
コード例 #25
0
        public void testRoot()
        {
            //~/
            //=>
            //#{path}
            //=>
            //sys.Path.Root

            // 根目录
            string html = "<div><img src=\"~/doc.gif\" /></div>";
            wojilu.Web.ITemplate tpl = new Template().InitContent( html );
            string result = tpl.ToString();
            Console.WriteLine( result );

            Assert.AreEqual( "<div><img src=\"#{path}doc.gif\" /></div>", result );

            // 纯粹的根目录
            html = "<div><a href=\"~/\">site</a></div>";
            tpl = new Template().InitContent( html );
            result = tpl.ToString();
            Console.WriteLine( result );
            Assert.AreEqual( "<div><a href=\"#{path}\">site</a></div>", result );
        }
コード例 #26
0
 private string getDeleteCode( EntityInfo ei ) {
     Template template = new Template();
     template.InitContent( controllerTemplate.GetDeleteAction() );
     template.Set( "m.Name", ei.Name );
     return template.ToString();
 }
コード例 #27
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 );
 }
コード例 #28
0
 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();
 }
コード例 #29
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 );
        }
コード例 #30
0
        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();
        }