public override void Install(IDictionary stateSaver)
        {
            // figure out all paths based on this assembly in the bin dir
            string assemblyPath = GetType().Assembly.Location;
            string targetPath = Path.ChangeExtension(assemblyPath, ".Views.dll");
            string webSitePath = Path.GetDirectoryName(Path.GetDirectoryName(assemblyPath));
            string webBinPath = Path.Combine(webSitePath, "bin");
            string webFileHack = Path.Combine(webSitePath, "web");
            string viewsLocation = Path.Combine(webSitePath, "Views");

            // this hack enables you to open the web.config as if it was an .exe.config
            File.Create(webFileHack).Close();
            Configuration config = ConfigurationManager.OpenExeConfiguration(webFileHack);
            File.Delete(webFileHack);

            // GetSection will try to resolve the "Spark" assembly, which the installutil appdomain needs help finding
            AppDomain.CurrentDomain.AssemblyResolve +=
                ((sender, e) => Assembly.LoadFile(Path.Combine(webBinPath, e.Name + ".dll")));
            var settings = (ISparkSettings) config.GetSection("spark");

            // Finally create an engine with the <spark> settings from the web.config
            var engine = new SparkViewEngine(settings)
                             {
                                 ViewFolder = new FileSystemViewFolder(viewsLocation)
                             };

            // And generate all of the known view/master templates into the target assembly
            engine.BatchCompilation(targetPath, Global.AllKnownDescriptors());
        }
Beispiel #2
0
        public static string RenderTemplate(string template, ViewDataDictionary viewData)
        {
            // Set up your spark engine goodness.
            var settings = new SparkSettings().SetPageBaseType(typeof(SparkView));

            var engine = new SparkViewEngine(settings)
                         {
                             ViewFolder = new FileSystemViewFolder(AppDomain.CurrentDomain.BaseDirectory + @"\..\..\..\IntegrationTestingViews\Views")
                         };

            // "Describe" the view (the template, it is a template after all), and its details.
            var descriptor = new SparkViewDescriptor().AddTemplate(template);

            // Create a spark view engine instance
            var view = (SparkView)engine.CreateInstance(descriptor);
            try
            {
                // Merge the view data.
                viewData.Keys.ToList().ForEach(x => view.ViewData[x] = viewData[x]);

                // Render the view to a text writer.
                var writer = new StringWriter();
                view.RenderView(writer);
                return writer.ToString();
            }
            finally
            {
                engine.ReleaseInstance(view);
            }
        }
        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);
        }
Beispiel #4
0
        public virtual void Init()
        {
            mocks = new MockRepository();

            var services = new StubMonoRailServices();
            services.ViewSourceLoader = new FileAssemblyViewSourceLoader("MonoRail.Tests.Views");
            services.AddService(typeof(IViewSourceLoader), services.ViewSourceLoader);

            viewComponentFactory = new DefaultViewComponentFactory();
            viewComponentFactory.Initialize();
            services.AddService(typeof(IViewComponentFactory), viewComponentFactory);
            services.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry);

            var settings = new SparkSettings();
            engine = new SparkViewEngine(settings);
            services.AddService(typeof(ISparkViewEngine), engine);

            factory = new SparkViewFactory();
            factory.Service(services);

            controller = MockRepository.GenerateMock<IController>();
            controllerContext = new ControllerContext();
            var request = new StubRequest();
            request.FilePath = "";
            var response = new StubResponse();
            engineContext = new StubEngineContext(request, response, new UrlInfo("", "Home", "Index", "/", "castle"));
            engineContext.AddService(typeof(IViewComponentFactory), viewComponentFactory);
            engineContext.AddService(typeof(IViewComponentRegistry), viewComponentFactory.Registry);
        }
Beispiel #5
0
        public IBuilder Load(Options options)
        {
            var currentDirectory = Environment.CurrentDirectory;
            var assemblyDirectory = Path.GetDirectoryName(typeof(SakeEngine).Assembly.Location);

            var settings = new SparkSettings()
                .SetPageBaseType(typeof(BuilderBase))
                .SetAutomaticEncoding(true)
                .SetAttributeBehaviour(AttributeBehaviour.TextOriented)
                .SetDebug(true);

            IViewFolder viewFolder = new FileSystemViewFolder(currentDirectory);
            foreach(var includeDir in options.IncludeDirectory)
            {
                viewFolder = new CombinedViewFolder(viewFolder, new FileSystemViewFolder(Path.Combine(currentDirectory, includeDir)));
            }
            viewFolder = new CombinedViewFolder(viewFolder, new FileSystemViewFolder(assemblyDirectory));

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

            var descriptor = new SparkViewDescriptor
            {
                Templates = new[] { options.Makefile }
            };

            var builder = (BuilderBase)engine.CreateInstance(descriptor);
            builder.Output = new StringWriter();
            builder.Log = _log;
            builder.Render();
            return builder;
        }
