Exemplo n.º 1
0
        public void BindingProviderIsCalledUsingTheCorrectBindingRequest()
        {
            var bindingProvider = MockRepository.GenerateMock<IBindingProvider>();
            var syntaxProvider = MockRepository.GenerateStub<ISparkSyntaxProvider>();
            var viewPath = Path.Combine("Account", "index.spark");
            var folder = new StubViewFolder { Path = viewPath, LastModified = 4 };

            bindingProvider.Expect(x => x.GetBindings(null))
                .IgnoreArguments()
                .Return(new Binding[0])
                .Callback<BindingRequest>(x => x.ViewFolder == folder && x.ViewPath == viewPath);

            syntaxProvider.Stub(x => x.GetChunks(null, null))
                .IgnoreArguments()
                .Return(new List<Chunk>());
            var viewLoader = new ViewLoader
            {
                ViewFolder = folder,
                SyntaxProvider = syntaxProvider,
                BindingProvider = bindingProvider
            };
            viewLoader.Load(viewPath);

            bindingProvider.VerifyAllExpectations();
        }
Exemplo n.º 2
0
        public void IterationInPartialFile()
        {
            var viewFolder = new InMemoryViewFolder
                                 {
                                     {"home\\index.spark", "<Guts items='new[]{1,2,3}'><section:each>${xIndex}</section:each></Guts>"},
                                     {"home\\_Guts.spark", "<for each='var x in items'><render:each/></for>"}
                                 };
            var loader = new ViewLoader { SyntaxProvider = new DefaultSyntaxProvider(ParserSettings.DefaultBehavior), ViewFolder = viewFolder };

            var chunks = loader.Load("home\\index.spark");

            var detectCode = new DetectCodeExpressionVisitor(null);
            var index = detectCode.Add("xIndex");
            var count = detectCode.Add("xCount");
            detectCode.Accept(chunks);

            Assert.IsTrue(index.Detected);
            Assert.IsFalse(count.Detected);
        }
Exemplo n.º 3
0
        public void ExpiresWhenFilesChange()
        {
            var viewFolder = new StubViewFolder { Path = Path.Combine("home", "changing.spark"), LastModified = 4 };

            var viewLoader = new ViewLoader
                             {
                                 ViewFolder = viewFolder,
                                 SyntaxProvider = MockRepository.GenerateStub<ISparkSyntaxProvider>()
                             };
            viewLoader.SyntaxProvider
                .Expect(x => x.GetChunks(null, null))
                .IgnoreArguments()
                .Return(new Chunk[0]);

            viewLoader.Load(Path.Combine("home", "changing.spark"));

            Assert.That(viewLoader.IsCurrent());

            viewFolder.LastModified = 7;
            Assert.That(!viewLoader.IsCurrent());
        }
Exemplo n.º 4
0
        void LoadTemplates(ViewLoader loader, IEnumerable<string> templates, ICollection<IList<Chunk>> chunksLoaded, ICollection<string> templatesLoaded)
        {
            foreach (var template in templates)
            {
                if (templatesLoaded.Contains(template))
                {
                    throw new CompilerException(string.Format(
                        "Unable to include template '{0}' recusively",
                        templates));
                }

                var chunks = loader.Load(template);
                chunksLoaded.Add(chunks);
                templatesLoaded.Add(template);

                var useMaster = new UseMasterVisitor();
                useMaster.Accept(chunks);
                if (useMaster.Chunk == null)
                {
                    // process next template normally
                    continue;
                }

                if (string.IsNullOrEmpty(useMaster.Chunk.Name))
                {
                    // <use master=""/> will explicitly ignore any default master layouts
                    return;
                }

                var result = TemplateLocator.LocateMasterFile(ViewFolder, useMaster.Chunk.Name);
                if (string.IsNullOrEmpty(result.Path))
                {
                    throw new CompilerException(string.Format(
                                                    "Unable to find master layout file for '{0}'", useMaster.Chunk.Name));
                }
                LoadTemplates(loader, new[] {result.Path}, chunksLoaded, templatesLoaded);

                // Explicit master templates loaded recursively. This loop is abandoned.
                return;
            }
        }
Exemplo n.º 5
0
        void LoadTemplates(ViewLoader loader, IEnumerable<string> templates, ICollection<IList<Chunk>> chunksLoaded, ICollection<string> templatesLoaded)
        {
            foreach (var template in templates)
            {
                if (templatesLoaded.Contains(template))
                {
                    throw new CompilerException(string.Format(
                        "Unable to include template '{0}' recusively",
                        templates));
                }

                var chunks = loader.Load(template);
                chunksLoaded.Add(chunks);
                templatesLoaded.Add(template);
            }
        }
