Beispiel #1
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;
        }
        public void HasTemplate()
        {
            var first = new InMemoryViewFolder { { "one.txt", "one" } };
            var second = new InMemoryViewFolder { { "two.txt", "two" } };
            var viewFolder = new CombinedViewFolder(first, second);

            Assert.IsTrue(viewFolder.HasView("one.txt"));
            Assert.IsTrue(viewFolder.HasView("two.txt"));
            Assert.IsFalse(viewFolder.HasView("three.txt"));
        }
        public void ListFilesWithDedupe()
        {
            var first = new InMemoryViewFolder { { "home\\three.txt", "three" }, { "home\\one.txt", "one" } };
            var second = new InMemoryViewFolder { { "home\\two.txt", "two" }, { "home\\three.txt", "three" } };
            var viewFolder = new CombinedViewFolder(first, second);

            var views = viewFolder.ListViews("home");
            Assert.AreEqual(3, views.Count);
            Assert.Contains("home\\one.txt", views.ToArray());
            Assert.Contains("home\\two.txt", views.ToArray());
            Assert.Contains("home\\three.txt", views.ToArray());
        }
Beispiel #4
0
        public void SharingExtraFolders()
        {
            var normal = new FileSystemViewFolder("Spark.Tests.Views");
            var otherLocation = new FileSystemViewFolder("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);
        }
        public void OpenFileStream()
        {
            var first = new InMemoryViewFolder { { "one.txt", "one" } };
            var second = new InMemoryViewFolder { { "two.txt", "two" } };
            var viewFolder = new CombinedViewFolder(first, second);

            using (var reader = new StreamReader(viewFolder.GetViewSource("one.txt").OpenViewStream()))
            {
                var content = reader.ReadToEnd();
                Assert.AreEqual("one", content);
            }

            using (var reader = new StreamReader(viewFolder.GetViewSource("two.txt").OpenViewStream()))
            {
                var content = reader.ReadToEnd();
                Assert.AreEqual("two", content);
            }
        }
        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;
        }
        public void OpenMissingFile()
        {
            var first = new InMemoryViewFolder { { "one.txt", "one" } };
            var second = new InMemoryViewFolder { { "two.txt", "two" } };
            var viewFolder = new CombinedViewFolder(first, second);

            viewFolder.GetViewSource("three.txt");
        }
        public void OpenMissingFile()
        {
            var first = new InMemoryViewFolder { { "one.txt", "one" } };
            var second = new InMemoryViewFolder { { "two.txt", "two" } };
            var viewFolder = new CombinedViewFolder(first, second);

            Assert.That(() => viewFolder.GetViewSource("three.txt"), Throws.TypeOf<FileNotFoundException>());
        }