Beispiel #6
0
        public SourceSupervisor(ISparkSource source)
        {
            _source = source;

            IVsHierarchy hierarchy;
            uint itemid;
            IVsTextLines buffer;
            _source.GetDocument(out hierarchy, out itemid, out buffer);

            _path = GetDocumentPath(hierarchy, itemid);

            //Spark.Web.Mvc.SparkView
            //MyBaseView

            var settings = new VsProjectSparkSettings(hierarchy)
                               {
                                   PageBaseType = source.GetDefaultPageBaseType()
                               };

            var viewFolder = new VsProjectViewFolder(_source, hierarchy);

            _engine = new SparkViewEngine(settings)
                          {
                              ViewFolder = viewFolder
                          };

            _grammar = new MarkupGrammar(settings);
        }
Beispiel #7
0
 public DescriptorBuildingFixture()
 {
     this.viewFolder = new InMemoryViewFolder();
     this.engine     = new SparkViewEngine(null)
     {
         ViewFolder = viewFolder
     };
     this.actionContext = new ActionContext(A.Fake <HttpContextBase>(), "Bar");
 }
Beispiel #8
0
 public SparkEngine()
 {
     // TODO read settings from config
     var settings = new SparkSettings
     {
         DefaultLanguage = LanguageType.CSharp
     };
     settings.SetPageBaseType(typeof(ViewBase));
     _engine = new SparkViewEngine();
 }
Beispiel #9
0
        public SparkRender()
        {
            _viewFolder = new EmbeddedViewFolder(typeof (SparkRender).Assembly, "klinger.views");

            _engine = new SparkViewEngine
                          {
                              DefaultPageBaseType = typeof (VoteView).FullName,
                              ViewFolder = _viewFolder
                          };
        }
Beispiel #10
0
        public static void SetupEngine()
        {
            engine = new SparkViewEngine ();
            engine.DefaultPageBaseType = "Manos.Spark.ManosSparkTemplate";

            var vf = new FileSystemViewFolder ("Templates");
            vf.AddLayoutsPath ("Templates");

            engine.ViewFolder = vf;
        }
Beispiel #11
0
        protected void Application_Start(object sender, EventArgs e)
        {
            var engine = new SparkViewEngine
                             {
                                 ViewFolder = new FileSystemViewFolder(Server.MapPath("~/Views"))
                             };

            Application["ViewEngine"] = engine;

            engine.LoadBatchCompilation(Assembly.Load("MediumTrustHosting.Views"));
        }
    public SparkViewEngine CreateViewEngine()
    {
      var settings = new SparkSettings().SetPageBaseType(typeof(TemplateBase))
        .AddNamespace("System")
        .AddNamespace("System.Linq");
      var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
      var templates = new FileSystemViewFolder(Path.Combine(dir, "Templates"));
      var engine = new SparkViewEngine(settings) { ViewFolder = templates };

      return engine;
    }
Beispiel #13
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
                   };
 }
Beispiel #14
0
        public static void SetupEngine()
        {
            var settings = new SparkSettings ();
            settings.SetDebug (true);
            engine = new SparkViewEngine (settings);
            engine.DefaultPageBaseType = "Manos.Spark.ManosSparkTemplate";

            var vf = new FileSystemViewFolder ("Templates");
            vf.AddLayoutsPath ("Templates");

            engine.ViewFolder = vf;
        }
Beispiel #15
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;
        }
        public PageGenerator(IResourceManager resourceManager)
        {
            var template = resourceManager.GetStringFromAssemblyOf<PageGenerator>("Forseti.Pages.Spark.Harness.spark");

            var settings = new SparkSettings().SetPageBaseType(typeof(HarnessView));
            var templates = new InMemoryViewFolder();
            _engine = new SparkViewEngine(settings)
            {
                ViewFolder = templates
            };
            templates.Add(TemplateName, template); 
            _descriptor = new SparkViewDescriptor().AddTemplate(TemplateName);
        }
Beispiel #17
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 #18
0
        public SparkViewEngineFixture()
        {
            var settings = new SparkSettings();

            this.actionContext = new ActionContext(httpContext, "Stub");
            this.engine        = new SparkViewEngine(settings)
            {
                ViewFolder = new FileSystemViewFolder("TestViews")
            };
            this.httpContext = MockHttpContextBase.Generate("/", new StringWriter());
            this.response    = httpContext.Response;
            this.output      = response.Output;
        }
