コード例 #1
0
        protected StringTemplateGroup GetTemplateManager(Controller controller)
        {
            if ((controller.AreaName == null) || (controller.AreaName.Trim().Length == 0))
            {
                return(templateGroup);
            }

            StringTemplateGroup group = (StringTemplateGroup)area2templateManager[controller.AreaName];

            if (group == null)
            {
                group = new BasicStringTemplateGroup(
                    ConfigConstants.STGROUP_NAME_PREFIX + "_area_" + controller.AreaName,
                    (StringTemplateLoader)null,
                    config.TemplateLexerType);
                group.SuperGroup = templateGroup;

                if (config.TemplateWriterTypeName != null)
                {
                    group.SetTemplateWriterType(config.TemplateWriterType);
                }

                IEnumerator renderersEnumerator = config.GetAttributeRenderersForArea(controller.AreaName);
                while (renderersEnumerator.MoveNext())
                {
                    RendererInfo rendererInfo = (RendererInfo)renderersEnumerator.Current;
                    group.RegisterAttributeRenderer(rendererInfo.AttributeType, rendererInfo.GetRendererInstance());
                }
                area2templateManager[controller.AreaName] = group;
            }
            return(group);
        }
コード例 #2
0
        /// <summary>
        /// Retrieves the ST layout template for the specified controller.
        /// </summary>
        protected StringTemplate GetLayoutTemplate(Controller controller)
        {
            string layoutName   = controller.LayoutName;
            string templateName = string.Format("{0}/{1}", ConfigConstants.LAYOUTS_DIR, layoutName.Replace('\\', '/'));
            StringTemplateGroup templateManager = GetTemplateManager(controller);
            StringTemplate      st = templateManager.GetInstanceOf(templateName);

            return(st);
        }
コード例 #3
0
 public void SetUp()
 {
     group = new StringTemplateGroup(new System.IO.StringReader(gString));
     /*
     // warm up the on-the-fly compiler
     for (int i=1; i<=2*N; i++) {
     testBaselineLiteral();
     testSingleLocalAttributeReference();
     testApplyTemplateToList();
     }
     */
 }
コード例 #4
0
        /// <summary>
        /// Retrieves the ST template for specified controller and template name.
        /// </summary>
        protected StringTemplate GetViewTemplate(Controller controller, string viewName)
        {
            StringTemplate      st = null;
            StringTemplateGroup templateManager = GetTemplateManager(controller);

            if (viewName.IndexOfAny(ConfigConstants.PATH_SEPARATOR_CHARS) == -1)
            {
                // try locations in order
                bool   controllerHasArea = ((controller.AreaName != null) && (controller.AreaName.Trim().Length > 0));
                string templateName;
                // <area>/<controller>/<view>
                if (controllerHasArea)
                {
                    templateName = string.Format("{0}/{1}/{2}", controller.AreaName, controller.Name, viewName);
                    st           = templateManager.GetInstanceOf(templateName);
                }
                if (st == null)
                {
                    // <area>/shared/<view>
                    if (controllerHasArea)
                    {
                        templateName = string.Format("{0}/{1}/{2}", controller.AreaName, ConfigConstants.SHARED_DIR, viewName);
                        st           = templateManager.GetInstanceOf(templateName);
                    }
                    if (st == null)
                    {
                        // <controller>/<view>
                        templateName = string.Format("{0}/{1}", controller.Name, viewName);
                        st           = templateManager.GetInstanceOf(templateName);
                        if (st == null)
                        {
                            // shared/<view>
                            templateName = string.Format("{0}/{1}", ConfigConstants.SHARED_DIR, viewName);
                            st           = templateManager.GetInstanceOf(templateName);
                        }
                    }
                }
            }

            if (st == null)
            {
                st = templateManager.GetInstanceOf(viewName.Replace('\\', '/'));
            }

            if (st == null)
            {
                throw new Castle.MonoRail.Framework.RailsException("Could not find the view: " + viewName);
            }

            return(st);
        }
