diff --git a/lib/jekyll/layout_reader.rb b/lib/jekyll/layout_reader.rb index 1b07c724..66854339 100644 --- a/lib/jekyll/layout_reader.rb +++ b/lib/jekyll/layout_reader.rb @@ -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 diff --git a/test/test_layout_reader.rb b/test/test_layout_reader.rb index eead655a..ff979c2b 100644 --- a/test/test_layout_reader.rb +++ b/test/test_layout_reader.rb @@ -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