HTML::...ources(3pm)

πŸ’– HTML::RewriteAttributes::Resources πŸ’–

okay bestie, so this is a page from the User Contributed Perl Documentation corner of the manual-verse, and it's about HTML::RewriteAttributes::Resources β€” the resource-link-rewriting bestie. concise. iconic. no cap. πŸŽ€


✨ NAME ✨

HTML::RewriteAttributes::Resources β€” concise resource-link rewriting πŸ¦‹


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

like... the range?? we love a three-ways-to-do-it moment πŸ’…


✨ DESCRIPTION ✨

so HTML::RewriteAttributes::Resources is literally a special case of HTML::RewriteAttributes, except it's specifically for rewriting links to resources. its whole thing is making it easy to generate stuff like HTML email in an extensible way. main character energy, fr.

and here's the deal bestie β€” we do not care how you fetch resources and attach them to the MIME object. that's your job, your moment, your slay. the part you get to skip entirely is figuring out how to rewrite the HTML. 🫢


✨ METHODS ✨

new 🌸

okay so you do not need to call new yourself β€” it already happens inside rewrite. it takes no arguments. that's it. that's the whole method. periodt. πŸ’…

rewrite HTML, callback[, args] -> HTML πŸ‘‘

go read the documentation of HTML::RewriteAttributes, bestie, that's where the real lore is.

the callback gets, as its arguments, the resource URI (which is the attribute value), and then, in a hash, tag and attr. like a little care package of context. 🎁

Inlining CSS πŸ’–

rewrite can auto-inline CSS for you. iconic behaviour, honestly.

if you pass inline_css, it'll invoke that callback to inline style tags. the callback receives the URI to a CSS file as its argument, and it's expected to hand back the contents of that file so they can get inlined. heads up: if it returns undef, that stops any sort of inlining from happening. nope, not today. πŸ™ˆ

if you pass inline_imports (a boolean), it'll peek at any inline CSS and call the inline_css callback to inline that import. 🧚

and lowkey the smartest part: it keeps track of what CSS has already been inlined, and it won't inline a particular CSS file more than once β€” which is how it prevents import loops. protecting you from yourself, we love to see it. ✨


✨ SEE ALSO ✨

  • HTML::RewriteAttributes
  • HTML::Parser
  • Email::MIME::CreateHTML

the squad. the group chat. the whole friend group showed up. 🌈


✨ AUTHOR ✨

Best Practical Solutions, LLC <modules@bestpractical.com> πŸ’Œ


✨ LICENSE ✨

Copyright 2008-2024 Best Practical Solutions, LLC.

HTML::RewriteAttributes::Resources is distributed under the same terms as Perl itself.

so basically: same terms as Perl. don't be weird about it, bestie. πŸ“

and that's the whole page!! this was perl v5.40.0, dated 2024-11-15, and it's the HTML::...ources(3pm) manual. k bye, go rewrite some resource links, you absolute legend πŸ’œπŸ‘‘β­

πŸ“¦ where this page comes from