コード例 #5
0
        public static void Main(string[] args)
        {
            StringTemplateGroup group = new StringTemplateGroup("dummy");
            StringTemplate bold = group.DefineTemplate("bold", "<b>$attr$</b>");
            StringTemplate banner = group.DefineTemplate("banner", "the banner");
            StringTemplate st = new StringTemplate(group,
                "<html>\n" +
                "$banner(a=b)$" +
                "<p><b>$name$:$email$</b>" +
                "$if(member)$<i>$fontTag$member</font></i>$endif$");
            st.SetAttribute("name", "Terence");
            st.SetAttribute("name", "Tom");
            st.SetAttribute("email", "*****@*****.**");
            st.SetAttribute("templateAttr", bold);

            StringTemplateTreeView frame =
                new StringTemplateTreeView("StringTemplateTreeView Example", st);
            Application.Run(frame);
        }
コード例 #6
0
        public void Initialize()
        {
            config = STViewEngineConfiguration.GetConfig(ConfigConstants.ELEMENT_stview_sectionname);

            StringTemplateGroup componentGroup = new ViewComponentStringTemplateGroup(
                ConfigConstants.STGROUP_NAME_PREFIX + "_components",
                config.TemplateLexerType);

            StringTemplateGroup helpersSTGroup = new BasicStringTemplateGroup(
                ConfigConstants.STGROUP_NAME_PREFIX + "_helpersST",
                new EmbeddedResourceTemplateLoader(this.GetType().Assembly, ConfigConstants.HELPER_RESOURCE_NAMESPACE, false),
                config.TemplateLexerType);

            helpersSTGroup.SuperGroup = componentGroup;

            templateGroup = new BasicStringTemplateGroup(
                ConfigConstants.STGROUP_NAME_PREFIX,
                new FileSystemTemplateLoader(ViewSourceLoader.ViewRootDir, false),
                config.TemplateLexerType);
            templateGroup.SuperGroup = helpersSTGroup;

            if (config.TemplateWriterTypeName != null)
            {
                componentGroup.SetTemplateWriterType(config.TemplateWriterType);
                helpersSTGroup.SetTemplateWriterType(config.TemplateWriterType);
                templateGroup.SetTemplateWriterType(config.TemplateWriterType);
            }

            IEnumerator globalRenderersEnumerator = config.GetGlobalAttributeRenderers();

            while (globalRenderersEnumerator.MoveNext())
            {
                RendererInfo renderInfo = (RendererInfo)globalRenderersEnumerator.Current;
                componentGroup.RegisterAttributeRenderer(renderInfo.AttributeType, renderInfo.GetRendererInstance());
                helpersSTGroup.RegisterAttributeRenderer(renderInfo.AttributeType, renderInfo.GetRendererInstance());
                templateGroup.RegisterAttributeRenderer(renderInfo.AttributeType, renderInfo.GetRendererInstance());
            }
        }
コード例 #7
0
ファイル: Test.cs プロジェクト: david-mcneil/stringtemplate
        public static void Main(string[] args)
        {
            // choose a skin or site "look" to present
            string skin = "blue";

            // allow overrides for language and skin from arguments on command line
            string language = null;
            if ( args.Length > 0 )
            {
                language = args[0];
            }
            if ( args.Length > 1)
            {
                if ( "blue".Equals(args[1]) || "red".Equals(args[1]) )
                    skin = args[1];
            }

            TryToSetRequestedLocale(language);

            // load strings from a properties files like en.strings
            ResourceManager resMgr = new ResourceManager("ST.Examples.i18n.Content.Strings", typeof(ResourceWrapper).Assembly);
            ResourceWrapper strings = new ResourceWrapper(resMgr);

            // get a template group rooted at appropriate skin
            string absoluteSkinRootDirectoryName = Path.Combine(new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).Parent.FullName, skin);
            StringTemplateGroup templates = new StringTemplateGroup("test", absoluteSkinRootDirectoryName);

            // generate some pages; every page gets strings table to pull strings from
            StringTemplate page1ST = templates.GetInstanceOf("page1");
            page1ST.SetAttribute("strings", strings);
            StringTemplate page2ST = templates.GetInstanceOf("page2");
            page2ST.SetAttribute("strings", strings);

            // render to text
            Console.Out.WriteLine(page1ST);
            Console.Out.WriteLine(page2ST);
        }
