Skip to content

Commit

Permalink
Support passing render options to #widget.
Browse files Browse the repository at this point in the history
  • Loading branch information
John Firebaugh committed Jun 10, 2010
1 parent bec0715 commit 8d011d3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/erector/widget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ def call_block
# This is the preferred way to call one widget from inside another. This
# method assures that the same output string is used, which gives better
# performance than using +capture+ or +to_s+.
def widget(target, parameters={}, &block)
def widget(target, assigns = {}, options = {}, &block)
if target.is_a? Class
target.new(parameters, &block)._render_via(self)
target.new(assigns, &block)._render_via(self, options)
else
unless parameters.empty?
raise "Unexpected second parameter. Did you mean to pass in variables when you instantiated the #{target.class.to_s}?"
unless assigns.empty?
raise "Unexpected second parameter. Did you mean to pass in assigns when you instantiated the #{target.class.to_s}?"
end
target._render_via(self, &block)
target._render_via(self, options, &block)
end
end

Expand Down
9 changes: 9 additions & 0 deletions spec/erector/widget_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ def content
outer.output.widgets.should include(inner)
end

it "supports specifying content_method_name" do
inner = Class.new(Erector::Widget) do
def foo; text "foo"; end
end
erector do
widget inner, {}, :content_method_name => :foo
end.should == "foo"
end

it "renders nested widgets in the correct order" do
class Parent < Erector::Widget
def content
Expand Down

0 comments on commit 8d011d3

Please sign in to comment.