public string RenderTemplate(string templateSource, object data)
        {
            var settings = new SparkSettings
                           	{
                           		PageBaseType = typeof(TestSparkView).Name
                           	};
            settings.AddViewFolder(typeof (TestingViewFolder), new Dictionary<string, string>
                                                               	{
                                                               		{"templateSource", templateSource}
                                                               	});

            settings.AddNamespace("OpenRasta.Codecs.Spark.Tests.TestObjects");
            settings.AddNamespace("OpenRasta.Codecs.Spark.IntegrationTests");
            settings.AddNamespace("OpenRasta.Codecs.Spark2.ViewHelpers");
            settings.AddNamespace("System.Collections.Generic");

            IWindsorContainer dependencies = CreateTestDependencies();
            ISparkViewEngine sparkViewEngine = new SparkViewEngine(settings)
                                               	{
                                               		ExtensionFactory =dependencies.Resolve<ISparkExtensionFactory>()
                                               	};

            var descriptor = new SparkViewDescriptor();
            descriptor.AddTemplate(TestingViewFolder.SingleTemplateName);
            var view = (TestSparkView)sparkViewEngine.CreateInstance(descriptor);
            view.Uris = new UriGenerator(DependencyManager.GetService<IUriResolver>());
            view.ViewData = new TestViewData(data);
            return Render(view);
        }
Esempio n. 2
0
        public HtmlGenerator()
        {
            var setup = new SparkSettings();

            setup.AddNamespace("Docu");
            setup.AddNamespace("Docu.Parsing.Model");
            setup.AddNamespace("System.Linq");

            engine = new SparkViewEngine(setup);
            SetTemplatePath("templates");
            engine.DefaultPageBaseType = typeof(SparkTemplateBase).FullName;
        }
Esempio n. 3
0
        public HtmlGenerator()
        {
            var setup = new SparkSettings();

            setup.AddNamespace(typeof(Program).Namespace);
            setup.AddNamespace(typeof(TemplateExtensions.TemplateHelperExtensions).Namespace);
            setup.AddNamespace(typeof(Parsing.Model.TypeIdentifier).Namespace);
            setup.AddNamespace(typeof(System.Linq.Enumerable).Namespace);

            engine = new SparkViewEngine(setup);
            SetTemplatePath("templates");
            engine.DefaultPageBaseType = typeof(SparkTemplateBase).FullName;
        }
Esempio n. 4
0
		private SparkSettings CreateSparkSettings()
		{
			var result = new SparkSettings
			             	{
			             		PageBaseType = typeof (SparkResourceView).Name
			             	};
			result.AddViewFolder(ViewFolderType.VirtualPathProvider,
			                     new Dictionary<string, string> {{"virtualBaseDir", "~/views/"}});
			result.AddNamespace("OpenRasta.Web.Markup");
			result.AddNamespace("OpenRasta.Web");
			result.AddNamespace("OpenRasta.Codecs.Spark");
			result.AddNamespace("System.Linq");
			result.AddNamespace("OpenRasta.Codecs.Spark.Extensions");
			return result;
		}
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            ViewEngines.Engines.Clear();

            var settings = new SparkSettings()
                .SetAutomaticEncoding(true)
                .AddNamespace("Microsoft.Web.Mvc")
                .AddNamespace("System")
                .AddNamespace("System.Collections.Generic")
                .AddNamespace("System.Linq")
                .AddNamespace("System.Web.Mvc")
                .AddNamespace("System.Web.Mvc.Html")
                .AddNamespace("WhoCanHelpMe.Framework.Extensions")
                .AddNamespace("WhoCanHelpMe.Web.Code");

            // Add all namespaces from controllers project.
            typeof(HomeController).Assembly
                                  .GetExportedTypes()
                                  .Select(t => t.Namespace)
                                  .Distinct()
                                  .ToList()
                                  .ForEach(n => settings.AddNamespace(n));

            var services = SparkEngineStarter.CreateContainer(settings);

            SparkEngineStarter.RegisterViewEngine(services);
        }
Esempio n. 6
0
        public static void RegisterViewEngine(ViewEngineCollection engines)
        {
            var sparkSettings = new SparkSettings();

            sparkSettings
                .AddNamespace("System")
                .AddNamespace("System.Collections.Generic")
                .AddNamespace("System.Linq")
                .AddNamespace("System.Web.Mvc")
                .AddNamespace("System.Web.Mvc.Html");

            sparkSettings
                .AddAssembly("Spark.Web.Mvc")
                .AddAssembly("System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35")
                .AddAssembly("System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");

            var builder = new DefaultDescriptorBuilder();
            builder.Filters.Add(new AreaDescriptorFilter());

            var container = SparkEngineStarter.CreateContainer(sparkSettings);
            container.SetServiceBuilder<Spark.Web.Mvc.IDescriptorBuilder>(c => builder);
            SparkEngineStarter.RegisterViewEngine(container);

            engines.Add(new SparkViewFactory(sparkSettings));
        }