コード例 #8
0
		public void Initialize()
		{
			config = STViewEngineConfiguration.GetConfig(ConfigConstants.ELEMENT_stview_sectionname);

			StringTemplateGroup componentGroup = new ViewComponentStringTemplateGroup(
				ConfigConstants.STGROUP_NAME_PREFIX + "_components", 
				config.TemplateLexerType);

			StringTemplateGroup helpersSTGroup = new BasicStringTemplateGroup(
				ConfigConstants.STGROUP_NAME_PREFIX + "_helpersST", 
				new EmbeddedResourceTemplateLoader(this.GetType().Assembly, ConfigConstants.HELPER_RESOURCE_NAMESPACE, false),
				config.TemplateLexerType);
			helpersSTGroup.SuperGroup = componentGroup;

			templateGroup = new BasicStringTemplateGroup(
				ConfigConstants.STGROUP_NAME_PREFIX, 
				new FileSystemTemplateLoader(ViewSourceLoader.ViewRootDir, false),
				config.TemplateLexerType);
			templateGroup.SuperGroup = helpersSTGroup;

			if (config.TemplateWriterTypeName != null)
			{
				componentGroup.SetTemplateWriterType(config.TemplateWriterType);
				helpersSTGroup.SetTemplateWriterType(config.TemplateWriterType);
				templateGroup.SetTemplateWriterType(config.TemplateWriterType);
			}

			IEnumerator globalRenderersEnumerator = config.GetGlobalAttributeRenderers();
			while (globalRenderersEnumerator.MoveNext())
			{
				RendererInfo renderInfo = (RendererInfo)globalRenderersEnumerator.Current;
				componentGroup.RegisterAttributeRenderer(renderInfo.AttributeType, renderInfo.GetRendererInstance());
				helpersSTGroup.RegisterAttributeRenderer(renderInfo.AttributeType, renderInfo.GetRendererInstance());
				templateGroup.RegisterAttributeRenderer(renderInfo.AttributeType, renderInfo.GetRendererInstance());
			}
		}
コード例 #9
0
            public virtual void TestMultipleRefsToIEnumeratorGivesEmptyOutput()
            {
            string templates = ""
                + "group TestIEnum ;" + NL
                + "Action(Arg) ::=<<" + NL
                + "Ref 1: " + NL
                + "  $Arg:{X=$it$ # }$" + NL
                + "Ref 2: " + NL
                + "  $Arg:{X=$it$ # }$" + NL
                + ">>"
                ;

            StringTemplateGroup group = new StringTemplateGroup(
                new StringReader(templates),
                typeof(DefaultTemplateLexer));
            StringTemplate actionST = group.GetInstanceOf("Action");
            int[] myIntArray = new int[5] { 1, 2, 3, 4, 5 };
            actionST.SetAttribute("Arg", myIntArray.GetEnumerator());
            string expected = ""
                + "Ref 1: " + NL
                + "  X=1 # X=2 # X=3 # X=4 # X=5 # " + NL
                + "Ref 2: " + NL
                + "  X=1 # X=2 # X=3 # X=4 # X=5 # " + NL
                ;
            string actual = actionST.ToString();
            Assert.AreEqual(expected, actual,
                "IEnumerators have side-effects. Can't just Reset() and reuse because it may be \"deliberately positioned\".");
            }
コード例 #10
0
            public virtual void testEmbeddedMultiLineIF()
            {
            StringTemplateGroup group = new StringTemplateGroup("test");
            StringTemplate main = new StringTemplate(group, "$sub$");
            StringTemplate sub = new StringTemplate(
                group, ""
                + "begin" + NL
                + "$if(foo)$" + NL
                + "$foo$" + NL
                + "$else$" + NL
                + "blort" + NL
                + "$endif$" + NL
                );
            sub.SetAttribute("foo", "stuff");
            main.SetAttribute("sub", sub);
            string expecting = "begin" + NL
                + "stuff";
            Assert.AreEqual(expecting, main.ToString());

            main = new StringTemplate(group, "$sub$");
            sub = sub.GetInstanceOf();
            main.SetAttribute("sub", sub);
            expecting = "begin" + NL
                + "blort";
            Assert.AreEqual(expecting, main.ToString());
            }