Exemplo n.º 6
0
 public void Setup()
 {
     _syntaxProvider = new DefaultSyntaxProvider(new ParserSettings());
     _viewLoader = new ViewLoader { ViewFolder = new FileSystemViewFolder(ROOT_VIEW_PATH), SyntaxProvider = _syntaxProvider };
 }
Exemplo n.º 7
0
        public void ParametersInCallerBody()
        {
            var viewFolder = new InMemoryViewFolder
                                 {
                                     {"home\\index.spark", "<for each='var x in new[]{1,2,3}'><Guts>${xIndex}</Guts></for>"},
                                     {"home\\_Guts.spark", "<p><render/></p>"}
                                 };
            var loader = new ViewLoader { SyntaxProvider = new DefaultSyntaxProvider(ParserSettings.DefaultBehavior), ViewFolder = viewFolder };

            var chunks = loader.Load("home\\index.spark");

            var detectCode = new DetectCodeExpressionVisitor(null);
            var index = detectCode.Add("xIndex");
            var count = detectCode.Add("xCount");
            detectCode.Accept(chunks);

            Assert.IsTrue(index.Detected);
            Assert.IsFalse(count.Detected);
        }
Exemplo n.º 8
0
        public void PartialsInSameFolderAreDiscovered()
        {
            var viewFolder = new InMemoryViewFolder
                             {
                                 {Path.Combine("home", "zero.spark"), ""},
                                 {Path.Combine("home", "_one.spark"), ""},
                                 {Path.Combine("product", "two.spark"), ""},
                                 {Path.Combine("product", "_three.spark"), ""},
                                 {Path.Combine("product", "_four.spark"), ""},
                                 {Path.Combine("invoice", "five.spark"), ""},
                             };

            var viewLoader = new ViewLoader { ViewFolder = viewFolder };
            var zero = viewLoader.FindPartialFiles(Path.Combine("home", "zero.spark"));
            var product = viewLoader.FindPartialFiles(Path.Combine("product", "two.spark"));
            var invoice = viewLoader.FindPartialFiles(Path.Combine("invoice", "five.spark"));

            Assert.That(zero.Count(), Is.EqualTo(1));
            Assert.That(zero, Has.Some.EqualTo("one"));

            Assert.That(product.Count(), Is.EqualTo(2));
            Assert.That(product, Has.Some.EqualTo("three"));
            Assert.That(product, Has.Some.EqualTo("four"));

            Assert.That(invoice.Count(), Is.EqualTo(0));

            zero = viewLoader.FindPartialFiles("home/zero.spark");
            product = viewLoader.FindPartialFiles("product/two.spark");
            invoice = viewLoader.FindPartialFiles("invoice/five.spark");

            Assert.That(zero.Count(), Is.EqualTo(1));
            Assert.That(zero, Has.Some.EqualTo("one"));

            Assert.That(product.Count(), Is.EqualTo(2));
            Assert.That(product, Has.Some.EqualTo("three"));
            Assert.That(product, Has.Some.EqualTo("four"));

            Assert.That(invoice.Count(), Is.EqualTo(0));
        }
Exemplo n.º 9
0
        public void PartialsInCascadingBaseFoldersAndSharedFoldersAreDiscovered()
        {
            var viewFolder = new InMemoryViewFolder
                             {
                                 {Path.Combine("area1","controller2","view3.spark"), ""},
                                 {Path.Combine("area1","controller2","Shared","_alpha.spark"), ""},
                                 {Path.Combine("area1","Shared","_beta.spark"), ""},
                                 {Path.Combine("Shared", "_gamma.spark"), ""},
                                 {Path.Combine("area1","controller2","_epsilon.spark"), ""},
                                 {Path.Combine("area1", "_zeta.spark"), ""},
                                 {"_eta.spark", ""},
                                 {Path.Combine("area1","controller4","_dontfind1.spark"), ""},
                                 {Path.Combine("area1","controller4","Shared","_dontfind2.spark"), ""},
                                 {Path.Combine("area2","Shared","_dontfind3.spark"), ""},
                             };

            var viewLoader = new ViewLoader { ViewFolder = viewFolder };

            var partials = viewLoader.FindPartialFiles(Path.Combine("area1","controller2","view3.spark"));
            Assert.That(partials, Has.Some.EqualTo("alpha"));
            Assert.That(partials, Has.Some.EqualTo("beta"));
            Assert.That(partials, Has.Some.EqualTo("gamma"));
            Assert.That(partials, Has.Some.EqualTo("epsilon"));
            Assert.That(partials, Has.Some.EqualTo("zeta"));
            Assert.That(partials, Has.Some.EqualTo("eta"));
            Assert.That(partials, Has.None.EqualTo("dontfind1"));
            Assert.That(partials, Has.None.EqualTo("dontfind2"));
            Assert.That(partials, Has.None.EqualTo("dontfind3"));
        }
