NAME
CSS::Inliner - Library for converting CSS <style> blocks to inline styles.
SYNOPSIS
use Inliner;
my $inliner = new Inliner();
$inliner->read_file({filename => 'myfile.html'});
print $inliner->inlinify();
DESCRIPTION
Library for converting CSS style blocks into inline styles in an HTML document. Specifically this is intended for the ease of generating HTML emails. This is useful as even in 2009 Gmail and Hotmail don't support top level <style> declarations.
CONSTRUCTOR
- new ([ OPTIONS ])
-
Instantiates the Inliner object. Sets up class variables that are used during file parsing/processing. Possible options are:
html_tree (optional). Pass in a custom instance of HTML::Treebuilder
strip_attrs (optional). Remove all "id" and "class" attributes during inlining
METHODS
- fetch_file( params )
-
Fetches a remote HTML file that supposedly contains both HTML and a style declaration. It subsequently calls the read() method automatically.
This method expands all relative urls, as well as fully expands the stylesheet reference within the document.
This method requires you to pass in a params hash that contains a url argument for the requested document. For example:
$self->fetch_file({ url => 'http://www.example.com' });
- read_file( params )
-
Opens and reads an HTML file that supposedly contains both HTML and a style declaration. It subsequently calls the read() method automatically.
This method requires you to pass in a params hash that contains a filename argument. For example:
$self->read_file({filename => 'myfile.html'});
- read( params )
-
Reads html data and parses it. The intermediate data is stored in class variables.
The <style> block is ripped out of the html here, and stored separately. Class/ID/Names used in the markup are left alone.
This method requires you to pass in a params hash that contains scalar html data. For example:
$self->read({html => $html});
- inlinify()
-
Processes the html data that was entered through either 'read' or 'read_file', returns a scalar that contains a composite chunk of html that has inline styles instead of a top level <style> declaration.
- specificity()
-
Calculate the specificity for any given passed selector, a critical factor in determining how best to apply the cascade
A selector's specificity is calculated as follows:
* count the number of ID attributes in the selector (= a) * count the number of other attributes and pseudo-classes in the selector (= b) * count the number of element names in the selector (= c) * ignore pseudo-elements.
The specificity is based only on the form of the selector. In particular, a selector of the form "[id=p33]" is counted as an attribute selector (a=0, b=0, c=1, d=0), even if the id attribute is defined as an "ID" in the source document's DTD.
See the following spec for additional details: http://www.w3.org/TR/CSS21/cascade.html#specificity
Sponsor
This code has been developed under sponsorship of MailerMailer LLC, http://www.mailermailer.com/
AUTHOR
Kevin Kamel <kamelkev@mailermailer.com
>
CONTRIBUTORS
Vivek Khera <vivek@khera.org
> Michael Peters <wonko@cpan.org
>
LICENSE
This module is Copyright 2010 Khera Communications, Inc. It is licensed under the same terms as Perl itself.
2 POD Errors
The following errors were encountered while parsing the POD:
- Around line 289:
'=item' outside of any '=over'
- Around line 331:
'=item' outside of any '=over'