コード例 #11
0
 public void testImplicitRegionRedefError()
 {
     // cannot define an implicitly-defined template more than once
     string templates = ""
         + "group test;" + NL
         + "a() ::= \"X<@r()>Y\"" + NL
         + "@a.r() ::= \"foo\"" + NL
         + "@a.r() ::= \"bar\"" + NL;
     IStringTemplateErrorListener errors = new ErrorBuffer();
     StringTemplateGroup group =
         new StringTemplateGroup(new StringReader(templates), errors);
     StringTemplate st = group.GetInstanceOf("a");
     st.ToString();
     string result = errors.ToString();
     string expecting = "group test line 4: redefinition of template region: @a.r";
     Assert.AreEqual(expecting, result);
 }
コード例 #12
0
 public virtual void testIFTemplate()
 {
     StringTemplateGroup group = new StringTemplateGroup("dummy", ".", typeof(AngleBracketTemplateLexer));
     StringTemplate t = new StringTemplate(group, "SELECT <column> FROM PERSON " + "<if(cond)>WHERE ID=<id><endif>;");
     t.SetAttribute("column", "name");
     t.SetAttribute("cond", "true");
     t.SetAttribute("id", "231");
     Assert.AreEqual(t.ToString(), "SELECT name FROM PERSON WHERE ID=231;");
 }
コード例 #13
0
 public virtual void testIFCondWithParensDollarDelimsTemplate()
 {
     StringTemplateGroup group = new StringTemplateGroup("dummy", ".");
     StringTemplate t = new StringTemplate(group, "$if(map.(type))$$type$ $prop$=$map.(type)$;$endif$");
     Hashtable map = new Hashtable();
     map["int"] = "0";
     t.SetAttribute("map", map);
     t.SetAttribute("prop", "x");
     t.SetAttribute("type", "int");
     Assert.AreEqual("int x=0;", t.ToString());
 }
コード例 #14
0
        public virtual void testGroupSatisfiesSingleInterface()
        {
            // this also tests the group loader
            IStringTemplateErrorListener errors = new ErrorBuffer();
            StringTemplateGroup.RegisterGroupLoader(new CommonGroupLoader(errors, TEMPDIR));
            string groupIStr = ""
                + "interface testI;" + NL
                + "t();" + NL
                + "bold(item);" + NL
                + "optional duh(a,b,c);" + NL;
            WriteFile(TEMPDIR, "testI.sti", groupIStr);

            string templates = ""
                + "group testG implements testI;" + NL
                + "t() ::= <<foo>>" + NL
                + "bold(item) ::= <<foo>>" + NL
                + "duh(a,b,c) ::= <<foo>>" + NL;

            WriteFile(TEMPDIR, "testG.stg", templates);

            file1 = new StreamReader(Path.Combine(TEMPDIR, "testG.stg"));
            StringTemplateGroup group = new StringTemplateGroup(file1, errors);

            string expecting = ""; // should be no errors
            Assert.AreEqual(expecting, errors.ToString());
        }
コード例 #15
0
        public virtual void testGroupExtendsSuperGroup()
        {
            // this also tests the group loader
            IStringTemplateErrorListener errors = new ErrorBuffer();
            StringTemplateGroup.RegisterGroupLoader(
                new CommonGroupLoader(errors, TEMPDIR)
                );
            string superGroup = ""
                + "group superG;" + NL
                + "bold(item) ::= <<*<item>*>>;\n" + NL;
            WriteFile(TEMPDIR, "superG.stg", superGroup);

            string templates = ""
                + "group testG : superG;" + NL
                + "main(x) ::= <<$bold(x)$>>" + NL;

            WriteFile(TEMPDIR, "testG.stg", templates);

            file1 = new StreamReader(Path.Combine(TEMPDIR, "testG.stg"));
            StringTemplateGroup group = new StringTemplateGroup(file1, typeof(DefaultTemplateLexer), errors);
            StringTemplate st = group.GetInstanceOf("main");
            st.SetAttribute("x", "foo");

            string expecting = "*foo*";
            Assert.AreEqual(expecting, st.ToString());
        }
