From: John Napiorkowski Date: Mon, 4 Oct 2010 16:17:48 +0000 (-0400) Subject: trying to make the documentation a little more straightforward to setup X-Git-Tag: release_0.009004~20 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FHTML-Zoom.git;a=commitdiff_plain;h=a42917f6295747a1b4b3d081db5e2f1feaca9d00 trying to make the documentation a little more straightforward to setup --- diff --git a/lib/HTML/Zoom/FilterBuilder.pm b/lib/HTML/Zoom/FilterBuilder.pm index 6bbaa04..50398b3 100644 --- a/lib/HTML/Zoom/FilterBuilder.pm +++ b/lib/HTML/Zoom/FilterBuilder.pm @@ -286,6 +286,8 @@ HTML::Zoom::FilterBuilder - Add Filters to a Stream =head1 SYNOPSIS +Create an L instance: + use HTML::Zoom; my $root = HTML::Zoom ->from_html(< Default Title - + Default Content MAIN +Create a new attribute on the C tag: + + $root = $root + ->select('body') + ->set_attribute(class=>'main'); + +Add a extra value to an existing attribute: + + $root = $root + ->select('body') + ->add_to_attribute(class=>'one-column'); + +Set the content of the C tag: + + $root = $root + ->select('title') + ->replace_content('Hello World'); + +Set content from another L<HTML::Zoom> instance: + my $body = HTML::Zoom ->from_html(<<BODY); <div id="stuff"> @@ -307,31 +329,27 @@ HTML::Zoom::FilterBuilder - Add Filters to a Stream </div> BODY - my $output = $root - ->select('title') - ->replace_content('Hello World') + $root = $root ->select('body') - ->replace_content($body) - ->then - ->set_attribute(class=>'main') - ->then - ->add_to_attribute(class=>'one-column') - ->then - ->set_attribute(id=>'top') - ->then - ->add_to_attribute(id=>'deleteme') - ->then - ->remove_attribute({name=>'id'}) + ->replace_content($body); + +Set an attribute on multiple matches: + + $root = $root ->select('p') - ->set_attribute(class=>'para') - ->select('#p2') - ->set_attribute(class=>'para2') - ->to_html; + ->set_attribute(class=>'para'); + +Remove an attribute: + + $root = $root + ->select('body') + ->remove_attribute('bad_attr'); will produce: =begin testinfo + my $output = $root->to_html; my $expect = <<HTML; =end testinfo @@ -342,7 +360,7 @@ will produce: </head> <body class="main one-column"><div id="stuff"> <p class="para">Well Now</p> - <p id="p2" class="para2">Is the Time</p> + <p id="p2" class="para">Is the Time</p> </div> </body> </html> diff --git a/maint/synopsis-extractor b/maint/synopsis-extractor index 21980b4..ecafe67 100755 --- a/maint/synopsis-extractor +++ b/maint/synopsis-extractor @@ -16,9 +16,9 @@ sub extract_synopsis { my $head_or_cut = qr[head|cut]x; if($string=~m/^=head1 SYNOPSIS\n(.*?)^=$head_or_cut/sm) { my $extracted = $1; - $extracted=~s/^\S.+?$//m; # wipe out non code lines in pod my $begin_end = qr[begin|end]x; $extracted=~s/\n^=$begin_end testinfo\n\n//smg; # remove test block + $extracted=~s/^\S.+?$//smg; # wipe out non code lines in pod return $extracted; } else { return; diff --git a/t/synopsis/filterbuilder.t b/t/synopsis/filterbuilder.t index 67083c6..1112109 100644 --- a/t/synopsis/filterbuilder.t +++ b/t/synopsis/filterbuilder.t @@ -2,6 +2,8 @@ use strict; use warnings FATAL => 'all'; use Test::More qw(no_plan); + + use HTML::Zoom; my $root = HTML::Zoom ->from_html(<<MAIN); @@ -9,12 +11,32 @@ my $root = HTML::Zoom <head> <title>Default Title - + Default Content MAIN + + +$root = $root + ->select('body') + ->set_attribute(class=>'main'); + + + +$root = $root + ->select('body') + ->add_to_attribute(class=>'one-column'); + + + +$root = $root + ->select('title') + ->replace_content('Hello World'); + + + my $body = HTML::Zoom ->from_html(< @@ -23,36 +45,32 @@ my $body = HTML::Zoom BODY -my $output = $root - ->select('title') - ->replace_content('Hello World') +$root = $root ->select('body') - ->replace_content($body) - ->then - ->set_attribute(class=>'main') - ->then - ->add_to_attribute(class=>'one-column') - ->then - ->set_attribute(id=>'top') - ->then - ->add_to_attribute(id=>'deleteme') - ->then - ->remove_attribute({name=>'id', value=>'deleteme'}) + ->replace_content($body); + + + +$root = $root ->select('p') - ->set_attribute(class=>'para') - ->select('#p2') - ->set_attribute(class=>'para2') - ->to_html; + ->set_attribute(class=>'para'); + + + +$root = $root + ->select('body') + ->remove_attribute('bad_attr'); +my $output = $root->to_html; my $expect = < Hello World -
+

Well Now

-

Is the Time

+

Is the Time