Exemplo n.º 10
0
 public void LoadingPartialInsideNamedSection()
 {
     var viewFolder = new InMemoryViewFolder
                          {
                              {Path.Combine("home", "index.spark"), "<for each='var x in new[]{1,2,3}'><Guts><section:foo><Another/></section:foo></Guts></for>"},
                              {Path.Combine("home", "_Guts.spark"), "<div><render:foo/></div>"},
                              {Path.Combine("home", "_Another.spark"), "<p>hello world</p>"}
                          };
     var viewLoader = new ViewLoader { SyntaxProvider = new DefaultSyntaxProvider(ParserSettings.DefaultBehavior), ViewFolder = viewFolder };
     var chunks = viewLoader.Load(Path.Combine("home", "index.spark"));
     var everything = viewLoader.GetEverythingLoaded();
     Assert.AreEqual(3, everything.Count());
 }
Exemplo n.º 11
0
        public void Init()
        {
            viewFolder = MockRepository.GenerateMock<IViewFolder>();
            viewFolder.Stub(x => x.ListViews("home")).Return(new[] { "file.spark", "other.spark", "_comment.spark" });
            viewFolder.Stub(x => x.ListViews("Home")).Return(new[] { "file.spark", "other.spark", "_comment.spark" });
            viewFolder.Stub(x => x.ListViews("Account")).Return(new[] { "index.spark" });
            viewFolder.Stub(x => x.ListViews("Shared")).Return(new[] { "layout.spark", "_header.spark", "default.spark", "_footer.spark" });
            viewFolder.Stub(x => x.ListViews("")).IgnoreArguments().Return(new string[0]);

            syntaxProvider = MockRepository.GenerateMock<ISparkSyntaxProvider>();

            loader = new ViewLoader { ViewFolder = viewFolder, SyntaxProvider = syntaxProvider };
        }
Exemplo n.º 12
0
        public void PartialsInCascadingBaseFoldersAndSharedFoldersAreDiscovered()
        {
            var viewFolder = new InMemoryViewFolder
                             {
                                 {"area1\\controller2\\view3.spark", ""},
                                 {"area1\\controller2\\Shared\\_alpha.spark", ""},
                                 {"area1\\Shared\\_beta.spark", ""},
                                 {"Shared\\_gamma.spark", ""},
                                 {"area1\\controller2\\_epsilon.spark", ""},
                                 {"area1\\_zeta.spark", ""},
                                 {"_eta.spark", ""},
                                 {"area1\\controller4\\_dontfind1.spark", ""},
                                 {"area1\\controller4\\Shared\\_dontfind2.spark", ""},
                                 {"area2\\Shared\\_dontfind3.spark", ""},
                             };

            var viewLoader = new ViewLoader { ViewFolder = viewFolder };

            var partials = viewLoader.FindPartialFiles("area1\\controller2\\view3.spark");
            Assert.That(partials, Has.Some.EqualTo("alpha"));
            Assert.That(partials, Has.Some.EqualTo("beta"));
            Assert.That(partials, Has.Some.EqualTo("gamma"));
            Assert.That(partials, Has.Some.EqualTo("epsilon"));
            Assert.That(partials, Has.Some.EqualTo("zeta"));
            Assert.That(partials, Has.Some.EqualTo("eta"));
            Assert.That(partials, Has.None.EqualTo("dontfind1"));
            Assert.That(partials, Has.None.EqualTo("dontfind2"));
            Assert.That(partials, Has.None.EqualTo("dontfind3"));
        }
Exemplo n.º 13
0
 public void LoadingEmptyShadeFile()
 {
     var viewFolder = new InMemoryViewFolder
     {
         {Path.Combine("home", "empty.shade"), ""},
     };
     var viewLoader = new ViewLoader { SyntaxProvider = new DefaultSyntaxProvider(ParserSettings.DefaultBehavior), ViewFolder = viewFolder };
     var chunks = viewLoader.Load(Path.Combine("home", "empty.shade"));
     var everything = viewLoader.GetEverythingLoaded();
     Assert.AreEqual(1, everything.Count());
 }