ThemeAssetsReader: fix tests so everything passes.
This commit is contained in:
parent
6d7f305e7c
commit
74baeb889a
|
@ -16,7 +16,7 @@ Lint/UnreachableCode:
|
|||
Lint/UselessAccessModifier:
|
||||
Enabled: false
|
||||
Metrics/AbcSize:
|
||||
Max: 20
|
||||
Max: 21
|
||||
Metrics/ClassLength:
|
||||
Exclude:
|
||||
- !ruby/regexp /features\/.*.rb$/
|
||||
|
|
|
@ -17,7 +17,7 @@ Feature: Writing themes
|
|||
Scenario: A theme with SCSS
|
||||
Given I have a configuration file with "theme" set to "test-theme"
|
||||
And I have a css directory
|
||||
And I have a "css/main.scss" page that contains "@import 'style';"
|
||||
And I have a "css/main.scss" page that contains "@import 'test-theme-black';"
|
||||
When I run jekyll build
|
||||
Then I should get a zero exit status
|
||||
And the _site directory should exist
|
||||
|
|
|
@ -40,11 +40,11 @@ module Jekyll
|
|||
@base = base
|
||||
@dir = dir
|
||||
@name = name
|
||||
if site.in_theme_dir(base) == base # we're in a theme
|
||||
@path = site.in_theme_dir(base, dir, name)
|
||||
else
|
||||
@path = site.in_source_dir(base, dir, name)
|
||||
end
|
||||
@path = if site.in_theme_dir(base) == base # we're in a theme
|
||||
site.in_theme_dir(base, dir, name)
|
||||
else
|
||||
site.in_source_dir(base, dir, name)
|
||||
end
|
||||
|
||||
process(name)
|
||||
read_yaml(File.join(base, dir), name)
|
||||
|
|
|
@ -13,19 +13,35 @@ module Jekyll
|
|||
if File.symlink?(path)
|
||||
Jekyll.logger.warn "Theme reader:", "Ignored symlinked asset: #{path}"
|
||||
else
|
||||
base = site.theme.root
|
||||
dir = File.dirname(path.sub("#{site.theme.root}/", ""))
|
||||
name = File.basename(path)
|
||||
relative_path = File.join(*[dir, name].compact)
|
||||
if Utils.has_yaml_header?(path)
|
||||
next if site.pages.any? { |file| file.relative_path == relative_path }
|
||||
site.pages << Jekyll::Page.new(site, base, dir, name)
|
||||
else
|
||||
next if site.static_files.any? { |file| file.relative_path == relative_path }
|
||||
site.static_files << Jekyll::StaticFile.new(site, base, dir, name)
|
||||
end
|
||||
read_theme_asset(path)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def read_theme_asset(path)
|
||||
base = site.theme.root
|
||||
dir = File.dirname(path.sub("#{site.theme.root}/", ""))
|
||||
name = File.basename(path)
|
||||
|
||||
if Utils.has_yaml_header?(path)
|
||||
append_unless_exists site.pages,
|
||||
Jekyll::Page.new(site, base, dir, name)
|
||||
else
|
||||
append_unless_exists site.static_files,
|
||||
Jekyll::StaticFile.new(site, base, dir, name)
|
||||
end
|
||||
end
|
||||
|
||||
def append_unless_exists(haystack, new_item)
|
||||
if haystack.any? { |file| file.relative_path == new_item.relative_path }
|
||||
Jekyll.logger.debug "Theme:",
|
||||
"Ignoring #{new_item.relative_path} in theme due to existing file " \
|
||||
"with that path in site."
|
||||
return
|
||||
end
|
||||
|
||||
haystack << new_item
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
.sample {
|
||||
color: red;
|
||||
}
|
|
@ -1,3 +1,3 @@
|
|||
---
|
||||
---
|
||||
@import "test-theme-{{ site.theme-color }}";
|
||||
@import "test-theme-{{ site.theme-color | default: "red" }}";
|
||||
|
|
|
@ -37,7 +37,7 @@ class TestTheme < JekyllUnitTest
|
|||
[:assets, :_layouts, :_includes, :_sass].each do |folder|
|
||||
should "know the #{folder} path" do
|
||||
expected = File.expand_path(folder.to_s, @expected_root)
|
||||
assert_equal expected, @theme.public_send("#{folder}_path")
|
||||
assert_equal expected, @theme.public_send("#{folder.to_s.tr("_", "")}_path")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -3,22 +3,24 @@ require "helper"
|
|||
class TestThemeAssetsReader < JekyllUnitTest
|
||||
def setup
|
||||
@site = fixture_site(
|
||||
"theme" => "test-theme",
|
||||
"theme" => "test-theme",
|
||||
"theme-color" => "black"
|
||||
)
|
||||
assert @site.theme
|
||||
end
|
||||
|
||||
def assert_file_with_relative_path(haystack, relative_path)
|
||||
assert haystack.any? { |f|
|
||||
f.relative_path == relative_path
|
||||
}, "Site should read in the #{relative_path} file, but it was not found in #{haystack.inspect}"
|
||||
assert haystack.any? { |f|
|
||||
f.relative_path == relative_path
|
||||
}, "Site should read in the #{relative_path} file, " \
|
||||
"but it was not found in #{haystack.inspect}"
|
||||
end
|
||||
|
||||
def refute_file_with_relative_path(haystack, relative_path)
|
||||
refute haystack.any? { |f|
|
||||
f.relative_path == relative_path
|
||||
}, "Site should not have read in the #{relative_path} file, but it was found in #{haystack.inspect}"
|
||||
refute haystack.any? { |f|
|
||||
f.relative_path == relative_path
|
||||
}, "Site should not have read in the #{relative_path} file, " \
|
||||
"but it was found in #{haystack.inspect}"
|
||||
end
|
||||
|
||||
context "with a valid theme" do
|
||||
|
@ -55,7 +57,5 @@ class TestThemeAssetsReader < JekyllUnitTest
|
|||
refute_file_with_relative_path @site.static_files, "assets/img/logo.png"
|
||||
refute_file_with_relative_path @site.pages, "assets/style.scss"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue