Merge pull request #2058 from jekyll/layouts-relative-to-config
This commit is contained in:
commit
6a6e66bf9e
|
@ -14,6 +14,10 @@ module Jekyll
|
||||||
@layouts
|
@layouts
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def layout_directory
|
||||||
|
@layout_directory ||= (layout_directory_in_cwd || layout_directory_inside_source)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def layout_entries
|
def layout_entries
|
||||||
|
@ -33,8 +37,19 @@ module Jekyll
|
||||||
Dir.chdir(directory) { yield }
|
Dir.chdir(directory) { yield }
|
||||||
end
|
end
|
||||||
|
|
||||||
def layout_directory
|
def layout_directory_inside_source
|
||||||
File.join(site.source, site.config['layouts'])
|
# TODO: Fix for Windows
|
||||||
|
File.join(site.source, File.expand_path(site.config['layouts'], "/"))
|
||||||
|
end
|
||||||
|
|
||||||
|
def layout_directory_in_cwd
|
||||||
|
# TODO: Fix on Windows
|
||||||
|
dir = File.join(Dir.pwd, File.expand_path(site.config['layouts'], '/'))
|
||||||
|
if File.directory?(dir)
|
||||||
|
dir
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,5 +13,22 @@ class TestLayoutReader < Test::Unit::TestCase
|
||||||
layouts = LayoutReader.new(@site).read
|
layouts = LayoutReader.new(@site).read
|
||||||
assert_equal ["default", "simple", "post/simple"].sort, layouts.keys.sort
|
assert_equal ["default", "simple", "post/simple"].sort, layouts.keys.sort
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when no _layouts directory exists in CWD" do
|
||||||
|
should "know to use the layout directory relative to the site source" do
|
||||||
|
assert_equal LayoutReader.new(@site).layout_directory, source_dir("_layouts")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when a _layouts directory exists in CWD" do
|
||||||
|
setup do
|
||||||
|
stub(File).directory? { true }
|
||||||
|
stub(Dir).pwd { source_dir("blah") }
|
||||||
|
end
|
||||||
|
|
||||||
|
should "know to use the layout directory relative to CWD" do
|
||||||
|
assert_equal LayoutReader.new(@site).layout_directory, source_dir("blah/_layouts")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue