Skip to content

Commit

Permalink
Merge remote-tracking branches 'tcrayford/new_content_for' and 'tcray…
Browse files Browse the repository at this point in the history
…ford/faster_layout_rendering'

Conflicts:
	lib/raptor/templates.rb
	spec/template_spec.rb
  • Loading branch information
garybernhardt committed Apr 24, 2012
2 parents 01c0e2e + 23c653d commit 33ffbca
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
18 changes: 11 additions & 7 deletions lib/raptor/templates.rb
Expand Up @@ -7,9 +7,9 @@ def self.find(path)
in_same_dir = File.join('views', path, LAYOUT_FILENAME)
in_root_dir = File.join('views', LAYOUT_FILENAME)
if File.exist?(in_same_dir)
Layout.new(in_same_dir)
Layout.from_path(in_same_dir)
elsif File.exist?(in_root_dir)
Layout.new(in_root_dir)
Layout.from_path(in_root_dir)
else
NullLayout
end
Expand All @@ -23,20 +23,24 @@ def self.render(inner, presenter)
end

class Layout
attr_reader :path
def initialize(path)
@path = path
attr_reader :tilt
def initialize(tilt)
@tilt = tilt
end

def self.from_path(path)
new(Tilt.new(path))
end

def ==(other)
other.is_a?(Layout) &&
other.path == path
other.tilt == tilt
end

def render(inner, presenter)
context = ViewContext.new(presenter)
rendered = inner.render(context)
Tilt.new(@path).render(context) { rendered }
@tilt.render(context) { rendered }
end
end

Expand Down
11 changes: 9 additions & 2 deletions spec/template_spec.rb
Expand Up @@ -26,16 +26,17 @@

describe Raptor::Layout do
let(:presenter) { stub }

it "renders a yielded template" do
inner = stub(:render => 'inner')
rendered = Raptor::Layout.new('spec/fixtures/layout.html.erb').
rendered = Raptor::Layout.from_path('spec/fixtures/layout.html.erb').
render(inner, presenter)
rendered.strip.should == "<div>inner</div>"
end

it "integrates content_for" do
inner = Raptor::Template.from_path("../spec/fixtures/provides_content_for.html.erb")
layout = Raptor::Layout.new('spec/fixtures/layout_with_content_for.html.erb')
layout = Raptor::Layout.from_path('spec/fixtures/layout_with_content_for.html.erb')
rendered = layout.render(inner, presenter)
rendered.strip.should include("<script></script")
end
Expand All @@ -61,6 +62,12 @@
end

describe Raptor::FindsLayouts do
before do
Tilt.stub(:new) do |path|
path
end
end

it "finds a layout in the path directory" do
path = 'views/post/layout.html.erb'
File.stub(:exist?).with(path) { true }
Expand Down
Empty file added views/ping/layout.html.erb
Empty file.

0 comments on commit 33ffbca

Please sign in to comment.