From fcde83431e9389b57ede544bffd368e1301651e5 Mon Sep 17 00:00:00 2001 From: ashmaroli Date: Thu, 15 Jun 2017 01:08:38 +0530 Subject: [PATCH] Address reading non-binary static files in themes (#5918) Merge pull request 5918 --- features/theme.feature | 11 +++++++++++ lib/jekyll/readers/theme_assets_reader.rb | 2 +- test/fixtures/test-theme/assets/base.js | 1 + test/source/assets/base.js | 1 + test/test_theme_assets_reader.rb | 11 ++++++++--- 5 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/test-theme/assets/base.js create mode 100644 test/source/assets/base.js diff --git a/features/theme.feature b/features/theme.feature index 820283e8..650c1675 100644 --- a/features/theme.feature +++ b/features/theme.feature @@ -46,6 +46,17 @@ Feature: Writing themes And I should see "default.html from test-theme: I'm content." in "_site/index.html" And I should see "post.html from the project: I'm more content." in "_site/post.html" + Scenario: A theme with assets + Given I have a configuration file with "theme" set to "test-theme" + And I have an assets directory + And I have an "assets/application.coffee" file that contains "From your site." + And I have an "assets/base.js" file that contains "From your site." + When I run jekyll build + Then I should get a zero exit status + And the _site directory should exist + And I should see "From your site." in "_site/assets/application.coffee" + And I should see "From your site." in "_site/assets/base.js" + Scenario: Requiring dependencies of a theme Given I have a configuration file with "theme" set to "test-dependency-theme" When I run jekyll build diff --git a/lib/jekyll/readers/theme_assets_reader.rb b/lib/jekyll/readers/theme_assets_reader.rb index 035c0607..80a6547d 100644 --- a/lib/jekyll/readers/theme_assets_reader.rb +++ b/lib/jekyll/readers/theme_assets_reader.rb @@ -29,7 +29,7 @@ module Jekyll Jekyll::Page.new(site, base, dir, name) else append_unless_exists site.static_files, - Jekyll::StaticFile.new(site, base, dir, name) + Jekyll::StaticFile.new(site, base, "/#{dir}", name) end end diff --git a/test/fixtures/test-theme/assets/base.js b/test/fixtures/test-theme/assets/base.js new file mode 100644 index 00000000..00c238ed --- /dev/null +++ b/test/fixtures/test-theme/assets/base.js @@ -0,0 +1 @@ +alert("From your theme."); diff --git a/test/source/assets/base.js b/test/source/assets/base.js new file mode 100644 index 00000000..40e8a468 --- /dev/null +++ b/test/source/assets/base.js @@ -0,0 +1 @@ +alert("From your site."); diff --git a/test/test_theme_assets_reader.rb b/test/test_theme_assets_reader.rb index fc335248..8d792f73 100644 --- a/test/test_theme_assets_reader.rb +++ b/test/test_theme_assets_reader.rb @@ -27,7 +27,7 @@ class TestThemeAssetsReader < JekyllUnitTest should "read all assets" do @site.reset ThemeAssetsReader.new(@site).read - assert_file_with_relative_path @site.static_files, "assets/img/logo.png" + assert_file_with_relative_path @site.static_files, "/assets/img/logo.png" assert_file_with_relative_path @site.pages, "assets/style.scss" end @@ -45,8 +45,13 @@ class TestThemeAssetsReader < JekyllUnitTest @site.read file = @site.pages.find { |f| f.relative_path == "assets/application.coffee" } + static_script = File.read( + @site.static_files.find { |f| f.relative_path == "/assets/base.js" }.path + ) refute_nil file + refute_nil static_script assert_includes file.content, "alert \"From your site.\"" + assert_includes static_script, "alert(\"From your site.\");" end end @@ -55,7 +60,7 @@ class TestThemeAssetsReader < JekyllUnitTest site = fixture_site("theme" => "test-theme") allow(site.theme).to receive(:assets_path).and_return(nil) ThemeAssetsReader.new(site).read - refute_file_with_relative_path site.static_files, "assets/img/logo.png" + refute_file_with_relative_path site.static_files, "/assets/img/logo.png" refute_file_with_relative_path site.pages, "assets/style.scss" end end @@ -64,7 +69,7 @@ class TestThemeAssetsReader < JekyllUnitTest should "not read any assets" do site = fixture_site("theme" => nil) ThemeAssetsReader.new(site).read - refute_file_with_relative_path site.static_files, "assets/img/logo.png" + refute_file_with_relative_path site.static_files, "/assets/img/logo.png" refute_file_with_relative_path site.pages, "assets/style.scss" end end