From: John Napiorkowski Date: Fri, 24 Sep 2010 01:39:25 +0000 (-0400) Subject: made the new FilterBuilder synopsis pass its test X-Git-Tag: release_0.009004~29 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FHTML-Zoom.git;a=commitdiff_plain;h=0d8f057ed479290d61f84e13ae6b3efec78813dd made the new FilterBuilder synopsis pass its test --- diff --git a/lib/HTML/Zoom/FilterBuilder.pm b/lib/HTML/Zoom/FilterBuilder.pm index cfae74e..96ddb8f 100644 --- a/lib/HTML/Zoom/FilterBuilder.pm +++ b/lib/HTML/Zoom/FilterBuilder.pm @@ -282,39 +282,57 @@ HTML::Zoom::FilterBuilder - Add Filters to a Stream =head1 SYNOPSIS - use HTML::Zoom; - my $root = HTML::Zoom - ->from_html(< - - Default Title - - - Default Content - - - MAIN - - my $body = HTML::Zoom - ->from_html(< -

Stuff

-

Stuff

- - BODY - - print $root - ->select('title') - ->replace_content('Hello World') - ->select('body') - ->replace_content($body) - ->select('#p1') - ->replace_content(sub { - ## Ask mst... - - }) - ->to_html; - + use HTML::Zoom; + my $root = HTML::Zoom + ->from_html(< + + Default Title + + + Default Content + + + MAIN + + my $body = HTML::Zoom + ->from_html(< +

Stuff

+ + BODY + + my $output = $root + ->select('title') + ->replace_content('Hello World') + ->select('body') + ->replace_content($body) + ->to_html; + +will produce: + +=begin testinfo + + my $expect = < + + Hello World + +
+

Stuff

+
+ + + +=begin testinfo + + HTML + is($output, $expect, 'Synopsis code works ok'); + +=end testinfo =head1 DESCRIPTION diff --git a/t/synopsis/filterbuilder.t b/t/synopsis/filterbuilder.t new file mode 100644 index 0000000..9769c3d --- /dev/null +++ b/t/synopsis/filterbuilder.t @@ -0,0 +1,45 @@ +use strict; +use warnings FATAL => 'all'; +use Test::More qw(no_plan); + +use HTML::Zoom; +my $root = HTML::Zoom + ->from_html(< + + Default Title + + + Default Content + + +MAIN + +my $body = HTML::Zoom + ->from_html(< +

Stuff

+ +BODY + +my $output = $root +->select('title') +->replace_content('Hello World') +->select('body') +->replace_content($body) +->to_html; + + +my $expect = < + + Hello World + +
+

Stuff

+
+ + +HTML +is($output, $expect, 'Synopsis code works ok'); + diff --git a/t/synopsis/zoom.t b/t/synopsis/zoom.t new file mode 100644 index 0000000..83f99e8 --- /dev/null +++ b/t/synopsis/zoom.t @@ -0,0 +1,76 @@ +use strict; +use warnings FATAL => 'all'; +use Test::More qw(no_plan); + +use HTML::Zoom; + +my $template = < + + Hello people + + +

Placeholder

+
+ +

Name: Bob

+

Age: 23

+
+
+
+ + +HTML + +my $output = HTML::Zoom + ->from_html($template) + ->select('title, #greeting')->replace_content('Hello world & dog!') + ->select('#list')->repeat_content( + [ + sub { + $_->select('.name')->replace_content('Matt') + ->select('.age')->replace_content('26') + }, + sub { + $_->select('.name')->replace_content('Mark') + ->select('.age')->replace_content('0x29') + }, + sub { + $_->select('.name')->replace_content('Epitaph') + ->select('.age')->replace_content('') + }, + ], + { repeat_between => '.between' } + ) + ->to_html; + + +my $expect = < + + Hello world & dog! + + +

Hello world & dog!

+
+ +

Name: Matt

+

Age: 26

+
+
+ +

Name: Mark

+

Age: 0x29

+
+
+ +

Name: Epitaph

+

Age: <redacted>

+
+ +
+ + +HTML +is($output, $expect, 'Synopsis code works ok'); +