Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Correctly search the root directory for layouts.

Closes #72.
  • Loading branch information...
commit 4f35e864222260fa80d05e16f8dc81321239f531 1 parent 5e63daf
@ntalbott ntalbott authored
View
5 lib/serve/pipeline.rb
@@ -23,7 +23,7 @@ def find_layout_for(template_path)
root = @root_path
path = template_path[root.size..-1]
layout = nil
- until(layout || ["/", ""].include?(path))
+ until(layout || path == "")
possible_layouts = FileTypeHandler.extensions.map do |ext|
l = "_layout.#{ext}"
possible_layout = File.join(root, path, l)
@@ -48,8 +48,9 @@ def process(request, response)
end
class Template
- attr_reader :path, :handlers
+ attr_reader :file, :path, :handlers
def initialize(file)
+ @file = File.basename(file)
@path = File.dirname(file)
@raw = File.read(file)
@handlers = FileTypeHandler.handlers_for(file).collect{|h, extension| h.new(@root_path, @path, extension)}
View
3  spec/fixtures/directory/_layout.erb
@@ -0,0 +1,3 @@
+<h1>Awesomesacue</h1>
+
+<%= yield %>
View
1  spec/fixtures/directory/subdirectory/test.erb
@@ -0,0 +1 @@
+Test
View
8 spec/pipeline_spec.rb
@@ -55,5 +55,13 @@
pipeline = Serve::Pipeline.new(@root, "file.erb")
pipeline.layout.should be_passthrough
end
+
+ it "should search up the directory tree for layouts" do
+ root = File.join(@root, "directory")
+ pipeline = Serve::Pipeline.new(root, "subdirectory/test.erb")
+ pipeline.layout.should_not be_passthrough
+ pipeline.layout.path.should == root
+ pipeline.layout.file.should == "_layout.erb"
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.