예제 #1
0
        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");
        }
예제 #2
0
        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>());
        }
예제 #3
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);
        }
예제 #4
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)
            {
                var path = Path.Combine(currentDirectory, includeDir);
                viewFolder = new CombinedViewFolder(viewFolder, new FileSystemViewFolder(path));
                foreach (var file in Directory.EnumerateFiles(path, "*.dll"))
                {
                    try
                    {
                        Assembly.LoadFile(file);
                    }
                    catch
                    {
                    }
                }
            }

            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.SakeSettings = _settings;
            builder.Render();
            return(builder);
        }
예제 #5
0
        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"));
        }
예제 #6
0
        public void OpenFromFirstViewFolder()
        {
            var first = new InMemoryViewFolder {
                { "one.txt", "one" }
            };
            var second = new InMemoryViewFolder {
                { "one.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);
            }
        }
예제 #7
0
        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());
        }