Implementation of ITemplateEngine that uses NVelocity
Inheritance: ITemplateEngine, ISupportInitialize
Exemple #1
0
		public AbstractGenerator()
		{
			engine = new NVelocityTemplateEngine();

			engine.AddResourceAssembly(System.Reflection.Assembly.GetExecutingAssembly().FullName);
			
			engine.BeginInit();
			engine.EndInit();
		}
Exemple #2
0
		static void Main(string[] args)
		{
			AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

			MainOptions opts = new MainOptions();
			opts.ProcessArgs(args);

			if (args.Length == 0 || args[0].StartsWith("-"))
			{
				ShowUsage();
			}

			Console.WriteLine("Processing {0} {1}", args[0], opts.verbose);

			IGenerator generator = null;

			if (args[0] == "controller")
			{
				generator = new NewController();
			}
			else if (args[0] == "project")
			{
				generator = new NewProject();
			}
			else
			{
				Console.Error.WriteLine("Not supported");
				return;
			}

			Configure(generator, args);

			string workingDir = AppDomain.CurrentDomain.BaseDirectory;
			string templateDir = @"C:\dev\DotNet\castle\svn\trunk\MonoRail\NewGenerator\GeneratorTemplates\";

			GeneratorContext context = new GeneratorContext(workingDir, templateDir);

			ITemplateEngine engine = new NVelocityTemplateEngine(templateDir);

			if (engine is ISupportInitialize)
			{
				((ISupportInitialize)engine).BeginInit();
			}

			generator.Generate(context, new DefaultGeneratorService(context, engine));
		}
		public void Execute(object Application, int hwndOwner, ref object[] ContextParams, ref object[] CustomParams,
		                    ref wizardResult retval)
		{
			DTE dte = (DTE) Application;

			AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
			
			string workingDir =  (string) ContextParams[3];
			string templateDir = @"C:\dev\DotNet\castle\svn\trunk\MonoRail\NewGenerator\GeneratorTemplates\";

			context = new GeneratorContext(workingDir, templateDir);

			//Using NVelocityTemplateEngine. Since we must resolve the lib dir...
			templateEngine = new NVelocityTemplateEngine(templateDir);
			((ISupportInitialize) templateEngine).BeginInit();

			NewProject generator = CreateNewProject(ContextParams);

			generator.Generate(context, this);

			dte.Solution.Open(generator.SolutionFilePath);
		}
		private static void InitializeTemplateEngine()
		{
			if (templateEngine == null)
			{
				NVelocityTemplateEngine 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;
			}
		}