Beispiel #1
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());
            }
        }
 public virtual void testOverriddenRenderer()
 {
 string templates = ""
     + "group test;" + NL
     + "dateThing(created) ::= \"date: <created>\"" + NL;
 StringTemplateGroup group = new StringTemplateGroup(new StringReader(templates), typeof(AngleBracketTemplateLexer));
 StringTemplate st = group.GetInstanceOf("dateThing");
 st.SetAttribute("created", new DateTime(2005, 7, 5));
 group.RegisterAttributeRenderer(typeof(DateTime), new DateRenderer());
 st.RegisterAttributeRenderer(typeof(DateTime), new DateRenderer2());
 string expecting = "date: 07/05/2005";
 string result = st.ToString();
 Assert.AreEqual(expecting, result);
 }
 public virtual void testEmbeddedRendererSeesEnclosing_UsingGroupFile()
 {
 string templates = ""
     + "group Messages;" + NL
     + "PrintMessage(date) ::= <<" + NL
     + "Remember this date: $PrintDate(date=date)$" + NL
     + ">>" + NL
     + "PrintDate(date) ::= <<$date$>>" + NL
     ;
 StringTemplateGroup group = new StringTemplateGroup(
     new StringReader(templates), typeof(DefaultTemplateLexer)
     );
 StringTemplate printMessageTemplate = group.GetInstanceOf("PrintMessage");
 printMessageTemplate.SetAttribute("date", new DateTime(2005, 7, 5));
 group.RegisterAttributeRenderer(typeof(DateTime), new DateRenderer2());
 printMessageTemplate.RegisterAttributeRenderer(typeof(DateTime), new DateRenderer());
 string expecting = "Remember this date: 2005.07.05";
 string result = printMessageTemplate.ToString();
 Assert.AreEqual(expecting, result);
 }
		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());
			}
		}