From 035611fb9f88755d3b053ceecda13806dbfe1c73 Mon Sep 17 00:00:00 2001 From: Damian Karzon Date: Thu, 2 Apr 2015 11:34:28 +1300 Subject: [PATCH 1/3] Better support for exclude config setting --- .../Templating/Context/SiteContextGenerator.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs b/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs index 2d31d7522..aad25ce53 100644 --- a/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs +++ b/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs @@ -59,6 +59,10 @@ public SiteContext BuildContext(string path, string destinationPath, bool includ } } } + if (config.ContainsKey("exclude")) + { + excludes.AddRange((IEnumerable)config["exclude"]); + } var context = new SiteContext { @@ -193,9 +197,14 @@ private bool ContainsYamlFrontMatter(string file) return postFirstLine != null && postFirstLine.StartsWith("---"); } + private bool IsExcludedPath(string relativePath) + { + return excludes.Contains(relativePath) || excludes.Any(e => relativePath.StartsWith(e)); + } + public bool CanBeIncluded(string relativePath) { - if (excludes.Count > 0 && excludes.Contains(relativePath)) + if (excludes.Count > 0 && IsExcludedPath(relativePath)) { return false; } From 5317500e0270d7777ee0d9b3a64a98ad4cc80cf8 Mon Sep 17 00:00:00 2001 From: Damian Karzon Date: Sun, 5 Apr 2015 17:14:42 +1200 Subject: [PATCH 2/3] Update include and exclude to be root config settings --- .../Templating/Context/SiteContextGenerator.cs | 15 ++------------- .../Context/SiteContextGeneratorTests.cs | 12 +++++------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs b/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs index aad25ce53..0a307999b 100644 --- a/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs +++ b/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs @@ -44,20 +44,9 @@ public SiteContext BuildContext(string path, string destinationPath, bool includ if (!config.ContainsKey("permalink")) config.Add("permalink", "/:year/:month/:day/:title.html"); - if (config.ContainsKey("pretzel")) + if (config.ContainsKey("include")) { - var pretzelSettings = config["pretzel"] as Dictionary; - if (pretzelSettings != null) - { - if (pretzelSettings.ContainsKey("include") && includes.Count == 0) - { - includes.AddRange((IEnumerable)pretzelSettings["include"]); - } - if (pretzelSettings.ContainsKey("exclude") && excludes.Count == 0) - { - excludes.AddRange((IEnumerable)pretzelSettings["exclude"]); - } - } + includes.AddRange((IEnumerable)config["include"]); } if (config.ContainsKey("exclude")) { diff --git a/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs b/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs index 18dad65fe..3be2b9ef4 100644 --- a/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs +++ b/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs @@ -420,8 +420,7 @@ public void CanBeIncluded_Scenarios_Include() // arrange Func function = generator.CanBeIncluded; fileSystem.AddFile(@"C:\TestSite\_config.yml", new MockFileData(@"--- -pretzel: - include: [_folder, .something-else, some-file.tmp, test\somefile.txt, subfolder\childfolder, anotherfolder\tempfile.tmp] +include: [_folder, .something-else, some-file.tmp, test\somefile.txt, subfolder\childfolder, anotherfolder\tempfile.tmp] ---")); // act var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); @@ -450,14 +449,14 @@ public void CanBeIncluded_Scenarios_Exclude() // arrange Func function = generator.CanBeIncluded; fileSystem.AddFile(@"C:\TestSite\_config.yml", new MockFileData(@"--- -pretzel: - exclude: [folder, .htaccess, some-file.tmp, test\somefile.txt, subfolder\childfolder, anotherfolder\tempfile.tmp] +exclude: [folder, .htaccess, some-file.tmp, test\somefile.txt, subfolder\childfolder, anotherfolder\tempfile.tmp] ---")); // act var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); // assert Assert.False(function("folder")); + Assert.False(function("folder\file.txt")); Assert.False(function("_folder")); // .htaccess is excluded @@ -480,9 +479,8 @@ public void CanBeIncluded_Scenarios_IncludeExclude() // arrange Func function = generator.CanBeIncluded; fileSystem.AddFile(@"C:\TestSite\_config.yml", new MockFileData(@"--- -pretzel: - include: [_folder, .something-else] - exclude: [folder, test\somefile.txt] +include: [_folder, .something-else] +exclude: [folder, test\somefile.txt] ---")); // act var siteContext = generator.BuildContext(@"C:\TestSite", @"C:\TestSite\_site", false); From 10cb37246cecb64d132d67cd55bb3a1d5c8085e1 Mon Sep 17 00:00:00 2001 From: Damian Karzon Date: Fri, 10 Apr 2015 14:04:21 +1200 Subject: [PATCH 3/3] Added support for folder includes --- .../Templating/Context/SiteContextGenerator.cs | 7 ++++++- .../Templating/Context/SiteContextGeneratorTests.cs | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs b/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs index 0a307999b..c292203b4 100644 --- a/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs +++ b/src/Pretzel.Logic/Templating/Context/SiteContextGenerator.cs @@ -191,6 +191,11 @@ private bool IsExcludedPath(string relativePath) return excludes.Contains(relativePath) || excludes.Any(e => relativePath.StartsWith(e)); } + private bool IsIncludedPath(string relativePath) + { + return includes.Contains(relativePath) || includes.Any(e => relativePath.StartsWith(e)); + } + public bool CanBeIncluded(string relativePath) { if (excludes.Count > 0 && IsExcludedPath(relativePath)) @@ -198,7 +203,7 @@ public bool CanBeIncluded(string relativePath) return false; } - if (includes.Count > 0 && includes.Contains(relativePath)) + if (includes.Count > 0 && IsIncludedPath(relativePath)) { return true; } diff --git a/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs b/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs index 3be2b9ef4..506227f5c 100644 --- a/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs +++ b/src/Pretzel.Tests/Templating/Context/SiteContextGeneratorTests.cs @@ -438,6 +438,8 @@ public void CanBeIncluded_Scenarios_Include() Assert.False(function("some-file.TMP")); Assert.True(function("another-file.bar")); + Assert.True(function("_folder\file.txt")); + Assert.True(function(@"test\somefile.txt")); Assert.True(function(@"subfolder\childfolder")); Assert.True(function(@"anotherfolder\tempfile.tmp"));