Skip to content
Browse files

make sure the scope is passed through to the layout template too and …

…not just the template being rendered
  • Loading branch information...
1 parent a361124 commit bc5cc2e35d69f003d46a8e3bc029fb06dad1f2d8 @AndrewVos committed Aug 28, 2011
Showing with 14 additions and 4 deletions.
  1. +8 −3 features/templates.feature
  2. +1 −1 lib/oni/template.rb
  3. +5 −0 spec/oni/template_spec.rb
View
11 features/templates.feature
@@ -19,6 +19,7 @@ Feature: Templates
attr_reader :value
def get
@value = "the value of value"
+ render :index
end
end
Oni::Routes.route "/value_controller", ValueReturnerController
@@ -41,15 +42,19 @@ Feature: Templates
Scenario: Templates can see the controller binding
Given I have the template "layout.haml" with the contents:
"""
+ = "The layout can see the controller binding: " + value
= yield
"""
And I have the template "index.haml" with the contents:
"""
- HAML Template Title
- = value
+ = "And so can the template: " + value
"""
When I visit "/value_controller"
- Then I should see "the value of value"
+ Then I should see
+ """
+ The layout can see the controller binding: the value of value
+ And so can the template: the value of value
+ """
Scenario: Template without a layout
Given I have the template "layout.haml" with the contents:
View
2 lib/oni/template.rb
@@ -20,7 +20,7 @@ def render scope, options = {}
layout = Dir.glob("templates/#{options[:layout]}.*").first
end
if layout
- rendered = Tilt.new(layout).render { rendered }
+ rendered = Tilt.new(layout).render(scope) { rendered }
end
end
View
5 spec/oni/template_spec.rb
@@ -59,6 +59,11 @@ module Oni
Template.new(:index).render(nil).body.should == "layout with something inside"
end
+ it "passes the scope through to the layout template" do
+ layout_tilt.should_receive(:render).with("scope")
+ Template.new(:index).render("scope")
+ end
+
context "with the template option turned off" do
it "does not render the template inside the layout template" do
layout_tilt.should_not_receive(:render)

0 comments on commit bc5cc2e

Please sign in to comment.
Something went wrong with that request. Please try again.