コード例 #16
0
 public virtual void testFormalArgumentAssignment()
 {
     string templates = ""
         + "group test;" + NL
         + @"page() ::= <<$body(font=""Times"")$>>" + NL
         + @"body(font) ::= ""<font face=$font$>my body</font>""" + NL;
     StringTemplateGroup group = new StringTemplateGroup(new StringReader(templates), typeof(DefaultTemplateLexer));
     StringTemplate t = group.GetInstanceOf("page");
     string expecting = "<font face=Times>my body</font>";
     Assert.AreEqual(expecting, t.ToString());
 }
コード例 #17
0
 public virtual void testExprInParens()
 {
     // specify a template to apply to an attribute
     // Use a template group so we can specify the start/stop chars
     StringTemplateGroup group = new StringTemplateGroup("dummy", ".");
     StringTemplate bold = group.DefineTemplate("bold", "<b>$it$</b>");
     StringTemplate duh = new StringTemplate(group, @"$(""blort: ""+(list)):bold()$");
     duh.SetAttribute("list", "a");
     duh.SetAttribute("list", "b");
     duh.SetAttribute("list", "c");
     // System.out.println(duh);
     string expecting = "<b>blort: abc</b>";
     Assert.AreEqual(expecting, duh.ToString());
 }
コード例 #18
0
            public virtual void TestIfTestingDoesNotAdvanceIEnumeratorPosition2()
            {
            string templates = ""
                + "group TestIEnum ;" + NL
                + "ActionWithIfTest(Arg) ::=<<" + NL
                + "$if( Arg )$" + NL
                + "$Arg:{X=$it$ # }$" + NL
                + "$endif$" + NL
                + ">>" + NL
                + "ActionWithoutIfTest(Arg) ::=<<" + NL
                + "$Arg:{X=$it$ # }$" + NL
                + ">>"
                ;

            StringTemplateGroup group = new StringTemplateGroup(
                new StringReader(templates),
                typeof(DefaultTemplateLexer));
            StringTemplate actionWithIfTestST = group.GetInstanceOf("ActionWithIfTest");
            StringTemplate actionWithoutIfTestST = group.GetInstanceOf("ActionWithoutIfTest");
            int[] myIntArray = new int[5] { 1, 2, 3, 4, 5 };
            actionWithIfTestST.SetAttribute("Arg", myIntArray.GetEnumerator());
            actionWithoutIfTestST.SetAttribute("Arg", myIntArray.GetEnumerator());
            string resultWithIfTestST = actionWithIfTestST.ToString();
            string resultWithoutIfTestST = actionWithoutIfTestST.ToString();
            Assert.AreEqual(resultWithIfTestST, resultWithoutIfTestST);
            }
コード例 #19
0
 public virtual void testFindTemplateInCLASSPATH_Nope_JustRelativeToAssemblyLocation()
 {
     // Look for templates in CLASSPATH as resources
     StringTemplateGroup mgroup = new StringTemplateGroup("method stuff", typeof(AngleBracketTemplateLexer));
     StringTemplate m = mgroup.GetInstanceOf("tests/method");
     // "method.st" references body() so "body.st" will be loaded too
     m.SetAttribute("visibility", "public");
     m.SetAttribute("name", "foobar");
     m.SetAttribute("returnType", "void");
     m.SetAttribute("statements", "i=1;"); // body inherits these from method
     m.SetAttribute("statements", "x=i;");
     string expecting = "public void foobar() {" + NL
         + "\t// start of a body" + NL
         + "\ti=1;" + NL + "\tx=i;" + NL
         + "\t// end of a body" + NL
         + "}";
     //.Replace(Environment.NewLine, "\n") below mitigates against failure due to line-ending differences
     Assert.AreEqual(expecting, m.ToString().Replace(Environment.NewLine, "\n"));
 }
