[Bps-public-commit] HTML-RewriteAttributes branch, master, updated. c4f5549f896792074393ed7b84cfd00a98f8aca7

Thomas Sibley trs at bestpractical.com
Mon Oct 22 17:55:38 EDT 2012


The branch, master has been updated
       via  c4f5549f896792074393ed7b84cfd00a98f8aca7 (commit)
      from  d2704eb441d9783569e95cd2ae577a755687c1cd (commit)

Summary of changes:
 lib/HTML/RewriteAttributes/Resources.pm |  4 +++-
 t/020-inline-css.t                      | 11 +++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

- Log -----------------------------------------------------------------
commit c4f5549f896792074393ed7b84cfd00a98f8aca7
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Mon Oct 22 14:54:01 2012 -0700

    Preserve the media attribute when inlining CSS
    
    Otherwise print styles may be turned into screen styles.

diff --git a/lib/HTML/RewriteAttributes/Resources.pm b/lib/HTML/RewriteAttributes/Resources.pm
index 2bb8f6c..955f832 100644
--- a/lib/HTML/RewriteAttributes/Resources.pm
+++ b/lib/HTML/RewriteAttributes/Resources.pm
@@ -53,7 +53,9 @@ sub _start_tag {
             my $content = $self->_import($attr->{href});
             if (defined $content) {
                 $content = $self->_handle_imports($content, $attr->{href});
-                $self->{rewrite_html} .= "\n<style type=\"text/css\">\n<!--\n$content\n-->\n</style>\n";
+                $self->{rewrite_html} .= "\n<style type=\"text/css\"";
+                $self->{rewrite_html} .= " media=\"$attr->{media}\"" if $attr->{media};
+                $self->{rewrite_html} .= ">\n<!--\n$content\n-->\n</style>\n";
                 return;
             }
         }
diff --git a/t/020-inline-css.t b/t/020-inline-css.t
index d9c5eb3..c89737a 100644
--- a/t/020-inline-css.t
+++ b/t/020-inline-css.t
@@ -8,6 +8,7 @@ my $html = << 'END';
 <html>
     <head>
         <link type="text/css" href="foo.css" />
+        <link type="text/css" href="print.css" media="print" />
     </head>
     <body>
         <img src="moose.jpg" />
@@ -45,6 +46,7 @@ is_deeply(\@seen, [
 
 is_deeply(\@seen_inline, [
     "foo.css",
+    "print.css",
 ]);
 
 is($rewrote, << "END", "rewrote the html correctly");
@@ -59,6 +61,15 @@ INLINED CSS
 -->
 </style>
 
+        
+<style type="text/css" media="print">
+<!--
+
+/* print.css */
+INLINED CSS
+-->
+</style>
+
     </head>
     <body>
         <img src="MOOSE.JPG" />

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list