Execute() public method

public Execute ( ) : TinySite.Models.SiteConfig
return TinySite.Models.SiteConfig
Ejemplo n.º 1
0
        public void CanGetDefaultLayout()
        {
            var command = new LoadSiteConfigCommand() { ConfigPath = "data\\site.config" };
            var config = command.Execute();

            var site = new Site(config, Enumerable.Empty<DataFile>(), Enumerable.Empty<DocumentFile>(), Enumerable.Empty<StaticFile>(), Enumerable.Empty<LayoutFile>());

            Assert.Equal("test", site.DefaultLayoutForExtension["html"]);
        }
Ejemplo n.º 2
0
        public void CanGetFullUrlFromData()
        {
            var command = new LoadSiteConfigCommand() { ConfigPath = "data\\site.config" };
            var config = command.Execute();
            var site = new Site(config, Enumerable.Empty<DataFile>(), Enumerable.Empty<DocumentFile>(), Enumerable.Empty<StaticFile>(), Enumerable.Empty<LayoutFile>());

            dynamic data = site; //site.GetAsDynamic();

            Assert.Equal("http://www.example.com/blog/", data.FullUrl);
        }
Ejemplo n.º 3
0
        public void CanGetTitle()
        {
            var command = new LoadSiteConfigCommand() { ConfigPath = "data\\site.config" };
            var config = command.Execute();

            var site = new Site(config, Enumerable.Empty<DataFile>(), Enumerable.Empty<DocumentFile>(), Enumerable.Empty<StaticFile>(), Enumerable.Empty<LayoutFile>());

            dynamic data = new DynamicSite(null, site);

            Assert.Equal("Test Blog.", (string)data.tiTle);
        }
Ejemplo n.º 4
0
        public void CanGetFilesToIgnore()
        {
            //TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
            var dataFolder = Path.GetFullPath(@"data\");

            var command = new LoadSiteConfigCommand() { ConfigPath = dataFolder + "site.config" };
            var config = command.Execute();

            Assert.Equal(2, config.IgnoreFiles.Count());

            var match = config.IgnoreFiles.First();
            Assert.True(match.IsMatch("foo.abc~"));
            Assert.True(match.IsMatch("a.b~"));
            Assert.False(match.IsMatch("foo.abc"));
            Assert.False(match.IsMatch("a.b"));

            match = config.IgnoreFiles.Skip(1).Single();
            Assert.True(match.IsMatch("bar.tmp"));
            Assert.True(match.IsMatch("foo.TMP"));
        }
Ejemplo n.º 5
0
        private SiteConfig LoadConfig(string sitePath, string outputPath)
        {
            using (var capture = Statistics.Current.Start(StatisticTiming.LoadedConfiguration))
            {
                var configPath = Path.Combine(sitePath, "site.json");
                if (!File.Exists(configPath))
                {
                    configPath = Path.Combine(sitePath, "site.config");
                }

                var command = new LoadSiteConfigCommand();
                command.ConfigPath = configPath;
                command.OutputPath = outputPath;
                return command.Execute();
            }
        }
Ejemplo n.º 6
0
        public SiteConfig Execute()
        {
            var root = Path.GetFullPath(Path.GetDirectoryName(this.ConfigPath));

            var settings = new JsonSerializerSettings();
            settings.Converters.Add(new JsonTimeZoneConverter());

            string json;
            using (var reader = new StreamReader(this.ConfigPath))
            {
                json = reader.ReadToEnd();
            }

            var config = new SiteConfig();
            config.Parent = this.Parent;

            var ignoreFiles = new string[0];
            var subsites = new string[0];

            //var config = JsonConvert.DeserializeObject<SiteConfig>(json, settings);
            foreach (var token in JObject.Parse(json))
            {
                var key = token.Key.ToLowerInvariant();
                var value = token.Value;

                switch (key)
                {
                    case "author":
                        config.Author = value.ToObject<Author>();
                        break;

                    case "output":
                    case "outputpath":
                        config.OutputPath = Path.Combine(root, (string)value).Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar).EnsureBackslashTerminated();
                        break;

                    case "url":
                        config.Url = (string)value;
                        break;

                    case "rooturl":
                        config.RootUrl = (string)value;
                        break;

                    case "subsites":
                        subsites = value.Values<string>().ToArray();
                        break;

                    case "additionalmetadata":
                        config.AdditionalMetadataForFiles = this.ParseAdditionalMetadata(value).ToList();
                        break;

                    case "defaultlayoutforextension":
                        this.AssignDefaultLayouts(config, value);
                        break;

                    case "ignorefiles":
                        config.IgnoreFiles = this.ParseIgnoreFiles(value.Values<string>()).ToArray();
                        break;

                    default:
                        config.Metadata.Add(key, value);
                        break;
                }
            }

            config.SitePath = root;
            config.DataPath = Path.Combine(root, "data\\");
            config.DocumentsPath = Path.Combine(root, "documents\\");
            config.FilesPath = Path.Combine(root, "files\\");
            config.LayoutsPath = Path.Combine(root, "layouts\\");

            config.OutputPath = config.OutputPath ?? Path.Combine(root, "build\\");
            config.Url = config.Url.EnsureStartsWith("/");
            config.RootUrl = config.RootUrl ?? "http://localhost/";

            // If override output path was provided use that.
            config.OutputPath = String.IsNullOrEmpty(this.OutputPath) ? Path.GetFullPath(config.OutputPath) : Path.GetFullPath(this.OutputPath);

            var siteConfigs = new List<SiteConfig>(subsites.Length);

            foreach (var subsite in subsites)
            {
                var command = new LoadSiteConfigCommand();
                command.Parent = config;
                command.ConfigPath = Path.Combine(root, subsite);
                var subsiteConfig = command.Execute();

                siteConfigs.Add(subsiteConfig);
            }

            config.SubsiteConfigs = siteConfigs.ToArray();

            return this.SiteConfig = config;
        }
