Permalink
Browse files

Support passing render options to #widget.

  • Loading branch information...
1 parent bec0715 commit 8d011d34e3ee4d32869fb08173205675bb9f1c6c John Firebaugh committed Jun 10, 2010
Showing with 14 additions and 5 deletions.
  1. +5 −5 lib/erector/widget.rb
  2. +9 −0 spec/erector/widget_spec.rb
View
10 lib/erector/widget.rb
@@ -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
View
9 spec/erector/widget_spec.rb
@@ -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

0 comments on commit 8d011d3

Please sign in to comment.