コード例 #20
0
            public virtual void TestFirstThenRestTwiceOnIEnumeratorResultsInNoOutputFor2ndRef()
            {
            string templates = ""
                + "group TestIEnum ;" + NL
                + "FirstThenRest(Arg) ::=<<" + NL
                + "Iteration 1: " + NL
                + "FIRST:  $first(Arg):{X=$it$ # }$" + NL
                + "REST :  $rest(Arg):{X=$it$ # }$" + NL
                + "-------------" + NL
                + "Iteration 2: " + NL
                + "FIRST:  $first(Arg):{X=$it$ # }$" + NL
                + "REST :  $rest(Arg):{X=$it$ # }$" + NL
                + "-------------" + NL
                + ">>"
                ;

            StringTemplateGroup group = new StringTemplateGroup(
                new StringReader(templates),
                typeof(DefaultTemplateLexer));
            StringTemplate actionST = group.GetInstanceOf("FirstThenRest");
            int[] myIntArray = new int[5] { 1, 2, 3, 4, 5 };
            actionST.SetAttribute("Arg", myIntArray.GetEnumerator());
            string expected = ""
                + "Iteration 1: " + NL
                + "FIRST:  X=1 # " + NL
                + "REST :  X=2 # X=3 # X=4 # X=5 # " + NL
                + "-------------" + NL
                + "Iteration 2: " + NL
                + "FIRST:  X=1 # " + NL
                + "REST :  X=2 # X=3 # X=4 # X=5 # " + NL
                + "-------------" + NL
                ;
            string actual = actionST.ToString();
            Assert.AreEqual(expected, actual,
                "IEnumerators have side-effects. Can't just Reset() and reuse because it may be \"deliberately positioned\".");
            }
コード例 #21
0
 public virtual void testFormalArgumentAssignmentInApply()
 {
     string templates = ""
         + "group test;" + NL
         + @"page(name) ::= <<$name:bold(font=""Times"")$>>" + NL
         + @"bold(font) ::= ""<font face=$font$><b>$it$</b></font>""" + NL;
     StringTemplateGroup group = new StringTemplateGroup(new StringReader(templates), typeof(DefaultTemplateLexer));
     StringTemplate t = group.GetInstanceOf("page");
     t.SetAttribute("name", "Ter");
     string expecting = "<font face=Times><b>Ter</b></font>";
     Assert.AreEqual(expecting, t.ToString());
 }
コード例 #22
0
 public void testComplicatedInheritance()
 {
     // in super: decls invokes labels
     // in sub:   overridden decls which calls super.decls
     //           overridden labels
     // Bug: didn't see the overridden labels.  In other words,
     // the overridden decls called super which called labels, but
     // didn't get the subgroup overridden labels--it calls the
     // one in the superclass.  Ouput was "DL" not "DSL"; didn't
     // invoke sub's labels().
     string basetemplates = ""
         + "group base;" + NL
         + "decls() ::= \"D<labels()>\"" + NL
         + "labels() ::= \"L\"" + NL
         ;
     StringTemplateGroup @base = new StringTemplateGroup(
         new StringReader(basetemplates),
         typeof(AngleBracketTemplateLexer));
     string subtemplates = ""
         + "group sub;" + NL
         + "decls() ::= \"<super.decls()>\"" + NL
         + "labels() ::= \"SL\"" + NL
         ;
     StringTemplateGroup sub = new StringTemplateGroup(
         new StringReader(subtemplates),
         typeof(AngleBracketTemplateLexer));
     sub.SuperGroup = @base;
     StringTemplate st = sub.GetInstanceOf("decls");
     string expecting = "DSL";
     string result = st.ToString();
     Assert.AreEqual(expecting, result);
 }
コード例 #23
0
        public virtual void testGroupFileFormat()
        {
            string templates = ""
                + "group test;" + NL
                + @"t() ::= ""literal template""" + NL
                + @"bold(item) ::= ""<b>$item$</b>""" + NL
                + "duh() ::= <<" + NL
                + "xx" + NL
                + ">>" + NL;
            StringTemplateGroup group = new StringTemplateGroup(new StringReader(templates), typeof(DefaultTemplateLexer));

            string expecting = ""
                + "group test;" + NL
                + "bold(item) ::= <<<b>$item$</b>>>" + NL
                + "duh() ::= <<xx>>" + NL
                + "t() ::= <<literal template>>" + NL;

            Assert.AreEqual(expecting, group.ToString());

            StringTemplate a = group.GetInstanceOf("t");
            expecting = "literal template";
            Assert.AreEqual(expecting, a.ToString());

            StringTemplate b = group.GetInstanceOf("bold");
            b.SetAttribute("item", "dork");
            expecting = "<b>dork</b>";
            Assert.AreEqual(expecting, b.ToString());
        }