Esempio n. 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SparkEngine"/> class.
        /// </summary>
        /// <exception cref="ArgumentNullException"><c>viewBaseType</c> or <c>handler</c> is <c>null</c>.</exception>
        public SparkEngine(Type viewBaseType, InitializeViewHandler handler)
        {
            if (viewBaseType == null) throw new ArgumentNullException("viewBaseType");
            if (handler == null) throw new ArgumentNullException("handler");
            _viewBaseType = viewBaseType;
            _handler = handler;
            _currentEngine = this;

            SparkSettings settings = new SparkSettings();
            settings.AddNamespace("System.Collections.Generic");
            settings.AddNamespace("HttpServer.Mvc.Views");
            settings.AddNamespace("HttpServer.ViewEngine.Spark");
            settings.AddAssembly(GetType().Assembly);
            settings.AddAssembly(typeof (Server).Assembly);
            _engine = new SparkViewEngine(settings)
            {
                ViewFolder = new MyViewFolder(),
                DefaultPageBaseType = viewBaseType.FullName
            };
        }
Esempio n. 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SparkEngine"/> class.
 /// </summary>
 public SparkEngine()
 {
     _currentEngine = this;
     SparkSettings settings = new SparkSettings();
     settings.AddNamespace("System.Collections.Generic");
     _engine = new SparkViewEngine(settings)
                   {
                       ViewFolder = new MyViewFolder(),
                       DefaultPageBaseType = typeof (SparkView).FullName
                   };
 }
Esempio n. 9
0
        public SparkRenderer()
        {
            SparkSettings settings = new SparkSettings();
            settings.SetPageBaseType(typeof(MarkdownPageTemplate));
            settings.DefaultLanguage = LanguageType.CSharp;
            settings.Debug = true;

            settings.AddNamespace("System");

            this.engine = new SparkViewEngine(settings);
        }
Esempio n. 10
0
        private static void ConfigureViewImports(SparkSettings settings)
        {
            settings.AddAssembly("Spark.Web.Mvc")
                    .AddAssembly("System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")
                    .AddAssembly("System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")
                    .AddAssembly("System.Web.Optimization, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");

            settings.AddNamespace("System")
                    .AddNamespace("System.Collections.Generic")
                    .AddNamespace("System.Linq")
                    .AddNamespace("System.Web.Mvc")
                    .AddNamespace("System.Web.Mvc.Html")
                    .AddNamespace("System.Web.Optimization");
        }
 public ISparkSettings CreateSettings()
 {
     var settings = new SparkSettings
                    	{
                    		PageBaseType = typeof (SparkResourceView).Name
                    	};
     settings.AddViewFolder(typeof (TestingViewFolder), new Dictionary<string, string>
                                                        	{
                                                        		{"templateSource", _templateSource}
                                                        	});
     new SparkCodecNamespacesConfiguration().AddNamespaces(settings);
     settings.AddNamespace("OpenRasta.Codecs.Spark.Tests.TestObjects");
     return settings;
 }
Esempio n. 12
0
        private static void Stub(FileSystemInfo source, FileSystemInfo destination)
        {
            if (source.FullName.EndsWith(".spark"))
            {
                // At this time the destination is already copied and processed by
                // 'simple' text substitution, so destination should be processed.
                var settings = new SparkSettings();
                settings.AddNamespace("System");

                var engine = new SparkViewEngine(settings) {DefaultPageBaseType = typeof(Template).FullName};
                var folder = new InMemoryViewFolder {{source.Name, File.ReadAllText(destination.FullName)}};
                engine.ViewFolder = folder;

                var descriptor = new SparkViewDescriptor();
                descriptor.AddTemplate(source.Name);

                var view = (Template) engine.CreateInstance(descriptor);
                var builder = new StringBuilder();
                using (var output = new StringWriter(builder))
                {
                    view.RenderView(output);
                    File.WriteAllText(destination.FullName, output.ToString());
                }

                engine.ReleaseInstance(view);
            }
            else if (source.FullName.EndsWith(".tt"))
            {
                var generator = new TemplateGenerator();
                if (!generator.ProcessTemplate(source.FullName, destination.FullName))
                {
                    var exception = new TemplateException(source.FullName);
                    foreach (CompilerError error in generator.Errors)
                    {
                        exception.AddError(error.ErrorText);
                    }
                    throw exception;
                }
            }
        }
 public void AddNamespaces(SparkSettings settings)
 {
     Namespaces.ForEach(ns => settings.AddNamespace(ns));
 }