GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
HTML::RewriteAttributes::Resources(3) User Contributed Perl Documentation HTML::RewriteAttributes::Resources(3)

HTML::RewriteAttributes::Resources - concise resource-link rewriting

    # writing some HTML email I see..
    $html = HTML::RewriteAttributes::Resources->rewrite($html, sub {
        my $uri = shift;
        my $content = render_template($uri);
        my $cid = generate_cid_from($content);
        $mime->attach($cid => content);
        return "cid:$cid";
    });

    # need to inline CSS too?
    $html = HTML::RewriteAttributes::Resources->rewrite($html, sub {
        # see above
    },
    inline_css => sub {
        my $uri = shift;
        return render_template($uri);
    });

    # need to inline CSS and follow @imports?
    $html = HTML::RewriteAttributes::Resources->rewrite($html, sub {
        # see above
    },
    inline_css => sub {
        # see above
    }, inline_imports => 1);

"HTML::RewriteAttributes::Resources" is a special case of HTML::RewriteAttributes for rewriting links to resources. This is to facilitate generating, for example, HTML email in an extensible way.

We don't care about how to fetch resources and attach them to the MIME object; that's your job. But you don't have to care about how to rewrite the HTML.

You don't need to call "new" explicitly - it's done in "rewrite". It takes no arguments.

See the documentation of HTML::RewriteAttributes.

The callback receives as arguments the resource URI (the attribute value), then, in a hash, "tag" and "attr".

Inlining CSS

"rewrite" can automatically inline CSS for you.

Passing "inline_css" will invoke that callback to inline "style" tags. The callback receives as its argument the URI to a CSS file, and expects as a return value the contents of that file, so that it may be inlined. Returning "undef" prevents any sort of inlining.

Passing "inline_imports" (a boolean) will look at any inline CSS and call the "inline_css" callback to inline that import.

This keeps track of what CSS has already been inlined, and won't inline a particular CSS file more than once (to prevent import loops).

HTML::RewriteAttributes, HTML::Parser, Email::MIME::CreateHTML

Shawn M Moore, "<sartak@bestpractical.com>"

Copyright 2008-2010 Best Practical Solutions, LLC. HTML::RewriteAttributes::Resources is distributed under the same terms as Perl itself.
2012-10-22 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.