Address reading non-binary static files in themes (#5918)

Merge pull request 5918
This commit is contained in:
ashmaroli 2017-06-15 01:08:38 +05:30 committed by jekyllbot
parent b0afe5125c
commit fcde83431e
5 changed files with 22 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -0,0 +1 @@
alert("From your theme.");

View File

@ -0,0 +1 @@
alert("From your site.");

View File

@ -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