Beispiel #1
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
            };
        }
Beispiel #2
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;
        }
Beispiel #3
0
        private void configureNamespaces(BehaviorGraph graph)
        {
            _sparkSettings.SetAutomaticEncoding(true);

            _sparkSettings.AddAssembly(typeof(HtmlTag).Assembly)
            .AddAssembly(typeof(IPartialInvoker).Assembly)
            .AddNamespace(typeof(IPartialInvoker).Namespace)
            .AddNamespace(typeof(VirtualPathUtility).Namespace) // System.Web
            .AddNamespace(typeof(SparkViewFacility).Namespace)  // FubuMVC.Spark
            .AddNamespace(typeof(HtmlTag).Namespace);           // HtmlTags

            var engineSettings = graph.Settings.Get <SparkEngineSettings>();

            engineSettings.UseNamespaces.Each(ns => _sparkSettings.AddNamespace(ns));
        }
        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);
        }
Beispiel #5
0
        public string Render <TViewData>(string template, TViewData data)
        {
            var settings = new SparkSettings();

            settings.AddNamespace("Topshelf.Dashboard");
            settings.PageBaseType = typeof(TopshelfView).FullName;

            var engine = new SparkViewEngine(settings)
            {
                ViewFolder = _viewFolder,
            };

            ISparkView instance = engine.CreateInstance(new SparkViewDescriptor().AddTemplate(template));

            var view = (TopshelfView <TViewData>)instance;

            view.SetModel(data);

            var sb = new StringBuilder();

            using (var writer = new StringWriter(sb))
                view.RenderView(writer);

            return(sb.ToString());
        }
        public SparkViewEngine Engine()
        {
            if (engine != null)
            {
                return(engine);
            }

            var settings = new SparkSettings()
                           .SetPageBaseType(typeof(WebFormsSparkView))
                           .SetNullBehaviour(NullBehaviour.Strict);

            foreach (var ns in namespaces)
            {
                settings = settings.AddNamespace(ns);
            }
            foreach (var a in assemblies)
            {
                settings = settings.AddAssembly(a);
            }

            engine = new SparkViewEngine(settings);

            engine.ViewFolder = GetViewFolder();

            engine.BatchCompilation(GetViewDescriptors());
            return(engine);
        }
        public void SettingsAreMergedRightToLeft()
        {
            var left = new SparkSettings();
            var right = new SparkSettings();

            right.NullBehaviour = NullBehaviour.Strict;
            right.PageBaseType = "test";
            right.Prefix = "test";
            right.StatementMarker = "T";
            right.AutomaticEncoding = true;
            right.AddResourceMapping("test", "test");
            right.AddAssembly("test");
            right.AddNamespace("test");
            right.AddViewFolder(typeof (int), new Dictionary<string, string>());

            Merger.Merge(left, right);

            left.NullBehaviour.ShouldEqual(right.NullBehaviour);
            left.NullBehaviour.ShouldEqual(right.PageBaseType);
            left.NullBehaviour.ShouldEqual(right.Prefix);
            left.NullBehaviour.ShouldEqual(right.StatementMarker);
            left.NullBehaviour.ShouldEqual(right.AutomaticEncoding);
            left.ResourceMappings.ShouldEqual(right.ResourceMappings);
            left.UseAssemblies.ShouldEqual(right.UseAssemblies);
            left.UseNamespaces.ShouldEqual(right.UseNamespaces);
        }
Beispiel #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
            };
        }
        private static HtmlResponse GetViewResponse <T>(byte[] viewTemplate, IEnumerable <string> namespaces, Action <T> populateView = null)
            where T : AbstractSparkView
        {
            return(new HtmlResponse(
                       () =>
            {
                Type viewType = typeof(T);
                SparkSettings settings = new SparkSettings()
                                         .SetPageBaseType(viewType)
                                         .SetDebug(false);

                foreach (string @namespace in namespaces.Distinct())
                {
                    settings.AddNamespace(@namespace);
                }

                var container = new SparkServiceContainer(settings);
                var viewFolder = new InMemoryViewFolder();

                container.SetServiceBuilder <IViewFolder>(arg => viewFolder);
                var viewEngine = container.GetService <ISparkViewEngine>();
                string viewKey = viewType.Name.Replace("View", "") + ".spark";
                const string applicationKey = @"Layouts\application.spark";

                viewFolder.AddLayoutsPath("Layouts");
                viewFolder.Add(viewKey, viewTemplate);
                viewFolder.Add(applicationKey, ResponseResources.Application);

                SparkViewDescriptor descriptor = new SparkViewDescriptor()
                                                 .AddTemplate(viewKey)
                                                 .AddTemplate(applicationKey);
                var view = (T)viewEngine.CreateInstance(descriptor);

                try
                {
                    if (populateView != null)
                    {
                        populateView(view);
                    }

                    var writer = new StringWriter();

                    view.RenderView(writer);

                    return writer.ToString();
                }
                finally
                {
                    viewEngine.ReleaseInstance(view);
                }
            }));
        }
        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);
        }
 private void SetTemplateSource(string templateSource)
 {
     var settings = new SparkSettings
                     {
                         PageBaseType = typeof (SparkResourceView).Name
                     };
     settings.AddViewFolder(typeof (TestingViewFolder), new Dictionary<string, string>
                                                         {
                                                             {"templateSource", templateSource}
                                                         });
     settings.AddNamespace("OpenRasta.Codecs.Spark");
     settings.AddNamespace("OpenRasta.Web.Markup");
     settings.AddNamespace("OpenRasta.Web");
     settings.AddNamespace("OpenRasta.Codecs.Spark.Tests.TestObjects");
     settings.AddNamespace("System.Collections.Generic");
     settings.AddNamespace("OpenRasta.Codecs.Spark.Extensions");
     sparkConfiguration
         .Container
         .SetService<ISparkSettings>(settings);
 }
        public static SparkSettings CreateSparkSettings()
        {
            var settings = new SparkSettings();

            settings.Debug = true;

            settings.AddAssembly("Newtonsoft.Json");
            settings.AddAssembly("RedBranch.Hammock");
            settings.AddAssembly("Ascend.Core");
            settings.AddAssembly("Ascend.Infrastructure");
            settings.AddAssembly("Ascend.Web.Admin");

            settings.AddNamespace("System");
            settings.AddNamespace("System.Collections.Generic");
            settings.AddNamespace("System.Linq");
            settings.AddNamespace("System.Web");
            settings.AddNamespace("System.Web.Routing");
            settings.AddNamespace("System.Web.Mvc");
            settings.AddNamespace("System.Web.Mvc.Html");
            settings.AddNamespace("Newtonsoft.Json");
            settings.AddNamespace("RedBranch.Hammock");
            settings.AddNamespace("Ascend.Core");
            settings.AddNamespace("Ascend.Core.Repositories");
            settings.AddNamespace("Ascend.Core.Services");
            settings.AddNamespace("Ascend.Infrastructure");
            settings.AddNamespace("Ascend.Infrastructure.Web");
            settings.AddNamespace("Ascend.Web.Admin");
            return(settings);
        }
 public ConfigureSparkSettingsExpression AddNamespace(string @namespace)
 {
     _settings.AddNamespace(@namespace);
     return(this);
 }
 public void AddNamespaces(SparkSettings settings)
 {
     Namespaces.ForEach(ns => settings.AddNamespace(ns));
 }