<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>api-announce.txt</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -193,23 +193,34 @@ module Erector
     end
 
     # To call one widget from another, inside the parent widget's write method, instantiate the child widget and call 
-    # its +write_via+ method, passing in +self+ (or self.output if you prefer). This assures that the same output string
+    # its +write_via+ method, passing in +self+. This assures that the same output string
     # is used, which gives better performance than using +capture+ or +to_s+.
-    def write_via(widget)
-      @parent = widget
-      prepare(widget.output, widget.prettyprint, widget.indentation, widget.helpers)
+    def write_via(parent)
+      @parent = parent
+      prepare(parent.output, parent.prettyprint, parent.indentation, parent.helpers)
       write
     end
 
-    # TODO: deprecate?
-    # Convenience method for on-the-fly widgets. This is a way of making
-    # a sub-widget which still has access to the methods of the parent class.
+    # Emits a (nested) widget onto the current widget's output stream. Accepts either
+    # a class or an instance. If the first argument is a class, then the second argument
+    # is a hash used to populate its instance variables. If the first argument is an 
+    # instance then the hash must be unspecified (or empty).
+    #
+    # The sub-widget will have access to the methods of the parent class, via some method_missing
+    # magic and a &quot;parent&quot; pointer.
+    #
     # This is an experimental erector feature which may disappear in future
     # versions of erector (see #widget in widget_spec in the Erector tests).
-    def widget(widget_class, assigns={}, &amp;block)
-      child = widget_class.new(assigns, &amp;block)
-      child.prepare(output, @prettyprint, @indentation, helpers)
-      child.write
+    def widget(target, assigns={}, &amp;block)
+      child = if target.is_a? Class
+        target.new(assigns, &amp;block)
+      else
+        unless assigns.empty?
+          raise &quot;Unexpected second parameter. Did you mean to pass in variables when you instantiated the #{target.class.to_s}?&quot;
+        end
+        target
+      end
+      child.write_via(self)
     end
 
     # (Should we make this hidden?)
@@ -467,6 +478,9 @@ protected
       end
       attributes ||= {}
       open_tag tag_name, attributes
+      if block &amp;&amp; value
+        raise ArgumentError, &quot;You can't pass both a block and a value to #{tag_name} -- please choose one.&quot;
+      end
       if block
         instance_eval(&amp;block)
       else</diff>
      <filename>lib/erector/widget.rb</filename>
    </modified>
    <modified>
      <diff>@@ -60,7 +60,64 @@ module WidgetSpec
       end
     end
 
+    describe '#widget' do
+      context &quot;basic nesting&quot; do
+        before do
+          class Parent &lt; Erector::Widget
+            def write
+              text 1
+              widget Child do
+                text 2
+                third
+              end
+            end
+
+            def third
+              text 3
+            end
+          end
+
+          class Child &lt; Erector::Widget
+            def write
+              super
+            end
+          end
+        end
+
+        it &quot;renders nested widgets in the correct order&quot; do
+          Parent.new.to_s.should == '123'
+        end
+      end
+      
+    end
+
     describe &quot;#widget&quot; do
+      class Orphan &lt; Erector::Widget
+        def write
+          p name
+        end
+      end
+      
+      context &quot;when passed a class&quot; do
+        it &quot;renders it&quot; do
+          Erector::Widget.new do
+            div do
+              widget Orphan, :name =&gt; &quot;Annie&quot;
+            end
+          end.to_s.should == &quot;&lt;div&gt;&lt;p&gt;Annie&lt;/p&gt;&lt;/div&gt;&quot;
+        end
+      end
+      
+      context &quot;when passed an instance&quot; do
+        it &quot;renders it&quot; do
+          Erector::Widget.new do
+            div do
+              widget Orphan.new(:name =&gt; &quot;Oliver&quot;)
+            end
+          end.to_s.should == &quot;&lt;div&gt;&lt;p&gt;Oliver&lt;/p&gt;&lt;/div&gt;&quot;
+        end
+      end
+
       context &quot;when nested&quot; do
         it &quot;renders the tag around the rest of the block&quot; do
           parent_widget = Class.new(Erector::Widget) do
@@ -584,34 +641,6 @@ module WidgetSpec
       end
     end
 
-    describe '#widget' do
-      before do
-        class Parent &lt; Erector::Widget
-          def write
-            text 1
-            widget Child do
-              text 2
-              third
-            end
-          end
-
-          def third
-            text 3
-          end
-        end
-
-        class Child &lt; Erector::Widget
-          def write
-            super
-          end
-        end
-      end
-
-      it &quot;renders nested widgets in the correct order&quot; do
-        Parent.new.to_s.should == '123'
-      end
-    end
-
     describe '#write_via' do
       class A &lt; Erector::Widget
         def write</diff>
      <filename>spec/erector/widget_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>api-changes.txt</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>55268900d4f3fd9ea801550f7f245c16f6a66ff5</id>
    </parent>
  </parents>
  <author>
    <name>Alex Chaffee</name>
    <email>alex@stinky.com</email>
  </author>
  <url>http://github.com/pivotal/erector/commit/0cacf53d2834d107980ef43aca9cf11950ecb606</url>
  <id>0cacf53d2834d107980ef43aca9cf11950ecb606</id>
  <committed-date>2009-04-20T18:22:25-07:00</committed-date>
  <authored-date>2009-04-20T18:22:25-07:00</authored-date>
  <message>widget method takes instance or class; documentation and refactoring</message>
  <tree>0eef48c032ae7c403abab1ea3d809862bfa5ffe6</tree>
  <committer>
    <name>Alex Chaffee</name>
    <email>alex@stinky.com</email>
  </committer>
</commit>
