changed add_attribute to add_to_attribute
John Napiorkowski [Fri, 24 Sep 2010 19:49:55 +0000 (15:49 -0400)]
lib/HTML/Zoom.pm
lib/HTML/Zoom/FilterBuilder.pm
t/actions.t
t/todo-forms.t

index d8c4f3a..07378b4 100644 (file)
@@ -298,16 +298,16 @@ cleanly:
     map { my $field = $_; sub {
 
      $_->select('label')
-       ->add_attribute( for => $field->{id} )
+       ->add_to_attribute( for => $field->{id} )
        ->then
        ->replace_content( $field->{label} )
 
        ->select('input')
-       ->add_attribute( name => $field->{name} )
+       ->add_to_attribute( name => $field->{name} )
        ->then
-       ->add_attribute( type => $field->{type} )
+       ->add_to_attribute( type => $field->{type} )
        ->then
-       ->add_attribute( value => $field->{value} )
+       ->add_to_attribute( value => $field->{value} )
 
     } } @fields
   ]);
@@ -696,7 +696,7 @@ together; the intermediary object isn't designed or expected to stick around.
 
 =head2 then
 
-  my $z2 = $z1->select('div')->add_attribute(class => 'spoon')
+  my $z2 = $z1->select('div')->add_to_attribute(class => 'spoon')
                              ->then
                              ->replace_content('I AM A DIV!');
 
index 96ddb8f..e07c557 100644 (file)
@@ -42,13 +42,17 @@ sub set_attribute {
 
 sub _parse_attribute_args {
   my $self = shift;
-  # allow ->add_attribute(name => 'value')
-  #    or ->add_attribute({ name => 'name', value => 'value' })
+  # allow ->add_to_attribute(name => 'value')
+  #    or ->add_to_attribute({ name => 'name', value => 'value' })
   my ($name, $value) = @_ > 1 ? @_ : @{$_[0]}{qw(name value)};
   return ($name, $self->_zconfig->parser->html_escape($value));
 }
 
 sub add_attribute {
+    die "renamed to add_to_attribute. killing this entirely for 1.0";
+}
+
+sub add_to_attribute {
   my $self = shift;
   my ($name, $value) = $self->_parse_attribute_args(@_);
   sub {
@@ -298,7 +302,8 @@ HTML::Zoom::FilterBuilder - Add Filters to a Stream
   my $body = HTML::Zoom
       ->from_html(<<BODY);
   <div id="stuff">
-      <p>Stuff</p>
+      <p>Well Now</p>
+      <p>Is the Time</p>
   </div>
   BODY
 
@@ -307,6 +312,8 @@ HTML::Zoom::FilterBuilder - Add Filters to a Stream
   ->replace_content('Hello World')
   ->select('body')
   ->replace_content($body)
+  ->select('#stuff p')
+  ->add_to_attribute(class=>'body')
   ->to_html;
 
 will produce:
@@ -347,7 +354,7 @@ This class defines the following public API
 
     TBD
 
-=head2 add_attribute
+=head2 add_to_attribute
 
     TBD
 
index 1d83aa1..584ec36 100644 (file)
@@ -67,7 +67,7 @@ is(
 ($expect = $tmpl) =~ s/class="main"/class="main foo"/;
 
 is(
-  run_for { $_->add_attribute({ name => 'class', value => 'foo' }) },
+  run_for { $_->add_to_attribute({ name => 'class', value => 'foo' }) },
   $expect,
   'add attribute on existing attribute'
 );
@@ -75,7 +75,7 @@ is(
 ($expect = $tmpl) =~ s/class="main"/class="main" foo="bar"/;
 
 is(
-  run_for { $_->add_attribute({ name => 'foo', value => 'bar' }) },
+  run_for { $_->add_to_attribute({ name => 'foo', value => 'bar' }) },
   $expect,
   'add attribute on non existing attribute'
 );
index ab8dcd7..a1bed00 100644 (file)
@@ -16,15 +16,15 @@ my @fields = (
 my $h = $zoom->select('.myform')->repeat_content([
     map { my $field = $_; sub {
               $_->select('label')
-               ->add_attribute( for => $field->{id} )
+               ->add_to_attribute( for => $field->{id} )
                ->then
                ->replace_content( $field->{label} )
                ->select('input')
-               ->add_attribute( name => $field->{name} )
+               ->add_to_attribute( name => $field->{name} )
                ->then
-               ->add_attribute( type => $field->{type} )
+               ->add_to_attribute( type => $field->{type} )
                ->then
-               ->add_attribute( value => $field->{value} )
+               ->add_to_attribute( value => $field->{value} )
            } } @fields
        ])->to_html;