Example #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();
        }
        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);
        }
Example #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());
        }
Example #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;
            }
        }
Example #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);
            }
        }
        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);
        }
Example #7
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());
 }
Example #8
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());
 }