[Bps-public-commit] r11929 - in HTML-RewriteResources: . t

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


Author: sartak
Date: Mon Apr 28 20:16:18 2008
New Revision: 11929

Modified:
   HTML-RewriteResources/   (props changed)
   HTML-RewriteResources/lib/HTML/RewriteResources.pm
   HTML-RewriteResources/t/001-basic.t

Log:
 r54602 at onn:  sartak | 2008-04-28 20:16:10 -0400
 More implementation, now passes tests (barely)


Modified: HTML-RewriteResources/lib/HTML/RewriteResources.pm
==============================================================================
--- HTML-RewriteResources/lib/HTML/RewriteResources.pm	(original)
+++ HTML-RewriteResources/lib/HTML/RewriteResources.pm	Mon Apr 28 20:16:18 2008
@@ -51,13 +51,50 @@
 
 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 _start_tag {
-    my ($self, $tagname, $attr, $attrseq, $text) = @_;
-    $self->{rewrite_html} .= $text;
+    my ($self, $tagname, $attrs, $attrseq, $text) = @_;
+
+    my @rewritable = $self->_rewritable_attrs($tagname);
+
+    for my $attr (@rewritable) {
+        next unless exists $attrs->{$attr};
+        $attrs->{$attr} = $self->{rewrite_callback}->($attrs->{$attr});
+    }
+
+    $self->{rewrite_html} .= "<$tagname";
+
+    for my $attr (@$attrseq) {
+        next if $attr eq '/';
+        $self->{rewrite_html} .= sprintf ' %s="%s"',
+                                    $attr,
+                                    #_escape($attrs->{$attr}),
+                                    $attrs->{$attr};
+    }
+
+    $self->{rewrite_html} .= ' /' if $attrs->{'/'};
+    $self->{rewrite_html} .= '>';
 }
 
 sub _default {
-    my ($self, $tagname, $attr, $text) = @_;
+    my ($self, $tagname, $attrs, $text) = @_;
     $self->{rewrite_html} .= $text;
 }
 

Modified: HTML-RewriteResources/t/001-basic.t
==============================================================================
--- HTML-RewriteResources/t/001-basic.t	(original)
+++ HTML-RewriteResources/t/001-basic.t	Mon Apr 28 20:16:18 2008
@@ -9,6 +9,9 @@
     <body>
         <img src="moose.jpg" />
         <img src="http://example.com/nethack.png">
+        <p align="justified">
+            hooray
+        </p>
     </body>
 </html>
 END
@@ -30,6 +33,9 @@
     <body>
         <img src="MOOSE.JPG" />
         <img src="HTTP://EXAMPLE.COM/NETHACK.PNG">
+        <p align="justified">
+            hooray
+        </p>
     </body>
 </html>
 END



More information about the Bps-public-commit mailing list