Beispiel #19
0
        public static void BuildIndex(string template, List<Metadata> model, Dictionary<string, List<Metadata>> byAssembly)
        {
            var viewFolder = new FileSystemViewFolder(".");
            var engine = new SparkViewEngine()
            {
                DefaultPageBaseType = typeof(IndexView).FullName,
                ViewFolder = viewFolder
            };

            string templateResult = ProcessViewTemplate(engine, template, model, byAssembly);

            if (!Directory.Exists("output")) Directory.CreateDirectory("output");
            File.WriteAllText(".\\output\\index.html", templateResult);
        }
Beispiel #20
0
        public PageGenerator(IResourceManager resourceManager, IFramework framework)
        {
            var template = resourceManager.GetStringFromAssemblyOf<PageGenerator>("Forseti.Pages.Spark.Harness.spark");

            _framework = framework;

            var settings = new SparkSettings().SetPageBaseType(typeof(HarnessView));
            var templates = new InMemoryViewFolder();
            _engine = new SparkViewEngine(settings)
            {
                ViewFolder = templates
            };
            templates.Add(TemplateName, template); //"<for each=\"var s in Stuff\"><p>${s}</p></for>");
            _descriptor = new SparkViewDescriptor().AddTemplate(TemplateName);
        }
        public TemplateFactory(string templateDirectoryPath)
        {
            if (!Directory.Exists(templateDirectoryPath))
                throw new ArgumentException(string.Format("The directory {0} does not exist", templateDirectoryPath));

            _templateDirectoryPath = templateDirectoryPath;
            var viewFolder = new FileSystemViewFolder(templateDirectoryPath);

            // Create an engine using the templates path as the root location
            // as well as the shared location
            _engine = new SparkViewEngine
                          {
                              DefaultPageBaseType = typeof(TemplateView).FullName,
                              ViewFolder = viewFolder
                          };
        }
Beispiel #22
0
        public PageGenerator(IResourceManager resourceManager)
        {
            var template = resourceManager.GetStringFromAssemblyOf<PageGenerator>("Forseti.Pages.Spark.Harness.spark");
            _jqueryJs = resourceManager.GetStringFromAssemblyOf<Forseti.Scripting.ScriptEngine>("Forseti.Scripting.Scripts.jquery.min.js");
            _forsetiJs = resourceManager.GetStringFromAssemblyOf<Forseti.Scripting.ScriptEngine>("Forseti.Scripting.Scripts.forseti.js");
            _requireJs = resourceManager.GetStringFromAssemblyOf<Forseti.Scripting.ScriptEngine>("Forseti.Scripting.Scripts.require.js");
            _forsetiBootstrapperJs = resourceManager.GetStringFromAssemblyOf<Forseti.Scripting.ScriptEngine>("Forseti.Scripting.Scripts.forseti.bootstrapper.js");

            var settings = new SparkSettings().SetPageBaseType(typeof(HarnessView));
            var templates = new InMemoryViewFolder();
            _engine = new SparkViewEngine(settings)
            {
                ViewFolder = templates
            };
            templates.Add(TemplateName, template); 
            _descriptor = new SparkViewDescriptor().AddTemplate(TemplateName);
        }
Beispiel #23
0
        public void Render(dynamic model, RunnerOptions runnerOptions)
        {
            _logger.Debug(string.Format("Rendering {0}", model.FileName));

            var viewEngine = new SparkViewEngine
                                 {
                                     DefaultPageBaseType = typeof (SparkView).FullName,
                                     ViewFolder = new FileSystemViewFolder(Path.Combine(runnerOptions.WorkingDirectory, "_templates"))
                                 };

            var view = (SparkView) viewEngine.CreateInstance(new SparkViewDescriptor().AddTemplate("post.spark"));
            view.Model = model;

            using(var writer = new StreamWriter(Console.OpenStandardOutput(), Encoding.UTF8))
            {
                view.RenderView(writer);
            }
        }