コード例 #24
0
 public virtual void testComplicatedSeparatorExpr()
 {
     StringTemplateGroup group = new StringTemplateGroup("test");
     StringTemplate bold = group.DefineTemplate("bulletSeparator", "</li>$foo$<li>");
     // make separator a complicated expression with args passed to included template
     StringTemplate t = new StringTemplate(
         group, @"<ul>$name; separator=bulletSeparator(foo="" "")+""&nbsp;""$</ul>"
         );
     t.SetAttribute("name", "Ter");
     t.SetAttribute("name", "Tom");
     t.SetAttribute("name", "Mel");
     //System.out.println(t);
     string expecting = "<ul>Ter</li> <li>&nbsp;Tom</li> <li>&nbsp;Mel</ul>";
     Assert.AreEqual(expecting, t.ToString());
 }
コード例 #25
0
        public virtual void testIFBoolean()
        {
            StringTemplateGroup group = new StringTemplateGroup("dummy", ".");
            StringTemplate t = new StringTemplate(group, "$if(b)$x$endif$ $if(!b)$y$endif$");
            t.SetAttribute("b", (object)true);
            Assert.AreEqual(t.ToString(), "x ");

            t = t.GetInstanceOf();
            t.SetAttribute("b", (object)false);
            Assert.AreEqual(t.ToString(), " y");
        }
コード例 #26
0
 public void testEmbeddedRegionRedefError()
 {
     // cannot define an embedded template within group
     string templates = ""
         + "group test;" + NL
         + "a() ::= \"X<@r>dork<@end>Y\""
         + "@a.r() ::= \"foo\"" + NL;
     IStringTemplateErrorListener errors = new ErrorBuffer();
     StringTemplateGroup group = new StringTemplateGroup(new StringReader(templates), errors);
     StringTemplate st = group.GetInstanceOf("a");
     st.ToString();
     string result = errors.ToString();
     string expecting = "group test line 2: redefinition of template region: @a.r";
     Assert.AreEqual(expecting, result);
 }
コード例 #27
0
 public virtual void testIFCondWithParensTemplate()
 {
     StringTemplateGroup group = new StringTemplateGroup("dummy", ".", typeof(AngleBracketTemplateLexer));
     StringTemplate t = new StringTemplate(group, "<if(map.(type))><type> <prop>=<map.(type)>;<endif>");
     Hashtable map = new Hashtable();
     map["int"] = "0";
     t.SetAttribute("map", map);
     t.SetAttribute("prop", "x");
     t.SetAttribute("type", "int");
     Assert.AreEqual("int x=0;", t.ToString());
 }
コード例 #28
0
 public void testEmbeddedRegionRef()
 {
     string templates = ""
         + "group test;" + NL
         + "a() ::= \"X$@r$blort$@end$Y\"" + NL;
     StringTemplateGroup group =
         new StringTemplateGroup(new StringReader(templates), typeof(DefaultTemplateLexer));
     StringTemplate st = group.GetInstanceOf("a");
     string result = st.ToString();
     string expecting = "XblortY";
     Assert.AreEqual(expecting, result);
 }
コード例 #29
0
        public void testImplicitOverriddenRegionRedefError()
        {
            string templates1 = ""
                + "group super;" + NL
                + "a() ::= \"X<@r()>Y\""
                + "@a.r() ::= \"foo\"" + NL;
            StringTemplateGroup group = new StringTemplateGroup(
                new StringReader(templates1));

            string templates2 = ""
                + "group sub;" + NL
                + "@a.r() ::= \"foo\"" + NL
                + "@a.r() ::= \"bar\"" + NL;
            IStringTemplateErrorListener errors = new ErrorBuffer();
            StringTemplateGroup subGroup = new StringTemplateGroup(
                new StringReader(templates2), errors, group);

            StringTemplate st = subGroup.GetInstanceOf("a");
            string result = errors.ToString();
            string expecting = "group sub line 3: redefinition of template region: @a.r";
            Assert.AreEqual(expecting, result);
        }
