public void SimpleTemplateProcessingWithinTwoResources() { NVelocityTemplateEngine engine = new NVelocityTemplateEngine(); engine.AddResourceAssembly("TemplateEngine.NVelocityTemplateEngine.Tests"); engine.AddResourceAssembly("Castle.Components.Common.TemplateEngine.NVelocityTemplateEngine.SR"); (engine as ISupportInitialize).BeginInit(); StringWriter writer = new StringWriter(); string templateFile = "Castle.Components.Common.TemplateEngine.NVelocityTemplateEngine.Tests/compiledres/simple.vm"; Assert.IsTrue(engine.Process( new Hashtable(), templateFile, writer)); Assert.AreEqual("This is a simple template", writer.GetStringBuilder().ToString()); // clear the writer for the second run writer = new StringWriter(); string secondTemplateFile = "Castle.Components.Common.TemplateEngine.NVelocityTemplateEngine.SR/compiledres/simple.vm"; Assert.IsTrue(engine.Process( new Hashtable(), secondTemplateFile, writer)); Assert.AreEqual("This is the second simple template", writer.GetStringBuilder().ToString()); }
public void SimpleTemplateProcessingWithinTwoResources() { NVelocityTemplateEngine engine = new NVelocityTemplateEngine(); engine.AddResourceAssembly("Castle.Components.Common.TemplateEngine.NVelocityTemplateEngine.Tests"); engine.AddResourceAssembly("Castle.Components.Common.TemplateEngine.NVelocityTemplateEngine.Tests.SR"); (engine as ISupportInitialize).BeginInit(); StringWriter writer = new StringWriter(); string templateFile = "Castle.Components.Common.TemplateEngine.NVelocityTemplateEngine.Tests/compiledres/simple.vm"; Assert.IsTrue(engine.Process( new Hashtable(), templateFile, writer)); Assert.AreEqual("This is a simple template", writer.GetStringBuilder().ToString()); // clear the writer for the second run writer = new StringWriter(); string secondTemplateFile = "Castle.Components.Common.TemplateEngine.NVelocityTemplateEngine.Tests.SR/compiledres/simple.vm"; Assert.IsTrue(engine.Process( new Hashtable(), secondTemplateFile, writer)); Assert.AreEqual("This is the second simple template", writer.GetStringBuilder().ToString()); }
public AbstractGenerator() { engine = new NVelocityTemplateEngine(); engine.AssemblyName = System.Reflection.Assembly.GetExecutingAssembly().FullName; engine.BeginInit(); engine.EndInit(); }
public void SimpleTemplateProcessing() { ITemplateEngine engine = new NVelocityTemplateEngine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "templates")); (engine as ISupportInitialize).BeginInit(); StringWriter writer = new StringWriter(); Assert.IsTrue( engine.Process(new Hashtable(), "simple.vm", writer) ); Assert.AreEqual("This is a simple template", writer.GetStringBuilder().ToString()); }
public void SimpleTemplateProcessing() { ITemplateEngine engine = new NVelocityTemplateEngine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "templates")); (engine as ISupportInitialize).BeginInit(); StringWriter writer = new StringWriter(); Assert.IsTrue(engine.Process(new Hashtable(), "simple.vm", writer)); Assert.AreEqual("This is a simple template", writer.GetStringBuilder().ToString()); }
public void SimpleTemplateProcessing() { String path = Path.Combine( AppDomain.CurrentDomain.BaseDirectory, Path.Combine(System.Configuration.ConfigurationManager.AppSettings["tests.src"], "templates")); ITemplateEngine engine = new NVelocityTemplateEngine(path); (engine as ISupportInitialize).BeginInit(); StringWriter writer = new StringWriter(); Assert.IsTrue( engine.Process(new Hashtable(), "simple.vm", writer) ); Assert.AreEqual("This is a simple template", writer.GetStringBuilder().ToString()); }
public void SimpleTemplateProcessingWithinResource() { NVelocityTemplateEngine engine = new NVelocityTemplateEngine(); engine.AssemblyName = "Castle.Components.Common.TemplateEngine.NVelocityTemplateEngine.Tests"; (engine as ISupportInitialize).BeginInit(); StringWriter writer = new StringWriter(); Assert.IsTrue(engine.Process( new Hashtable(), "Castle.Components.Common.TemplateEngine.NVelocityTemplateEngine.Tests/compiledres/simple.vm", writer)); Assert.AreEqual("This is a simple template", writer.GetStringBuilder().ToString()); }
private static void InitializeTemplateEngine() { if (templateEngine == null) { NVelocityTemplateEngine nvelTemplateEng = new NVelocityTemplateEngine(); #if DEBUG nvelTemplateEng.TemplateDir = @"E:\dev\castleall\trunk\MonoRail\Castle.MonoRail.ActiveRecordScaffold\Templates\"; nvelTemplateEng.BeginInit(); nvelTemplateEng.EndInit(); #else nvelTemplateEng.AssemblyName = "Castle.MonoRail.ActiveRecordScaffold"; nvelTemplateEng.BeginInit(); nvelTemplateEng.EndInit(); #endif templateEngine = nvelTemplateEng; } }
private static void InitializeTemplateEngine() { if (templateEngine == null) { var nvelTemplateEng = new NVelocityTemplateEngine(); #if USE_LOCAL_TEMPLATES nvelTemplateEng.TemplateDir = @"E:\dev\castle\trunk\MonoRail\Castle.MonoRail.ActiveRecordSupport.Scaffold\Templates\"; nvelTemplateEng.BeginInit(); nvelTemplateEng.EndInit(); #else nvelTemplateEng.AddResourceAssembly("Castle.MonoRail.ActiveRecordSupport"); nvelTemplateEng.BeginInit(); nvelTemplateEng.EndInit(); #endif templateEngine = nvelTemplateEng; } }
public void ShouldProcessATextReaderTemplate() { NVelocityTemplateEngine engine = new NVelocityTemplateEngine(); (engine as ISupportInitialize).BeginInit(); StringWriter writer = new StringWriter(); StringWriter contextWriter = new StringWriter(); string template = "This is a simple template"; string contextTemplate = "This is a simple $templateType template"; IDictionary context = new Hashtable(); context.Add("templateType", typeof(NVelocityTemplateEngine).Name); Assert.IsTrue(engine.Process(new Hashtable(), "ShouldProcessAStringTemplate", writer, new StringReader(template))); Assert.AreEqual("This is a simple template", writer.GetStringBuilder().ToString()); Assert.IsTrue(engine.Process(context, "ShouldProcessAStringTemplate", contextWriter, new StringReader(contextTemplate))); Assert.AreEqual("This is a simple NVelocityTemplateEngine template", contextWriter.GetStringBuilder().ToString()); }
public void ShouldProcessAStringTemplate() { NVelocityTemplateEngine engine = new NVelocityTemplateEngine(); (engine as ISupportInitialize).BeginInit(); StringWriter writer = new StringWriter(); StringWriter contextWriter = new StringWriter(); string template = "This is a simple template"; string contextTemplate = "This is a simple $templateType template"; IDictionary context = new Hashtable(); context.Add("templateType", typeof(NVelocityTemplateEngine).Name); Assert.IsTrue(engine.Process(new Hashtable(), "ShouldProcessAStringTemplate", writer, template)); Assert.AreEqual("This is a simple template", writer.GetStringBuilder().ToString()); Assert.IsTrue(engine.Process(context, "ShouldProcessAStringTemplate", contextWriter, contextTemplate)); Assert.AreEqual("This is a simple NVelocityTemplateEngine template", contextWriter.GetStringBuilder().ToString()); }
public FileTypeProcessor(string basePath) { this.basePath = basePath; engine = new NVelocityTemplateEngine(basePath); engine.Initialize(); }
private static void AttachSnippet( OrmEntityMethod entityMethod, string methodBodyTemplate, string relationshipProperty, string localProperty, string foreignProperty, params string[] usings) { string methodName = string.Format("{0}_Set{1}", entityMethod.MethodName, localProperty); OrmMethodTargetSnippet snippet = (OrmMethodTargetSnippet) CollectionUtils.Find( entityMethod.PostExecuteTargets, delegate(OrmMethodTarget item) { return (item is OrmMethodTargetSnippet && StringUtils.CaseInsensitiveEquals(item.TargetMethod, methodName)); }); if (snippet == null) { snippet = new OrmMethodTargetSnippet(entityMethod, MethodTargetType.PostExecute); entityMethod.PostExecuteTargets.Add(snippet); } string namespaceName = CodeSnippetManager.GetConfiguration().DefaultNamespace; string className = entityMethod.Entity.Name + "BusinessRules"; CodeSnippetTemplateContext context = new CodeSnippetTemplateContext( namespaceName, className, methodName, "void"); foreach (string use in usings) { context.Usings.Add(use); } context.Usings.Add("NHibernate"); string targetInstance = entityMethod.Entity.Name.ToLowerInvariant(); context.AddParameter(entityMethod.Entity.InterfaceName, targetInstance); context.AddParameter("ISession", "session"); if (!(snippet.CodeSnippet is CodeSnippetCSharp)) { if (snippet.CodeSnippet != null) { snippet.CodeSnippet.Delete(); } snippet.CodeSnippet = new CodeSnippetCSharp(entityMethod, context); } snippet.CodeSnippet.Header.Name = methodName; snippet.CodeSnippet.Header.AssemblyReferences.Add( new AssemblyReference( "Sage.Entity.Interfaces.dll", Path.Combine("%BASEBUILDPATH%", @"interfaces\bin\Sage.Entity.Interfaces.dll"))); snippet.CodeSnippet.Header.AssemblyReferences.Add( new AssemblyReference( "Sage.Platform.dll", Path.Combine("%BASEBUILDPATH%", @"assemblies\Sage.Platform.dll"))); snippet.TargetMethod = methodName; snippet.TargetType = string.Format("{0}.{1}, {2}", namespaceName, className, snippet.CodeSnippet.Header.Assembly); string code = snippet.CodeSnippet.Code; int pos = code.IndexOf(methodName); if (pos >= 0) { pos = code.IndexOf("// TODO: ", pos); if (pos >= 0) { int pos2 = code.IndexOfAny(new char[] {'\r', '\n'}, pos); if (pos2 >= 0) { Hashtable contexts = new Hashtable(4); contexts.Add("targetInstance", targetInstance); contexts.Add("relationshipProperty", relationshipProperty); contexts.Add("localProperty", localProperty); contexts.Add("foreignProperty", foreignProperty); ITemplateEngine engine = new NVelocityTemplateEngine(); ITemplate template = engine.CreateTemplate(methodBodyTemplate, contexts); snippet.CodeSnippet.Code = code.Replace( code.Substring(pos, pos2 - pos), template.ApplyTemplate()); } } } entityMethod.Validate(); entityMethod.Save(); }