Exemplo n.º 1
0
        public DefaultPageBuilder()
        {
            SparkSettings settings = new SparkSettings();
            //settings.SetStatementMarker("#*");
            //settings.StatementMarker = "#*";
            settings.SetPrefix("s");
            settings.SetPageBaseType(typeof(TemplateBase));
            _engine = new SparkViewEngine(settings);
            //var sm = _engine.Settings.StatementMarker;

            var templateDirPath = Path.GetFullPath("./Veis/Views/");
            var viewFolder = new FileSystemViewFolder(templateDirPath);

            _engine.ViewFolder = viewFolder.Append(new SubViewFolder(viewFolder, "Shared"));

               //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"))
            //};
        }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
0
        public static void SetupEngine()
        {
            engine = new SparkViewEngine ();
            engine.DefaultPageBaseType = "Manos.Spark.ManosSparkTemplate";

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

            engine.ViewFolder = vf;
        }
    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;
    }
Exemplo n.º 5
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;
        }
        private SparkViewEngine GetSparkEngine(string templateDirPath)
        {
            var viewFolder = new FileSystemViewFolder(templateDirPath);

            // Create an engine using the templates path as the root location
            // as well as the shared location
            return new SparkViewEngine
                       {
                           DefaultPageBaseType = typeof (SparkView).FullName,
                           ViewFolder = viewFolder.Append(new SubViewFolder(viewFolder, "Shared"))
                       };
        }
Exemplo n.º 7
0
        public void SharingExtraFolders()
        {
            var normal = new FileSystemViewFolder("Spark.Tests.Views");
            var otherLocation = new FileSystemViewFolder(Path.Combine("Spark.Tests.Views","Prefix"));

            var viewFolder = new CombinedViewFolder(normal, new SubViewFolder(otherLocation, "Shared"));

            var normalSharedCount = normal.ListViews("Shared").Count;
            var otherLocationCount = otherLocation.ListViews("").Count;
            var totalSharedCount = viewFolder.ListViews("Shared").Count;

            Assert.AreEqual(normalSharedCount + otherLocationCount, totalSharedCount);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        public void ListViewsSameResults()
        {
            var filesystem = new FileSystemViewFolder(Path.Combine("FileSystem", "Embedded"));
            Assert.IsTrue(filesystem.HasView(Path.Combine("Home", "Index.spark")));

            var files = filesystem.ListViews("Home");
            Assert.AreEqual(2, files.Count);
            Assert.That(files.Any(f => Path.GetFileName(f) == "Index.spark"));
            Assert.That(files.Any(f => Path.GetFileName(f) == "List.spark"));

            var embedded = new EmbeddedViewFolder(Assembly.Load("Spark.Tests"), "Spark.Tests.FileSystem.Embedded");
            files = embedded.ListViews("home");
            Assert.AreEqual(2, files.Count);
            Assert.That(files.Any(f => Path.GetFileName(f) == "Index.spark"));
            Assert.That(files.Any(f => Path.GetFileName(f) == "List.spark"));
        }
        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
                          };
        }
    public ISparkViewEngine CreateViewEngine()
    {
      var settings = new SparkSettings()
        .SetPageBaseType(typeof(SparkView))
        .SetAutomaticEncoding(true)
        .AddNamespace(typeof(string).Namespace)
        .AddNamespace(typeof(Enumerable).Namespace)
        .AddNamespace(typeof(Status).Namespace)
        .AddNamespace(typeof(Run).Namespace);

      var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
      var templates = new FileSystemViewFolder(Path.Combine(dir, "Generation\\Spark\\Templates"));

      return new SparkViewEngine(settings)
             {
               ViewFolder = templates
             };
    }
Exemplo n.º 12
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);
                }
            }
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
 public void Init()
 {
     _viewFolder = new FileSystemViewFolder("Spark.Tests.Views");
 }