コード例 #30
0
 public void testEmbeddedRegionRefWithNewlinesAngleBrackets()
 {
     string templates = ""
         + "group test;" + NL
         + "a() ::= \"X<@r>" + NL
         + "blort" + NL
         + "<@end>" + NL
         + "Y\"" + NL;
     StringTemplateGroup group =
         new StringTemplateGroup(new StringReader(templates));
     StringTemplate st = group.GetInstanceOf("a");
     string result = st.ToString();
     string expecting = "XblortY";
     Assert.AreEqual(expecting, result);
 }
コード例 #31
0
 public virtual void testLiteralStringEscapes()
 {
     StringTemplateGroup group = new StringTemplateGroup("dummy", ".");
     group.DefineTemplate("foo", "$x$ && $it$");
     StringTemplate t = new StringTemplate(group, @"$A:foo(x=""dog\""\"""")$");
     StringTemplate u = new StringTemplate(group, @"$A:foo(x=""dog\""g"")$");
     StringTemplate v = new StringTemplate(group, @"$A:{$it:foo(x=""\{dog\}\"""")$ is cool}$");
     t.SetAttribute("A", "ick");
     u.SetAttribute("A", "ick");
     v.SetAttribute("A", "ick");
     string expecting = @"dog"""" && ick";
     Assert.AreEqual(expecting, t.ToString());
     expecting = @"dog""g && ick";
     Assert.AreEqual(expecting, u.ToString());
     expecting = @"{dog}"" && ick is cool";
     Assert.AreEqual(expecting, v.ToString());
     }
コード例 #32
0
        public void testEscapedTemplateDelimiters()
        {
            string templates = ""
                + "group test;" + NL
                + "t() ::= <<$\"literal\":{a|$a$\\}}$ template\n>>" + NL
                + "bold(item) ::= <<<b>$item$</b\\>>>" + NL
                + "duh() ::= <<" + NL
                + "xx" + NL
                + ">>" + NL;
            StringTemplateGroup group = new StringTemplateGroup(new StringReader(templates), typeof(DefaultTemplateLexer));

            string expecting = ""
                + "group test;" + NL
                + "bold(item) ::= <<<b>$item$</b>>>" + NL
                + "duh() ::= <<xx>>" + NL
                + "t() ::= <<$\"literal\":{a|$a$\\}}$ template>>" + NL;
            Assert.AreEqual(expecting, group.ToString());

            StringTemplate b = group.GetInstanceOf("bold");
            b.SetAttribute("item", "dork");
            expecting = "<b>dork</b>";
            Assert.AreEqual(expecting, b.ToString());

            StringTemplate a = group.GetInstanceOf("t");
            expecting = "literal} template";
            Assert.AreEqual(expecting, a.ToString());
        }
コード例 #33
0
 public virtual void testSimpleIndentOfAttributeList()
 {
 string templates = ""
     + "group test;" + NL
     + "list(names) ::= <<" + @"  $names; separator=""\n""$" + NL
     + ">>" + NL;
 IStringTemplateErrorListener errors = new ErrorBuffer();
 StringTemplateGroup group = new StringTemplateGroup(new StringReader(templates), typeof(DefaultTemplateLexer), errors);
 StringTemplate t = group.GetInstanceOf("list");
 t.SetAttribute("names", "Terence");
 t.SetAttribute("names", "Jim");
 t.SetAttribute("names", "Sriram");
 string expecting = ""
     + "  Terence" + NL
     + "  Jim" + NL
     + "  Sriram";
 Assert.AreEqual(expecting, t.ToString());
 }
コード例 #34
0
 public virtual void testExpressionAsRHSOfAssignment()
 {
     StringTemplateGroup group = new StringTemplateGroup("test");
     StringTemplate hostname = group.DefineTemplate("hostname", "$machine$.jguru.com");
     StringTemplate bold = group.DefineTemplate("bold", "<b>$x$</b>");
     StringTemplate t = new StringTemplate(group, @"$bold(x=hostname(machine=""www""))$");
     string expecting = "<b>www.jguru.com</b>";
     Assert.AreEqual(expecting, t.ToString());
 }