Ejemplo n.º 7
0
        public void CanLoadWithAdditionalMetadata()
        {
            var dataFolder = Path.GetFullPath(@"data\additional-metadata\");
            var outputPath = Path.GetFullPath("output");

            var loadConfig = new LoadSiteConfigCommand() { ConfigPath = dataFolder + "site.json" };
            var config = loadConfig.Execute();

            var loadData = new LoadDataFilesCommand(config.DataPath, config.AdditionalMetadataForFiles, config.IgnoreFiles);
            loadData.Execute();

            var loadDocuments = new LoadDocumentsCommand();
            loadDocuments.Author = new Author();
            loadDocuments.DocumentsPath = config.DocumentsPath;
            loadDocuments.OutputRootPath = config.OutputPath;
            loadDocuments.AdditionalMetadataForFiles = config.AdditionalMetadataForFiles;
            loadDocuments.IgnoreFiles = config.IgnoreFiles;
            loadDocuments.RenderedExtensions = new[] { "md" };
            loadDocuments.RootUrl = config.RootUrl;
            loadDocuments.ApplicationUrl = config.Url;
            loadDocuments.Execute();

            var data = loadData.DataFiles.Single();
            var document = loadDocuments.Documents.Single();

            Assert.Equal("bar", data.Metadata.Get<string>("foo"));
            Assert.Equal("quux", document.Metadata.Get<string>("baz"));
        }
Ejemplo n.º 8
0
        public void CanLoadSiteConfig()
        {
            //TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
            var dataFolder = Path.GetFullPath(@"data\");

            var command = new LoadSiteConfigCommand() { ConfigPath = dataFolder + "site.config" };
            var config = command.Execute();

            Assert.Empty(config.SubsiteConfigs);
            Assert.Equal(dataFolder + @"build\here\", config.OutputPath);
            //Assert.Equal(tzi, config.TimeZone);
        }
Ejemplo n.º 9
0
        public void CanLoadSiteConfigWithSubsites()
        {
            TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
            var dataFolder = Path.GetFullPath(@"data\");

            var command = new LoadSiteConfigCommand() { ConfigPath = dataFolder + "parent.config" };
            var config = command.Execute();

            Assert.Equal(dataFolder + @"parent_build\", config.OutputPath);
            Assert.NotEmpty(config.SubsiteConfigs);
            Assert.Equal(1, config.SubsiteConfigs.Length);
            foreach (var subsite in config.SubsiteConfigs)
            {
                Assert.Equal(config, subsite.Parent);
            }
        }