Beispiel #24
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 #25
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 Stream Process(string virtualPath, string rootPath, Stream source, Dictionary<string, string> settings)
        {
            IViewFolder currentFolder =
                new Spark.FileSystem.CombinedViewFolder(
                    new StringViewFolderFile(virtualPath, source),
                    new Spark.FileSystem.FileSystemViewFolder(rootPath)
                );

            /*
            foreach(var dir in Directory.GetDirectories(rootPath, "*", SearchOption.AllDirectories))
            {
                currentFolder = new Spark.FileSystem.CombinedViewFolder(
                    currentFolder,
                    new Spark.FileSystem.FileSystemViewFolder(dir)
                    );
            }
            */

            SparkViewEngine _engine = new SparkViewEngine(new Spark.SparkSettings())
            {
                DefaultPageBaseType = typeof(ViewTemplate).FullName,
                ViewFolder = currentFolder,
                TemplateLocator = new MasterFileLocator(virtualPath, rootPath),
            };

            var descriptor = new SparkViewDescriptor()
                .AddTemplate(virtualPath.TrimStart('\\'));

            var view = (ViewTemplate)_engine.CreateInstance(descriptor);

            view.RootPath = rootPath;
            view.VirtualPath = virtualPath;
            source.Dispose();
            var tw = new StringWriter();
            view.RenderView(tw);
            MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(tw.ToString().Replace("@/", view.AppRelativeFolder)));

            return ms;
        }
Beispiel #27
0
        public static void DumpToHtml(string template, Metadata model)
        {
            var viewFolder = new FileSystemViewFolder(".");
            var engine = new SparkViewEngine()
                             {
                                 DefaultPageBaseType = typeof (MessageView).FullName,
                                 ViewFolder = viewFolder
                             };
            string templateResult = ProcessViewTemplate(engine, template, model);

            if (!Directory.Exists("output")) Directory.CreateDirectory("output");
            File.WriteAllText(".\\output\\{0}.model.html".FormatWith(model.Name), templateResult);
        }
Beispiel #28
0
 public SparkEngine()
 {
     _spark = new SparkViewEngine();
     _spark.Initialize(this);
 }
 public DescriptorBuildingFixture()
 {
     this.viewFolder = new InMemoryViewFolder();
     this.engine = new SparkViewEngine(null) {ViewFolder = viewFolder};
     this.actionContext = new ActionContext(A.Fake<HttpContextBase>(), "Bar");
 }
Beispiel #30
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.Write(@"
            Transforms Xml using a Spark template

            XPARK templatefile [inputfile [outputfile]]

              templatefile  Path to a .spark file.
              inputfile     Source xml. Path to an file or url for http GET.
              outputfile    Target file to receive template output.

            If inputfile or outputfile are not provided stdin and stdout are used.

            The Model in the template is an XDocument loaded from the source.

            The templatefile location may also contain _partial.spark files, and
            a _global.spark file with common namespaces, macros, etc.
            ");
                return;
            }

            // Find the full path to the template file,
            // using current directory if argument isn't fully qualified
            var templatePath = Path.Combine(Environment.CurrentDirectory, args[0]);
            var templateName = Path.GetFileName(templatePath);
            var templateDirPath = Path.GetDirectoryName(templatePath);

            var viewFolder = new FileSystemViewFolder(templateDirPath);

            // Create an engine using the templates path as the root location
            // as well as the shared location
            var engine = new SparkViewEngine
                             {
                                 DefaultPageBaseType = typeof(SparkView).FullName,
                                 ViewFolder = viewFolder.Append(new SubViewFolder(viewFolder, "Shared"))
                             };

            SparkView view;
            // compile and instantiate the template
            view = (SparkView)engine.CreateInstance(
                                  new SparkViewDescriptor()
                                      .AddTemplate(templateName));

            // load the second argument, or default to reading stdin
            if (args.Length >= 2)
                view.Model = XDocument.Load(args[1]);
            else
                view.Model = XDocument.Load(XmlReader.Create(Console.OpenStandardInput()));

            // write out to the third argument, or default to writing stdout
            if (args.Length >= 3)
            {
                using (var writer = new StreamWriter(new FileStream(args[2], FileMode.Create), Encoding.UTF8))
                {
                    view.RenderView(writer);
                }
            }
            else
            {
                using (var writer = new StreamWriter(Console.OpenStandardOutput(), Encoding.UTF8))
                {
                    view.RenderView(writer);
                }
            }
        }
Beispiel #31
0
        static string ProcessViewTemplate(SparkViewEngine engine, string templateName, Metadata model)
        {
            var view = (MessageView)engine.CreateInstance(
                new SparkViewDescriptor()
                    .AddTemplate(templateName));

            view.Model = model;

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

            return sb.ToString();
        }
Beispiel #32
0
        static string ProcessViewTemplate(SparkViewEngine engine, string templateName, List<Metadata> model, Dictionary<string, List<Metadata>> byAssembly)
        {
            var view = (IndexView)engine.CreateInstance(
                new SparkViewDescriptor()
                    .AddTemplate(templateName));

            view.Model = new ComplexView()
                             {
                                 ByAssembly = byAssembly,
                                 ByMessage = model
                             };

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

            return sb.ToString();
        }