[Bps-public-commit] r11931 - in HTML-RewriteResources: .

sartak at bestpractical.com sartak at bestpractical.com
Mon Apr 28 20:22:21 EDT 2008


Author: sartak
Date: Mon Apr 28 20:22:21 2008
New Revision: 11931

Added:
   HTML-RewriteResources/lib/HTML/RewriteAttributes.pm
      - copied, changed from r11929, /HTML-RewriteResources/lib/HTML/RewriteResources.pm
Removed:
   HTML-RewriteResources/lib/HTML/RewriteResources.pm
Modified:
   HTML-RewriteResources/   (props changed)

Log:
 r54605 at onn:  sartak | 2008-04-28 20:21:44 -0400
 Rename RewriteResources to RewriteAttributes (we'll now subclass and specialize)


Copied: HTML-RewriteResources/lib/HTML/RewriteAttributes.pm (from r11929, /HTML-RewriteResources/lib/HTML/RewriteResources.pm)
==============================================================================
--- /HTML-RewriteResources/lib/HTML/RewriteResources.pm	(original)
+++ HTML-RewriteResources/lib/HTML/RewriteAttributes.pm	Mon Apr 28 20:22:21 2008
@@ -1,5 +1,5 @@
 #!/usr/bin/env perl
-package HTML::RewriteResources;
+package HTML::RewriteAttributes;
 use strict;
 use warnings;
 use base 'HTML::Parser';
@@ -51,35 +51,17 @@
 
 sub _done_rewriting { }
 
-my %rewritable_attrs = (
-    bgsound => [ qw/src       / ],
-    body    => [ qw/background/ ],
-    img     => [ qw/src       / ],
-    input   => [ qw/src       / ],
-    table   => [ qw/background/ ],
-    td      => [ qw/background/ ],
-    th      => [ qw/background/ ],
-    tr      => [ qw/background/ ],
-);
-
-sub _rewritable_attrs {
-    my $self = shift;
-    my $tag  = shift;
-
-    return @{ $rewritable_attrs{$tag} || [] }
-}
+sub _should_rewrite { 1 }
 
 sub _start_tag {
-    my ($self, $tagname, $attrs, $attrseq, $text) = @_;
-
-    my @rewritable = $self->_rewritable_attrs($tagname);
+    my ($self, $tag, $attrs, $attrseq, $text) = @_;
 
-    for my $attr (@rewritable) {
-        next unless exists $attrs->{$attr};
+    for my $attr (@$attrseq) {
+        next unless $self->_should_rewrite($tag, $attr);
         $attrs->{$attr} = $self->{rewrite_callback}->($attrs->{$attr});
     }
 
-    $self->{rewrite_html} .= "<$tagname";
+    $self->{rewrite_html} .= "<$tag";
 
     for my $attr (@$attrseq) {
         next if $attr eq '/';
@@ -94,7 +76,7 @@
 }
 
 sub _default {
-    my ($self, $tagname, $attrs, $text) = @_;
+    my ($self, $tag, $attrs, $text) = @_;
     $self->{rewrite_html} .= $text;
 }
 



More information about the Bps-public-commit mailing list