SYNOPSIS

    # 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);

DESCRIPTION

\*(C`HTML::RewriteAttributes::Resources\*(C' is a special case of HTML::RewriteAttributes for rewriting links to resources. This is to facilitate generating, for example, \s-1HTML\s0 email in an extensible way.

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

METHODS

You don't need to call \*(C`new\*(C' explicitly - it's done in \*(L"rewrite\*(R". It takes no arguments. See the documentation of HTML::RewriteAttributes.

The callback receives as arguments the resource \s-1URI\s0 (the attribute value), then, in a hash, \*(C`tag\*(C' and \*(C`attr\*(C'.

Inlining \s-1CSS\s0

\*(C`rewrite\*(C' can automatically inline \s-1CSS\s0 for you.

Passing \*(C`inline_css\*(C' will invoke that callback to inline \*(C`style\*(C' tags. The callback receives as its argument the \s-1URI\s0 to a \s-1CSS\s0 file, and expects as a return value the contents of that file, so that it may be inlined. Returning \*(C`undef\*(C' prevents any sort of inlining.

Passing \*(C`inline_imports\*(C' (a boolean) will look at any inline \s-1CSS\s0 and call the \*(C`inline_css\*(C' callback to inline that import.

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

RELATED TO HTML::RewriteAttributes::Resources…

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

AUTHOR

Shawn M Moore, \*(C`<[email protected]>\*(C'

LICENSE

Copyright 2008-2010 Best Practical Solutions, \s-1LLC\s0. HTML::RewriteAttributes::Resources is distributed under the same terms as Perl itself.