[Bps-public-commit] r11958 - in HTML-RewriteAttributes: . lib/HTML

sartak at bestpractical.com sartak at bestpractical.com
Tue Apr 29 16:44:25 EDT 2008


Author: sartak
Date: Tue Apr 29 16:44:23 2008
New Revision: 11958

Added:
   HTML-RewriteAttributes/t/000-synopsis.t
Modified:
   HTML-RewriteAttributes/   (props changed)
   HTML-RewriteAttributes/lib/HTML/RewriteAttributes.pm

Log:
 r54652 at onn:  sartak | 2008-04-29 16:44:16 -0400
 Begin adding POD, synopsis tests


Modified: HTML-RewriteAttributes/lib/HTML/RewriteAttributes.pm
==============================================================================
--- HTML-RewriteAttributes/lib/HTML/RewriteAttributes.pm	(original)
+++ HTML-RewriteAttributes/lib/HTML/RewriteAttributes.pm	Tue Apr 29 16:44:23 2008
@@ -92,5 +92,36 @@
     return $self->{rewrite_callback}->($tag, $attr, $value);
 }
 
+=head1 NAME
+
+HTML::RewriteAttributes - concise attribute rewriting
+
+=head1 SYNOPSIS
+
+    use HTML::RewriteAttributes;
+    $html = HTML::RewriteAttributes->rewrite($html, sub {
+        my ($tag, $attr, $value) = @_;
+
+        # delete any attribute that mentions..
+        return if $value =~ /COBOL/i;
+
+        $value =~ s/\brocks\b/rules/g;
+        return $value;
+    });
+
+    use HTML::RewriteAttributes::Resources;
+    $html = HTML::RewriteAttributes::Resources->rewrite($html, sub {
+        my $uri = shift;
+        my $content = fetch_from_mason($uri);
+        my $cid = generate_cid_from($content);
+        $mime->attach($cid => content);
+        return "cid:$cid";
+    });
+
+    use HTML::RewriteAttributes::Links;
+    $html = HTML::RewriteAttributes::Links->rewrite($html, "http://search.cpan.org");
+
+=cut
+
 1;
 

Added: HTML-RewriteAttributes/t/000-synopsis.t
==============================================================================
--- (empty file)
+++ HTML-RewriteAttributes/t/000-synopsis.t	Tue Apr 29 16:44:23 2008
@@ -0,0 +1,103 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 3;
+
+# RewriteAttributes {{{
+my $html = << "END";
+<html>
+    <body background="baroque.jpg">
+        <a href="http://en.wikipedia.org/wiki/COBOL">COBOL</a><br />
+        <a href="http://en.wikipedia.org/wiki/FORTRAN">FORTRAN</a><br />
+
+        <img src="http://example.com/img/COBOL.bmp" title="COBOL rocks" />
+        <img src="http://example.com/img/FORTRAN.bmp" title="FORTRAN rocks" />
+    </body>
+</html>
+END
+
+use HTML::RewriteAttributes;
+$html = HTML::RewriteAttributes->rewrite($html, sub {
+    my ($tag, $attr, $value) = @_;
+
+    # delete any attribute that mentions..
+    return if $value =~ /COBOL/i;
+
+    $value =~ s/\brocks\b/rules/g;
+    return $value;
+});
+
+is($html, << "END", "rewrote the html correctly");
+<html>
+    <body background="baroque.jpg">
+        <a>COBOL</a><br />
+        <a href="http://en.wikipedia.org/wiki/FORTRAN">FORTRAN</a><br />
+
+        <img />
+        <img src="http://example.com/img/FORTRAN.bmp" title="FORTRAN rules" />
+    </body>
+</html>
+END
+# }}}
+# Resources {{{
+$html = << "END";
+<html>
+    <body background="baroque.jpg">
+        <a href="http://en.wikipedia.org/wiki/COBOL">COBOL</a><br />
+        <a href="http://en.wikipedia.org/wiki/FORTRAN">FORTRAN</a><br />
+
+        <img src="http://example.com/img/COBOL.bmp" title="COBOL rocks" />
+        <img src="http://example.com/img/FORTRAN.bmp" title="FORTRAN rocks" />
+    </body>
+</html>
+END
+
+use HTML::RewriteAttributes::Resources;
+my $cid = 0;
+$html = HTML::RewriteAttributes::Resources->rewrite($html, sub {
+    my $uri = shift;
+    ++$cid;
+    return "cid:$cid";
+});
+
+is($html, << "END", "rewrote the html correctly");
+<html>
+    <body background="cid:1">
+        <a href="http://en.wikipedia.org/wiki/COBOL">COBOL</a><br />
+        <a href="http://en.wikipedia.org/wiki/FORTRAN">FORTRAN</a><br />
+
+        <img src="cid:2" title="COBOL rocks" />
+        <img src="cid:3" title="FORTRAN rocks" />
+    </body>
+</html>
+END
+# }}}
+# Links {{{
+$html = << "END";
+<html>
+    <body background="baroque.jpg">
+        <a href="http://en.wikipedia.org/wiki/COBOL">COBOL</a><br />
+        <a href="http://en.wikipedia.org/wiki/FORTRAN">FORTRAN</a><br />
+
+        <img src="http://example.com/img/COBOL.bmp" title="COBOL rocks" />
+        <img src="http://example.com/img/FORTRAN.bmp" title="FORTRAN rocks" />
+    </body>
+</html>
+END
+
+use HTML::RewriteAttributes::Links;
+$html = HTML::RewriteAttributes::Links->rewrite($html, "http://search.cpan.org");
+
+is($html, << "END", "rewrote the html correctly");
+<html>
+    <body background="http://search.cpan.org/baroque.jpg">
+        <a href="http://en.wikipedia.org/wiki/COBOL">COBOL</a><br />
+        <a href="http://en.wikipedia.org/wiki/FORTRAN">FORTRAN</a><br />
+
+        <img src="http://example.com/img/COBOL.bmp" title="COBOL rocks" />
+        <img src="http://example.com/img/FORTRAN.bmp" title="FORTRAN rocks" />
+    </body>
+</html>
+END
+# }}}
+



More information about the Bps-public-commit mailing list