Skip Menu |

This queue is for tickets about the CSS-Inliner CPAN distribution.

Report information
The Basics
Id: 54999
Status: resolved
Priority: 0/
Queue: CSS-Inliner

People
Owner: Nobody in particular
Requestors: wonko [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 2434
Fixed in: (no value)



Subject: Custom HTML::TreeBuilder object
CSS::Inliner uses HTML::TreeBuilder internally to do some of the heavy lifting when dealing with the HTML. But it creates a vanilla HTML::TreeBuilder object with just the defaults and HTML::TreeBuilder has lots of knobs that can be adjusted. It would be nice if you could pass in an HTML::TreeBuilder object when a CSS::Inliner object is created which will be used instead. This attached patch accomplishes that.
Subject: custom_html_tree.patch
--- Inliner.pm 2010-01-26 10:44:44.000000000 -0500 +++ Inliner.pm.new 2010-02-25 14:05:22.856646633 -0500 @@ -58,11 +58,12 @@ sub new { my $this = shift; my $class = ref($this) || $this; + my %args = @_; my $self = { css => undef, html => undef, - html_tree => undef, + html_tree => $args{html_tree} || HTML::TreeBuilder->new(), }; if (@_) { @@ -127,7 +128,7 @@ croak "You must pass in hash params that contains html data"; } - my $tree = new HTML::TreeBuilder(); + my $tree = $self->{html_tree}; $tree->store_comments(1); $tree->parse($$params{html}); @@ -138,9 +139,6 @@ #stash the stylesheets $self->{css} = $style; - #keep the html tree for later so we don't have to reparse - $self->{html_tree} = $tree; - return(); }
Actually, this is the patch that should be used (since it actually works).
Subject: custom_html_tree.patch
--- Inliner.pm 2010-01-26 10:44:44.000000000 -0500 +++ Inliner.pm.new 2010-02-25 14:24:53.799912280 -0500 @@ -58,17 +58,14 @@ sub new { my $this = shift; my $class = ref($this) || $this; + my %args = @_; my $self = { css => undef, html => undef, - html_tree => undef, + html_tree => $args{html_tree} || HTML::TreeBuilder->new(), }; - if (@_) { - croak "Invalid number of arguments"; - } - bless $self, $class; return $self; } @@ -127,7 +124,7 @@ croak "You must pass in hash params that contains html data"; } - my $tree = new HTML::TreeBuilder(); + my $tree = $self->{html_tree}; $tree->store_comments(1); $tree->parse($$params{html}); @@ -138,9 +135,6 @@ #stash the stylesheets $self->{css} = $style; - #keep the html tree for later so we don't have to reparse - $self->{html_tree} = $tree; - return(); }
added