From 9a5307c3f9c568dec3703a3f30e6c68f0a751597 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Mon, 16 Jan 2017 19:17:45 -0500 Subject: [PATCH 1/5] Don't include the theme's includes_path if it is nil. --- lib/jekyll/site.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 5797df77..3bbeaef3 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -435,7 +435,7 @@ module Jekyll private def configure_include_paths @includes_load_paths = Array(in_source_dir(config["includes_dir"].to_s)) - @includes_load_paths << theme.includes_path if self.theme + @includes_load_paths << theme.includes_path if self.theme && theme.includes_path end private From ad8fb9b927908f52565efbf59e3a4198bfd8c82c Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 17 Jan 2017 16:19:26 -0500 Subject: [PATCH 2/5] Add theme_dir() helper func --- test/helper.rb | 4 ++++ test/test_theme.rb | 9 ++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/test/helper.rb b/test/helper.rb index bb9e5a29..ca60f79f 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -74,6 +74,10 @@ module DirectoryHelpers test_dir("source", *subdirs) end + def theme_dir(*subdirs) + test_dir("fixtures", "test-theme", *subdirs) + end + def test_dir(*subdirs) root_dir("test", *subdirs) end diff --git a/test/test_theme.rb b/test/test_theme.rb index ab1eff43..3d557dc8 100644 --- a/test/test_theme.rb +++ b/test/test_theme.rb @@ -3,7 +3,6 @@ require "helper" class TestTheme < JekyllUnitTest def setup @theme = Theme.new("test-theme") - @expected_root = File.expand_path "./fixtures/test-theme", File.dirname(__FILE__) end context "initializing" do @@ -13,7 +12,7 @@ class TestTheme < JekyllUnitTest end should "know the theme root" do - assert_equal @expected_root, @theme.root + assert_equal theme_dir, @theme.root end should "know the theme version" do @@ -36,13 +35,13 @@ class TestTheme < JekyllUnitTest context "path generation" do [:assets, :_layouts, :_includes, :_sass].each do |folder| should "know the #{folder} path" do - expected = File.expand_path(folder.to_s, @expected_root) + expected = theme_dir(folder.to_s) assert_equal expected, @theme.public_send("#{folder.to_s.tr("_", "")}_path") end end should "generate folder paths" do - expected = File.expand_path("./_sass", @expected_root) + expected = theme_dir("_sass") assert_equal expected, @theme.send(:path_for, :_sass) end @@ -58,7 +57,7 @@ class TestTheme < JekyllUnitTest # no support for symlinks on Windows skip_if_windows "Jekyll does not currently support symlinks on Windows." - expected = File.expand_path("./_layouts", @expected_root) + expected = theme_dir("_layouts") assert_equal expected, @theme.send(:path_for, :_symlink) end end From e0d63c8aa90acd4608cfc34b2dbf2e34c6c7483f Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 17 Jan 2017 16:19:47 -0500 Subject: [PATCH 3/5] Add test to ensure that if the includes dir isn't in the theme that it won't break the site --- test/test_site.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/test_site.rb b/test/test_site.rb index bbf42d25..cee08dfd 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -49,6 +49,17 @@ class TestSite < JekyllUnitTest site = Site.new(site_configuration({ "baseurl" => "/blog" })) assert_equal "/blog", site.baseurl end + + should "only include theme includes_path if the path exists" do + site = fixture_site({ "theme" => "test-theme" }) + assert_equal [source_dir("_includes"), theme_dir("_includes")], site.includes_load_paths + + allow(File).to receive(:directory?).with(theme_dir("_sass")).and_return(true) + allow(File).to receive(:directory?).with(theme_dir("_layouts")).and_return(true) + allow(File).to receive(:directory?).with(theme_dir("_includes")).and_return(false) + site = fixture_site({ "theme" => "test-theme" }) + assert_equal [source_dir("_includes")], site.includes_load_paths + end end context "creating sites" do setup do From 023476049befdd61dd9ffabbc3e871034bc3cd9c Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 17 Jan 2017 16:21:28 -0500 Subject: [PATCH 4/5] Remove superfluous self. --- lib/jekyll/site.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/site.rb b/lib/jekyll/site.rb index 3bbeaef3..87ea719b 100644 --- a/lib/jekyll/site.rb +++ b/lib/jekyll/site.rb @@ -435,7 +435,7 @@ module Jekyll private def configure_include_paths @includes_load_paths = Array(in_source_dir(config["includes_dir"].to_s)) - @includes_load_paths << theme.includes_path if self.theme && theme.includes_path + @includes_load_paths << theme.includes_path if theme && theme.includes_path end private From 130159dda4c1c567edc7ce2104a82f0e090b7048 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 17 Jan 2017 17:05:14 -0500 Subject: [PATCH 5/5] Fix rubocop error. --- test/test_site.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_site.rb b/test/test_site.rb index cee08dfd..65032ebd 100644 --- a/test/test_site.rb +++ b/test/test_site.rb @@ -52,7 +52,8 @@ class TestSite < JekyllUnitTest should "only include theme includes_path if the path exists" do site = fixture_site({ "theme" => "test-theme" }) - assert_equal [source_dir("_includes"), theme_dir("_includes")], site.includes_load_paths + assert_equal [source_dir("_includes"), theme_dir("_includes")], + site.includes_load_paths allow(File).to receive(:directory?).with(theme_dir("_sass")).and_return(true) allow(File).to receive(:directory?).with(theme_dir("_layouts")).and_return(true)