예제 #1
0
        public void LoadSimpleFile()
        {
            ExpectGetChunks("home\\simple.spark", new SendLiteralChunk());
            viewFolder.Stub(x => x.HasView("home\\_global.spark")).Return(false);
            viewFolder.Stub(x => x.HasView("Shared\\_global.spark")).Return(false);

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

            viewFolder.VerifyAllExpectations();
            syntaxProvider.VerifyAllExpectations();

            Assert.AreEqual(1, chunks.Count());
            Assert.AreEqual(1, loader.GetEverythingLoaded().Count());
        }
예제 #2
0
        public IList <string> GetGlobalVariables()
        {
            var masterFiles = new List <string>();

            GetMasterFiles(MasterFolderTypes.Shared, masterFiles);
            GetMasterFiles(MasterFolderTypes.Layouts, masterFiles);

            _viewLoader.Load(_viewPath);
            masterFiles.ToList().ForEach(filePath =>
            {
                var type = filePath.Contains(MasterFolderTypes.Shared.ToString()) ? MasterFolderTypes.Shared : MasterFolderTypes.Layouts;
                _viewLoader.Load(filePath.Substring(filePath.LastIndexOf(type.ToString())));
            });

            var globalVariables = new List <string>();
            var chunkLists      = _viewLoader.GetEverythingLoaded();

            chunkLists.ToList().ForEach(list =>
            {
                var globals = list.Where(chunk => chunk is GlobalVariableChunk);
                globals.ToList().ForEach(globalVar => globalVariables.Add(((GlobalVariableChunk)globalVar).Name));
            });

            return(globalVariables);
        }
예제 #3
0
        private IEnumerable <T> GetAllChunks <T>()
        {
            LoadChunks(_viewPath);
            var allChunks =
                _viewLoader.GetEverythingLoaded()
                .SelectMany(list => list)
                .Where(chunk => chunk is T).Cast <T>();

            return(allChunks);
        }
예제 #4
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());
        }
예제 #5
0
        public void LoadingPartialInsideNamedSection()
        {
            var viewFolder = new InMemoryViewFolder
            {
                { "home\\index.spark", "<for each='var x in new[]{1,2,3}'><Guts><section:foo><Another/></section:foo></Guts></for>" },
                { "home\\_Guts.spark", "<div><render:foo/></div>" },
                { "home\\_Another.spark", "<p>hello world</p>" }
            };
            var viewLoader = new ViewLoader {
                SyntaxProvider = new DefaultSyntaxProvider(ParserSettings.DefaultBehavior), ViewFolder = viewFolder
            };
            var chunks     = viewLoader.Load("home\\index.spark");
            var everything = viewLoader.GetEverythingLoaded();

            Assert.AreEqual(3, everything.Count());
        }