From: John Napiorkowski Date: Fri, 24 Sep 2010 19:49:55 +0000 (-0400) Subject: changed add_attribute to add_to_attribute X-Git-Tag: release_0.009004~27 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FHTML-Zoom.git;a=commitdiff_plain;h=2daa653a58384970b813ea933d125c4a88dad853 changed add_attribute to add_to_attribute --- diff --git a/lib/HTML/Zoom.pm b/lib/HTML/Zoom.pm index d8c4f3a..07378b4 100644 --- a/lib/HTML/Zoom.pm +++ b/lib/HTML/Zoom.pm @@ -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!'); diff --git a/lib/HTML/Zoom/FilterBuilder.pm b/lib/HTML/Zoom/FilterBuilder.pm index 96ddb8f..e07c557 100644 --- a/lib/HTML/Zoom/FilterBuilder.pm +++ b/lib/HTML/Zoom/FilterBuilder.pm @@ -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(< -

Stuff

+

Well Now

+

Is the Time

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 diff --git a/t/actions.t b/t/actions.t index 1d83aa1..584ec36 100644 --- a/t/actions.t +++ b/t/actions.t @@ -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' ); diff --git a/t/todo-forms.t b/t/todo-forms.t index ab8dcd7..a1bed00 100644 --- a/t/todo-forms.t +++ b/t/todo-forms.t @@ -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;