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
]);
=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!');
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 {
my $body = HTML::Zoom
->from_html(<<BODY);
<div id="stuff">
- <p>Stuff</p>
+ <p>Well Now</p>
+ <p>Is the Time</p>
</div>
BODY
->replace_content('Hello World')
->select('body')
->replace_content($body)
+ ->select('#stuff p')
+ ->add_to_attribute(class=>'body')
->to_html;
will produce:
TBD
-=head2 add_attribute
+=head2 add_to_attribute
TBD
($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'
);
($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'
);
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;