Merge pull request #2058 from jekyll/layouts-relative-to-config

This commit is contained in:
Parker Moore 2014-02-18 01:53:15 -05:00
commit 6a6e66bf9e
2 changed files with 34 additions and 2 deletions

View File

@ -14,6 +14,10 @@ module Jekyll
@layouts
end
def layout_directory
@layout_directory ||= (layout_directory_in_cwd || layout_directory_inside_source)
end
private
def layout_entries
@ -33,8 +37,19 @@ module Jekyll
Dir.chdir(directory) { yield }
end
def layout_directory
File.join(site.source, site.config['layouts'])
def layout_directory_inside_source
# 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

View File

@ -13,5 +13,22 @@ class TestLayoutReader < Test::Unit::TestCase
layouts = LayoutReader.new(@site).read
assert_equal ["default", "simple", "post/simple"].sort, layouts.keys.sort
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