X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FHTML%2FZoom%2FFilterBuilder.pm;h=c81e642c8d97b29e1db3413c1e73c3cd831378b8;hb=95dcb071e6789c2b985c36467674db31f9b35c39;hp=6040288e85b890bd5b69d3ba841569465e17a89f;hpb=948f7b2a1c6136a730e0ffc1c738c5f57b74a2ba;p=catagits%2FHTML-Zoom.git diff --git a/lib/HTML/Zoom/FilterBuilder.pm b/lib/HTML/Zoom/FilterBuilder.pm index 6040288..c81e642 100644 --- a/lib/HTML/Zoom/FilterBuilder.pm +++ b/lib/HTML/Zoom/FilterBuilder.pm @@ -58,7 +58,7 @@ sub add_attribute { sub add_class { shift->add_to_attribute('class',@_) } -sub remove_class { shift->remove_attribute('class',@_) } +sub remove_class { shift->remove_from_attribute('class',@_) } sub set_class { shift->set_attribute('class',@_) } @@ -82,6 +82,22 @@ sub add_to_attribute { }; } +sub remove_from_attribute { + my $self = shift; + my $attr = $self->_parse_attribute_args(@_); + sub { + my $a = (my $evt = $_[0])->{attrs}; + +{ %$evt, raw => undef, raw_attrs => undef, + attrs => { + %$a, + #TODO needs to support multiple removes + map { my $tar = $_; $_ => join ' ', + map {$attr->{$tar} ne $_} split ' ', $a->{$_} } keys %$attr + }, + } + }; +} + sub remove_attribute { my ($self, $args) = @_; my $name = (ref($args) eq 'HASH') ? $args->{name} : $args; @@ -463,8 +479,7 @@ Sets an attribute of a given name to a given value for all matching selections. ->select('p') ->set_attribute(class=>'paragraph') ->select('div') - ->set_attribute({name=>'class', value=>'divider'}); - + ->set_attribute({class=>'paragraph', name=>'divider'}); Overrides existing values, if such exist. When multiple L calls are made against the same or overlapping selection sets, the final @@ -475,19 +490,9 @@ call wins. Adds a value to an existing attribute, or creates one if the attribute does not yet exist. You may call this method with either an Array or HashRef of Args. -Here's the 'long form' HashRef: - - $html_zoom - ->select('p') - ->set_attribute(class=>'paragraph') - ->then - ->add_to_attribute({name=>'class', value=>'divider'}); - -And the exact same effect using the 'short form' Array: - $html_zoom ->select('p') - ->set_attribute(class=>'paragraph') + ->set_attribute({class => 'paragraph', name => 'test'}) ->then ->add_to_attribute(class=>'divider'); @@ -503,8 +508,26 @@ Removes an attribute and all its values. ->then ->remove_attribute('class'); +=head2 remove_from_attribute + +Removes a value from existing attribute + + $html_zoom + ->select('p') + ->set_attribute(class=>'paragraph lead') + ->then + ->remove_from_attribute('class' => 'lead'); + Removes attributes from the original stream or events already added. +=head2 add_class + +Add to a class attribute + +=head2 remove_class + +Remove from a class attribute + =head2 transform_attribute Transforms (or creates or deletes) an attribute by running the passed