From 67e78ff23a6eddb48860da18de89798a5e3f1efe Mon Sep 17 00:00:00 2001 From: tbrannon Date: Fri, 9 Jan 2009 09:36:02 -0500 Subject: [PATCH] first commit --- Changes | 19 + MANIFEST | 99 ++ META.yml | 18 + Makefile.PL | 50 + README | 540 +++++++++ lib/HTML/Element/Library.pm | 1622 ++++++++++++++++++++++++++ lib/HTML/Element/Library/Changes.pod | 6 + t/00system.t | 46 + t/Arsenal.pl | 4 + t/Arsenal.pm | 70 ++ t/HTML-Element-Library.t | 17 + t/SelectData.pm | 22 + t/SimpleClass.pm | 29 + t/TestUtils.pm | 29 + t/content_handler.t | 34 + t/data/3dig.dat | 5 + t/data/4dig.dat | 10 + t/data/table2.pm | 37 + t/dual_iter.t | 53 + t/highlander.t | 36 + t/highlander2.t | 50 + t/html/dual_iter.exp | 15 + t/html/dual_iter.gen | 15 + t/html/dual_iter.html | 25 + t/html/highlander-15.exp | 6 + t/html/highlander-15.gen | 6 + t/html/highlander-5.exp | 6 + t/html/highlander-5.gen | 6 + t/html/highlander-50.exp | 5 + t/html/highlander-50.gen | 5 + t/html/highlander.html | 13 + t/html/highlander2-15.exp | 6 + t/html/highlander2-15.gen | 6 + t/html/highlander2-27.exp | 6 + t/html/highlander2-27.gen | 6 + t/html/highlander2-5.exp | 6 + t/html/highlander2-5.gen | 6 + t/html/highlander2.html | 15 + t/html/iter.exp | 10 + t/html/iter.gen | 10 + t/html/iter.html | 4 + t/html/iter2.exp | 15 + t/html/iter2.gen | 15 + t/html/iter2.html | 27 + t/html/table-alt.exp | 42 + t/html/table-alt.gen | 42 + t/html/table-alt.html | 24 + t/html/table.exp | 42 + t/html/table.gen | 42 + t/html/table.html | 18 + t/html/table2-table_ld-arrayref.exp | 160 +++ t/html/table2-table_ld-arrayref.gen | 160 +++ t/html/table2-table_ld-arrayref.html | 80 ++ t/html/table2-table_ld-coderef.exp | 160 +++ t/html/table2-table_ld-coderef.gen | 160 +++ t/html/table2-table_ld-coderef.html | 80 ++ t/html/table2-table_ld-default.exp | 160 +++ t/html/table2-table_ld-default.gen | 160 +++ t/html/table2-table_ld-default.html | 80 ++ t/html/table2-tr_ld-arrayref.exp | 9 + t/html/table2-tr_ld-arrayref.gen | 9 + t/html/table2-tr_ld-arrayref.html | 80 ++ t/html/table2-tr_ld-coderef.exp | 134 +++ t/html/table2-tr_ld-coderef.gen | 134 +++ t/html/table2-tr_ld-coderef.html | 80 ++ t/html/table2-tr_ld-default.gen | 160 +++ t/html/table2-tr_ld-default.html | 80 ++ t/html/table2-tr_ld_coderef.exp | 134 +++ t/html/table2.exp | 179 +++ t/html/table2.gen | 179 +++ t/html/table2.html | 80 ++ t/html/table2_code.html | 68 ++ t/html/table2_id.exp | 80 ++ t/html/table2_id.html | 68 ++ t/html/table2_tr_proc.html | 80 ++ t/html/unroll_select.exp | 54 + t/html/unroll_select.gen | 54 + t/html/unroll_select.html | 56 + t/iter.t | 26 + t/iter2.t | 48 + t/m/SelectData.pm | 22 + t/m/SimpleClass.pm | 29 + t/m/TestUtils.pm | 31 + t/not-used/Arsenal.pl | 4 + t/not-used/Arsenal.pm | 70 ++ t/position.t | 37 + t/q | 23 + t/replace_content.t | 33 + t/set_child_content.t | 34 + t/sibdex.t | 32 + t/siblings.t | 40 + t/table-alt.t | 56 + t/table.t | 56 + t/table2-table_ld.t | 71 ++ t/table2-tr_ld.t | 87 ++ t/table2.t | 52 + t/unroll_select.t | 33 + t/wrap_content.t | 39 + 98 files changed, 6981 insertions(+) create mode 100644 Changes create mode 100644 MANIFEST create mode 100644 META.yml create mode 100644 Makefile.PL create mode 100644 README create mode 100644 lib/HTML/Element/Library.pm create mode 100644 lib/HTML/Element/Library/Changes.pod create mode 100644 t/00system.t create mode 100644 t/Arsenal.pl create mode 100644 t/Arsenal.pm create mode 100644 t/HTML-Element-Library.t create mode 100644 t/SelectData.pm create mode 100644 t/SimpleClass.pm create mode 100644 t/TestUtils.pm create mode 100644 t/content_handler.t create mode 100644 t/data/3dig.dat create mode 100644 t/data/4dig.dat create mode 100644 t/data/table2.pm create mode 100644 t/dual_iter.t create mode 100644 t/highlander.t create mode 100644 t/highlander2.t create mode 100644 t/html/dual_iter.exp create mode 100644 t/html/dual_iter.gen create mode 100644 t/html/dual_iter.html create mode 100644 t/html/highlander-15.exp create mode 100644 t/html/highlander-15.gen create mode 100644 t/html/highlander-5.exp create mode 100644 t/html/highlander-5.gen create mode 100644 t/html/highlander-50.exp create mode 100644 t/html/highlander-50.gen create mode 100644 t/html/highlander.html create mode 100644 t/html/highlander2-15.exp create mode 100644 t/html/highlander2-15.gen create mode 100644 t/html/highlander2-27.exp create mode 100644 t/html/highlander2-27.gen create mode 100644 t/html/highlander2-5.exp create mode 100644 t/html/highlander2-5.gen create mode 100644 t/html/highlander2.html create mode 100644 t/html/iter.exp create mode 100644 t/html/iter.gen create mode 100644 t/html/iter.html create mode 100644 t/html/iter2.exp create mode 100644 t/html/iter2.gen create mode 100644 t/html/iter2.html create mode 100644 t/html/table-alt.exp create mode 100644 t/html/table-alt.gen create mode 100644 t/html/table-alt.html create mode 100644 t/html/table.exp create mode 100644 t/html/table.gen create mode 100644 t/html/table.html create mode 100644 t/html/table2-table_ld-arrayref.exp create mode 100644 t/html/table2-table_ld-arrayref.gen create mode 100644 t/html/table2-table_ld-arrayref.html create mode 100644 t/html/table2-table_ld-coderef.exp create mode 100644 t/html/table2-table_ld-coderef.gen create mode 100644 t/html/table2-table_ld-coderef.html create mode 100644 t/html/table2-table_ld-default.exp create mode 100644 t/html/table2-table_ld-default.gen create mode 100644 t/html/table2-table_ld-default.html create mode 100644 t/html/table2-tr_ld-arrayref.exp create mode 100644 t/html/table2-tr_ld-arrayref.gen create mode 100644 t/html/table2-tr_ld-arrayref.html create mode 100644 t/html/table2-tr_ld-coderef.exp create mode 100644 t/html/table2-tr_ld-coderef.gen create mode 100644 t/html/table2-tr_ld-coderef.html create mode 100644 t/html/table2-tr_ld-default.gen create mode 100644 t/html/table2-tr_ld-default.html create mode 100644 t/html/table2-tr_ld_coderef.exp create mode 100644 t/html/table2.exp create mode 100644 t/html/table2.gen create mode 100644 t/html/table2.html create mode 100644 t/html/table2_code.html create mode 100644 t/html/table2_id.exp create mode 100644 t/html/table2_id.html create mode 100644 t/html/table2_tr_proc.html create mode 100644 t/html/unroll_select.exp create mode 100644 t/html/unroll_select.gen create mode 100644 t/html/unroll_select.html create mode 100644 t/iter.t create mode 100644 t/iter2.t create mode 100644 t/m/SelectData.pm create mode 100644 t/m/SimpleClass.pm create mode 100644 t/m/TestUtils.pm create mode 100644 t/not-used/Arsenal.pl create mode 100644 t/not-used/Arsenal.pm create mode 100644 t/position.t create mode 100644 t/q create mode 100644 t/replace_content.t create mode 100644 t/set_child_content.t create mode 100644 t/sibdex.t create mode 100644 t/siblings.t create mode 100644 t/table-alt.t create mode 100644 t/table.t create mode 100644 t/table2-table_ld.t create mode 100644 t/table2-tr_ld.t create mode 100644 t/table2.t create mode 100644 t/unroll_select.t create mode 100644 t/wrap_content.t diff --git a/Changes b/Changes new file mode 100644 index 0000000..9287d50 --- /dev/null +++ b/Changes @@ -0,0 +1,19 @@ +2006-04-10 U-LIFEBOOK\Administrator + + * removed dependancy on Array::Reform by uploading Array::Group + and changing dependancy to that. + +2006-01-31 metaperl + + * re-tooled highlander2 to use Params::Validate + +2006-01-21 metaperl + + * created iter2() and test case + +Revision history for Perl extension HTML::Element::Library. + +0.01 Sat Dec 25 18:36:02 2004 + - original version; created by h2xs 1.23 with options + -b 5.6.1 -A -X -n HTML::Element::Library + diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..c23f2f1 --- /dev/null +++ b/MANIFEST @@ -0,0 +1,99 @@ +Changes +CHANGES +lib/HTML/Element/Library.pm +lib/HTML/Element/Library/Changes.pod +Makefile.PL +MANIFEST This list of files +META.yml +README +t/00system.t +t/Arsenal.pl +t/Arsenal.pm +t/content_handler.t +t/data/3dig.dat +t/data/4dig.dat +t/data/table2.pm +t/dual_iter.t +t/highlander.t +t/highlander2.t +t/HTML-Element-Library.t +t/html/dual_iter.exp +t/html/dual_iter.gen +t/html/dual_iter.html +t/html/highlander-15.exp +t/html/highlander-15.gen +t/html/highlander-5.exp +t/html/highlander-5.gen +t/html/highlander-50.exp +t/html/highlander-50.gen +t/html/highlander.html +t/html/highlander2-15.exp +t/html/highlander2-15.gen +t/html/highlander2-27.exp +t/html/highlander2-27.gen +t/html/highlander2-5.exp +t/html/highlander2-5.gen +t/html/highlander2.html +t/html/iter.exp +t/html/iter.gen +t/html/iter.html +t/html/iter2.exp +t/html/iter2.gen +t/html/iter2.html +t/html/table-alt.exp +t/html/table-alt.gen +t/html/table-alt.html +t/html/table.exp +t/html/table.gen +t/html/table.html +t/html/table2-table_ld-arrayref.exp +t/html/table2-table_ld-arrayref.gen +t/html/table2-table_ld-arrayref.html +t/html/table2-table_ld-coderef.exp +t/html/table2-table_ld-coderef.gen +t/html/table2-table_ld-coderef.html +t/html/table2-table_ld-default.exp +t/html/table2-table_ld-default.gen +t/html/table2-table_ld-default.html +t/html/table2-tr_ld-arrayref.exp +t/html/table2-tr_ld-arrayref.gen +t/html/table2-tr_ld-arrayref.html +t/html/table2-tr_ld-coderef.exp +t/html/table2-tr_ld-coderef.gen +t/html/table2-tr_ld-coderef.html +t/html/table2-tr_ld-default.gen +t/html/table2-tr_ld-default.html +t/html/table2-tr_ld_coderef.exp +t/html/table2.exp +t/html/table2.gen +t/html/table2.html +t/html/table2_code.html +t/html/table2_id.exp +t/html/table2_id.html +t/html/table2_tr_proc.html +t/html/unroll_select.exp +t/html/unroll_select.gen +t/html/unroll_select.html +t/iter.t +t/iter2.t +t/m/SelectData.pm +t/m/SimpleClass.pm +t/m/TestUtils.pm +t/not-used/Arsenal.pl +t/not-used/Arsenal.pm +t/position.t +t/q +t/replace_content.t +t/SelectData.pm +t/set_child_content.t +t/sibdex.t +t/siblings.t +t/SimpleClass.pm +t/table-alt.t +t/table.t +t/table2-table_ld.t +t/table2-tr_ld.t +t/table2.t +t/TestUtils.pm +t/unroll_select.t +t/wrap_content.t diff --git a/META.yml b/META.yml new file mode 100644 index 0000000..13548e2 --- /dev/null +++ b/META.yml @@ -0,0 +1,18 @@ +# http://module-build.sourceforge.net/META-spec.html +#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# +name: HTML-Element-Library +version: 3.51 +version_from: lib/HTML/Element/Library.pm +installdirs: site +requires: + Array::Group: 1 + File::Slurp: 9999.06 + HTML::PrettyPrinter: 0.03 + HTML::Tree: 3.19 + List::MoreUtils: 0.09 + List::Rotation::Cycle: 1.003 + Params::Validate: 0.8 + Scalar::Listify: 0.02 + +distribution_type: module +generated_by: ExtUtils::MakeMaker version 6.17 diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..fc8fbe3 --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,50 @@ +use 5.006001; +use ExtUtils::MakeMaker; +# See lib/ExtUtils/MakeMaker.pm for details of how to influence +# the contents of the Makefile that is written. +WriteMakefile( + NAME => 'HTML::Element::Library', + VERSION_FROM => 'lib/HTML/Element/Library.pm', # finds $VERSION + PREREQ_PM => { + Array::Group => 1.00, + + File::Slurp => 9999.06, + + HTML::PrettyPrinter => 0.03, + HTML::Tree => 3.19, + + List::Rotation::Cycle => 1.003, + List::MoreUtils => 0.09, + + Params::Validate => 0.80, + + Scalar::Listify => 0.02, + }, + ($] >= 5.005 ? ## Add these new keywords supported since 5.005 + (ABSTRACT_FROM => 'lib/HTML/Element/Library.pm', # retrieve abstract from module + AUTHOR => 'Terrence Brannon ') : ()), +); + +sub MY::postamble { q{ + +cleandist: FORCE + make again; make cleanmanifest; make docs; make dist + +again: FORCE + make clean; perl Makefile.PL; make pm_to_blib + +cleanmanifest: realclean FORCE + rm MANIFEST ; perl Makefile.PL; touch MANIFEST; make manifest + +%.t: pm_to_blib FORCE + make; perl -Iblib/lib $@ + +docs : README CHANGES + +README: lib/HTML/Element/Library.pm + pod2text lib/HTML/Element/Library.pm > README + +CHANGES: lib/HTML/Element/Library/Changes.pod + pod2text lib/HTML/Element/Library/Changes.pod > CHANGES + +}; } diff --git a/README b/README new file mode 100644 index 0000000..9aee606 --- /dev/null +++ b/README @@ -0,0 +1,540 @@ +NAME + HTML::Element::Library - HTML::Element convenience functions + +SYNOPSIS + use HTML::Element::Library; + use HTML::TreeBuilder; + +DESCRIPTION + This method provides API calls for common actions on trees when using + HTML::Tree. + +METHODS + The test suite contains examples of each of these methods in a file + "t/$method.t" + + Positional Querying Methods + $elem->siblings + Return a list of all nodes under the same parent. + + $elem->sibdex + Return the index of $elem into the array of siblings of which it is a + part. HTML::ElementSuper calls this method "addr" but I don't think that + is a descriptive name. And such naming is deceptively close to the + "address" function of "HTML::Element". HOWEVER, in the interest of + backwards compatibility, both methods are available. + + $elem->addr + Same as sibdex + + $elem->position() + Returns the coordinates of this element in the tree it inhabits. This is + accomplished by succesively calling addr() on ancestor elements until + either a) an element that does not support these methods is found, or b) + there are no more parents. The resulting list is the n-dimensional + coordinates of the element in the tree. + + Element Decoration Methods + HTML::Element::Library::super_literal($text) + In HTML::Element, Sean Burke discusses super-literals. They are text + which does not get escaped. Great for includng Javascript in HTML. Also + great for including foreign language into a document. + + So, you basically toss "super_literal" your text and back comes your + text wrapped in a "~literal" element. + + One of these days, I'll around to writing a nice "EXPORT" section. + + Tree Rewriting Methods + $elem->replace_content($new_elem) + Replaces all of $elem's content with $new_elem. + + $elem->wrap_content($wrapper_element) + Wraps the existing content in the provided element. If the provided + element happens to be a non-element, a push_content is performed + instead. + + $elem->set_child_content(@look_down, $content) + This method looks down $tree using the criteria specified in @look_down using the the HTML::Element look_down() method. + + After finding the node, it detaches the node's content and pushes + $content as the node's content. + + $tree->content_handler($sid_value , $content) + This is a convenience method. Because the look_down criteria will often + simply be: + + id => 'fixme' + + to find things like: + + replace_content + + You can call this method to shorten your typing a bit. You can simply + type + + $elem->content_handler( fixme => 'new text' ) + + Instead of typing: + + $elem->set_child_content(sid => 'fixme', 'new text') + + $tree->highlander($subtree_span_id, $conditionals, @conditionals_args) + This allows for "if-then-else" style processing. Highlander was a movie + in which only one would survive. Well, in terms of a tree when looking + at a structure that you want to process in "if-then-else" style, only + one child will survive. For example, given this HTML template: + + + + Hello, does your mother know you're + using her AOL account? + + + Sorry, you're not old enough to enter + (and too dumb to lie about your age) + + + Welcome + + + + We only want one child of the "span" tag with id "age_dialog" to remain + based on the age of the person visiting the page. + + So, let's setup a call that will prune the subtree as a function of age: + + sub process_page { + my $age = shift; + my $tree = HTML::TreeBuilder->new_from_file('t/html/highlander.html'); + + $tree->highlander + (age_dialog => + [ + under10 => sub { $_[0] < 10} , + under18 => sub { $_[0] < 18} , + welcome => sub { 1 } + ], + $age + ); + + And there we have it. If the age is less than 10, then the node with id + "under10" remains. For age less than 18, the node with id "under18" + remains. Otherwise our "else" condition fires and the child with id + "welcome" remains. + + Tree-Building Methods: Single ("li") Iteration + This is best described by example. Given this HTML: + + Here are the things I need from the store: +
    +
  • Sample item
  • +
+ + We can unroll it like so: + + my $li = $tree->look_down(id => 'store_items'); + + my @items = qw(bread butter vodka); + + $tree->iter($li, @items); + + To produce this: + + + + Here are the things I need from the store: +
    +
  • bread
  • +
  • butter
  • +
  • vodka
  • +
+ + + + Tree-Building Methods: Select Unrolling + The "unroll_select" method has this API: + + $tree->unroll_select( + select_label => $id_label, + option_value => $closure, # how to get option value from data row + option_content => $closure, # how to get option content from data row + option_selected => $closure, # boolean to decide if SELECTED + data => $data # the data to be put into the SELECT + data_iter => $closure # the thing that will get a row of data + ); + + Here's an example: + + $tree->unroll_select( + select_label => 'clan_list', + option_value => sub { my $row = shift; $row->clan_id }, + option_content => sub { my $row = shift; $row->clan_name }, + option_selected => sub { my $row = shift; $row->selected }, + data => \@query_results, + data_iter => sub { my $data = shift; $data->next } + ) + + Tree-Building Methods: Table Generation + Matthew Sisk has a much more intuitive (imperative) way to generate + tables via his module HTML::ElementTable. However, for those with + callback fever, the following method is available. First, we look at a + nuts and bolts way to build a table using only standard HTML::Tree API + calls. Then the "table" method available here is discussed. + + Sample Model + package Simple::Class; + + use Set::Array; + + my @name = qw(bob bill brian babette bobo bix); + my @age = qw(99 12 44 52 12 43); + my @weight = qw(99 52 80 124 120 230); + + sub new { + my $this = shift; + bless {}, ref($this) || $this; + } + + sub load_data { + my @data; + + for (0 .. 5) { + push @data, { + age => $age[rand $#age] + int rand 20, + name => shift @name, + weight => $weight[rand $#weight] + int rand 40 + } + } + + Set::Array->new(@data); + } + + 1; + + Sample Usage: + my $data = Simple::Class->load_data; + ++$_->{age} for @$data + + Inline Code to Unroll a Table + HTML + + + + + + + + + + + + + + +
nameageweight
NATURE BOY RIC FLAIR 35 220
+ + + + The manual way (*NOT* recommended) + require 'simple-class.pl'; + use HTML::Seamstress; + + # load the view + my $seamstress = HTML::Seamstress->new_from_file('simple.html'); + + # load the model + my $o = Simple::Class->new; + my $data = $o->load_data; + + # find the and + my $table_node = $seamstress->look_down('id', 'load_data'); + my $iter_node = $table_node->look_down('id', 'iterate'); + my $table_parent = $table_node->parent; + + # drop the sample
and from the HTML + # only add them in if there is data in the model + # this is achieved via the $add_table flag + + $table_node->detach; + $iter_node->detach; + my $add_table; + + # Get a row of model data + while (my $row = shift @$data) { + + # We got row data. Set the flag indicating ok to hook the table into the HTML + ++$add_table; + + # clone the sample + my $new_iter_node = $iter_node->clone; + + # find the tags labeled name age and weight and + # set their content to the row data + $new_iter_node->content_handler($_ => $row->{$_}) + for qw(name age weight); + + $table_node->push_content($new_iter_node); + + } + + # reattach the table to the HTML tree if we loaded data into some table rows + + $table_parent->push_content($table_node) if $add_table; + + print $seamstress->as_HTML; + + $tree->table() : API call to Unroll a Table + require 'simple-class.pl'; + use HTML::Seamstress; + + # load the view + my $seamstress = HTML::Seamstress->new_from_file('simple.html'); + # load the model + my $o = Simple::Class->new; + + $seamstress->table + ( + # tell seamstress where to find the table, via the method call + # ->look_down('id', $gi_table). Seamstress detaches the table from the + # HTML tree automatically if no table rows can be built + + gi_table => 'load_data', + + # tell seamstress where to find the tr. This is a bit useless as + # the usually can be found as the first child of the parent + + gi_tr => 'iterate', + + # the model data to be pushed into the table + + table_data => $o->load_data, + + # the way to take the model data and obtain one row + # if the table data were a hashref, we would do: + # my $key = (keys %$data)[0]; my $val = $data->{$key}; delete $data->{$key} + + tr_data => sub { my ($self, $data) = @_; + shift(@{$data}) ; + }, + + # the way to take a row of data and fill the usually can be found as the first child of the parent + + gi_tr => ['iterate1', 'iterate2'], + + # the model data to be pushed into the table + + table_data => $o->load_data, + + # the way to take the model data and obtain one row + # if the table data were a hashref, we would do: + # my $key = (keys %$data)[0]; my $val = $data->{$key}; delete $data->{$key} + + tr_data => sub { my ($self, $data) = @_; + shift(@{$data}) ; + }, + + # the way to take a row of data and fill the usually can be found as the first child of the parent + + gi_tr => 'data_row', + + # the model data to be pushed into the table + + table_data => $o->load_data, + + # the way to take the model data and obtain one row + # if the table data were a hashref, we would do: + # my $key = (keys %$data)[0]; my $val = $data->{$key}; delete $data->{$key} + + tr_data => sub { my ($self, $data) = @_; + shift(@{$data}) ; + }, + + # the way to take a row of data and fill the
tags + + td_data => sub { my ($tr_node, $tr_data) = @_; + $tr_node->content_handler($_ => $tr_data->{$_}) + for qw(name age weight) } + + ); + + print $seamstress->as_HTML; + + Looping over Multiple Sample Rows + * HTML + + + + + + + + + + + + + + + + + + + + + + +
nameageweight
NATURE BOY RIC FLAIR 35 220
NATURE BOY RIC FLAIR 35 220
+ + + + * Only one change to last API call. + + This: + + gi_tr => 'iterate', + + becomes this: + + gi_tr => ['iterate1', 'iterate2'] + + $tree->table2() : New API Call to Unroll a Table + After 2 or 3 years with "table()", I began to develop production + websites with it and decided it needed a cleaner interface, particularly + in the area of handling the fact that "id" tags will be the same after + cloning a table row. + + First, I will give a dry listing of the function's argument parameters. + This will not be educational most likely. A better way to understand how + to use the function is to read through the incremental unrolling of the + function's interface given in conversational style after the dry + listing. But take your pick. It's the same information given in two + different ways. + + Dry/technical parameter documentation + "$tree->table2(%param)" takes the following arguments: + + * "table_ld => $look_down" : optional + How to find the "table" element in $tree. If $look_down is an + arrayref, then use "look_down". If it is a CODE ref, then call it, + passing it $tree. + + Defaults to "['_tag' => 'table']" if not passed in. + + * "table_data => $tabular_data" : required + The data to fill the table with. *Must* be passed in. + + * "table_proc => $code_ref" : not implemented + A subroutine to do something to the table once it is found. Not + currently implemented. Not obviously necessary. Just created because + there is a "tr_proc" and "td_proc". + + * "tr_ld => $look_down" : optional + Same as "table_ld" but for finding the table row elements. Please + note that the "tr_ld" is done on the table node that was found below + *instead* of the whole HTML tree. This makes sense. The "tr"s that + you want exist below the table that was just found. + + * "tr_data => $code_ref" : optional + How to take the "table_data" and return a row. Defaults to: + + sub { my ($self, $data) = @_; + shift(@{$data}) ; + } + + * "tr_proc => $code_ref" : optional + Something to do to the table row we are about to add to the table we + are making. Defaults to a routine which makes the "id" attribute + unique: + + sub { + my ($self, $tr, $tr_data, $row_count, $root_id) = @_; + $tr->attr(id => sprintf "%s_%d", $root_id, $row_count); + } + + * "td_proc => $code_ref" : required + This coderef will take the row of data and operate on the "td" cells + that are children of the "tr". See "t/table2.t" for several usage + examples. + + Conversational parameter documentation + The first thing you need is a table. So we need a look down for + that. If you don't give one, it defaults to + + ['_tag' => 'table'] + + What good is a table to display in without data to display?! So you + must supply a scalar representing your tabular data source. This + scalar might be an array reference, a "next"able iterator, a DBI + statement handle. Whatever it is, it can be iterated through to + build up rows of table data. These two required fields (the way to + find the table and the data to display in the table) are "table_ld" + and "table_data" respectively. A little more on "table_ld". If this + happens to be a CODE ref, then execution of the code ref is presumed + to return the "HTML::Element" representing the table in the HTML + tree. + + Next, we get the row or rows which serve as sample "tr" elements by + doing a "look_down" from the "table_elem". While normally one sample + row is enough to unroll a table, consider when you have alternating + table rows. This API call would need one of each row so that it can + cycle through the sample rows as it loops through the data. + Alternatively, you could always just use one row and make the + necessary changes to the single "tr" row by mutating the element in + "tr_proc", discussed below. The default "tr_ld" is "['_tag' => + 'tr']" but you can overwrite it. Note well, if you overwrite it with + a subroutine, then it is expected that the subroutine will return + the "HTML::Element"(s) which are "tr" element(s). The reason a + subroutine might be preferred is in the case that the HTML designers + gave you 8 sample "tr" rows but only one prototype row is needed. So + you can write a subroutine, to splice out the 7 rows you don't need + and leave the one sample row remaining so that this API call can + clone it and supply it to the "tr_proc" and "td_proc" calls. + + Now, as we move through the table rows with table data, we need to + do two different things on each table row: + + * get one row of data from the "table_data" via "tr_data" + The default procedure assumes the "table_data" is an array + reference and shifts a row off of it: + + sub { my ($self, $data) = @_; + shift(@{$data}) ; + } + + Your function MUST return undef when there is no more rows to + lay out. + + * take the "tr" element and mutate it via "tr_proc" + The default procedure simply makes the id of the table row + unique: + + sub { my ($self, $tr, $tr_data, $row_count, $root_id) = @_; + $tr->attr(id => sprintf "%s_%d", $root_id, $row_count); + } + + Now that we have our row of data, we call "td_proc" so that it can + take the data and the "td" cells in this "tr" and process them. This + function *must* be supplied. + + Whither a Table with No Rows + Often when a table has no rows, we want to display a message + indicating this to the view. Use conditional processing to decide + what to display: + + +
No Data is Good Data
+
+ + + + + + + + + + + + + + + +
nameageweight
NATURE BOY RIC FLAIR 35 220
+ + + +
+ +SEE ALSO + * HTML::Tree + A perl package for creating and manipulating HTML trees + + * HTML::ElementTable + An HTML::Tree - based module which allows for manipulation of + HTML trees using cartesian coordinations. + + * HTML::Seamstress + An HTML::Tree - based module inspired by XMLC + (), allowing for dynamic HTML + generation via tree rewriting. + +AUTHOR + Terrence Brannon, + +COPYRIGHT AND LICENSE + Copyright (C) 2004 by Terrence Brannon + + This library is free software; you can redistribute it and/or + modify it under the same terms as Perl itself, either Perl + version 5.8.4 or, at your option, any later version of Perl 5 + you may have available. + diff --git a/lib/HTML/Element/Library.pm b/lib/HTML/Element/Library.pm new file mode 100644 index 0000000..8f888b5 --- /dev/null +++ b/lib/HTML/Element/Library.pm @@ -0,0 +1,1622 @@ +package HTML::Element::Library; + +use 5.006001; +use strict; +use warnings; + + +our $DEBUG = 0; +#our $DEBUG = 1; + +use Array::Group qw(:all); +use Carp qw(confess); +use Data::Dumper; +use HTML::Element; +use List::MoreUtils qw/:all/; +use Params::Validate qw(:all); +use Scalar::Listify; +#use Tie::Cycle; +use List::Rotation::Cycle; + +our %EXPORT_TAGS = ( 'all' => [ qw() ] ); +our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); +our @EXPORT = qw(); + + + +our $VERSION = '3.51'; + + +# Preloaded methods go here. + +sub HTML::Element::siblings { + my $element = shift; + my $p = $element->parent; + return () unless $p; + $p->content_list; +} + +sub HTML::Element::sibdex { + + my $element = shift; + firstidx { $_ eq $element } $element->siblings + +} + +sub HTML::Element::addr { goto &HTML::Element::sibdex } + +sub HTML::Element::replace_content { + my $elem = shift; + $elem->delete_content; + $elem->push_content(@_); +} + +sub HTML::Element::wrap_content { + my($self, $wrap) = @_; + my $content = $self->content; + if (ref $content) { + $wrap->push_content(@$content); + @$content = ($wrap); + } + else { + $self->push_content($wrap); + } + $wrap; +} + +sub HTML::Element::Library::super_literal { + my($text) = @_; + + HTML::Element->new('~literal', text => $text); +} + + +sub HTML::Element::position { + # Report coordinates by chasing addr's up the + # HTML::ElementSuper tree. We know we've reached + # the top when a) there is no parent, or b) the + # parent is some HTML::Element unable to report + # it's position. + my $p = shift; + my @pos; + while ($p) { + my $a = $p->addr; + unshift(@pos, $a) if defined $a; + $p = $p->parent; + } + @pos; +} + + +sub HTML::Element::content_handler { + my ($tree, $id_name, $content) = @_; + + $tree->set_child_content(id => $id_name, $content); + +} + + +sub make_counter { + my $i = 1; + sub { + shift() . ':' . $i++ + } +} + + +sub HTML::Element::iter { + my ($tree, $p, @data) = @_; + + # warn 'P: ' , $p->attr('id') ; + # warn 'H: ' , $p->as_HTML; + + # my $id_incr = make_counter; + my @item = map { + my $new_item = clone $p; + $new_item->replace_content($_); + # $new_item->attr('id', $id_incr->( $p->attr('id') )); + $new_item; + } @data; + + $p->replace_with(@item); + +} + + +sub HTML::Element::iter2 { + + my $tree = shift; + + #warn "INPUT TO TABLE2: ", Dumper \@_; + + my %p = validate( + @_, { + wrapper_ld => { default => ['_tag' => 'dl'] }, + wrapper_data => 1, + wrapper_proc => { default => undef }, + item_ld => { default => sub { + my $tree = shift; + [ + $tree->look_down('_tag' => 'dt'), + $tree->look_down('_tag' => 'dd') + ]; + } + }, + item_data => { default => sub { my ($wrapper_data) = @_; + shift(@{$wrapper_data}) ; + }}, + item_proc => { + default => sub { + my ($item_elems, $item_data, $row_count) = @_; + $item_elems->[$_]->replace_content($item_data->[$_]) for (0,1) ; + $item_elems; + }}, + splice => { default => sub { + my ($container, @item_elems) = @_; + $container->splice_content(0, 2, @item_elems); + } + }, + debug => {default => 0} + } + ); + + warn "wrapper_data: " . Dumper $p{wrapper_data} if $p{debug} ; + + my $container = ref_or_ld($tree, $p{wrapper_ld}); + warn "wrapper_(preproc): " . $container->as_HTML if $p{debug} ; + $p{wrapper_proc}->($container) if defined $p{wrapper_proc} ; + warn "wrapper_(postproc): " . $container->as_HTML if $p{debug} ; + + my $_item_elems = $p{item_ld}->($container); + + + + my $row_count; + my @item_elem; + { + my $item_data = $p{item_data}->($p{wrapper_data}); + last unless defined $item_data; + + warn Dumper("item_data", $item_data); + + + my $item_elems = [ map { $_->clone } @{$_item_elems} ] ; + + if ($p{debug}) { + for (@{$item_elems}) { + warn "ITEM_ELEMS ", $_->as_HTML; + } + } + + my $new_item_elems = $p{item_proc}->($item_elems, $item_data, ++$row_count); + + if ($p{debug}) { + for (@{$new_item_elems}) { + warn "NEWITEM_ELEMS ", $_->as_HTML; + } + } + + + push @item_elem, @{$new_item_elems} ; + + redo; + } + + warn "pushing " . @item_elem . " elems " if $p{debug} ; + + $p{splice}->($container, @item_elem); + +} + +sub HTML::Element::dual_iter { + my ($parent, $data) = @_; + + my ($prototype_a, $prototype_b) = $parent->content_list; + + # my $id_incr = make_counter; + + my $i; + + @$data %2 == 0 or + confess 'dataset does not contain an even number of members'; + + my @iterable_data = ngroup 2 => @$data; + + my @item = map { + my ($new_a, $new_b) = map { clone $_ } ($prototype_a, $prototype_b) ; + $new_a->splice_content(0,1, $_->[0]); + $new_b->splice_content(0,1, $_->[1]); + #$_->attr('id', $id_incr->($_->attr('id'))) for ($new_a, $new_b) ; + ($new_a, $new_b) + } @iterable_data; + + $parent->splice_content(0, 2, @item); + +} + + +sub HTML::Element::set_child_content { + my $tree = shift; + my $content = pop; + my @look_down = @_; + + my $content_tag = $tree->look_down(@look_down); + + unless ($content_tag) { + warn "criteria [@look_down] not found"; + return; + } + + $content_tag->replace_content($content); + +} + +sub HTML::Element::highlander { + my ($tree, $local_root_id, $aref, @arg) = @_; + + ref $aref eq 'ARRAY' or confess + "must supply array reference"; + + my @aref = @$aref; + @aref % 2 == 0 or confess + "supplied array ref must have an even number of entries"; + + warn __PACKAGE__ if $DEBUG; + + my $survivor; + while (my ($id, $test) = splice @aref, 0, 2) { + warn $id if $DEBUG; + if ($test->(@arg)) { + $survivor = $id; + last; + } + } + + + my @id_survivor = (id => $survivor); + my $survivor_node = $tree->look_down(@id_survivor); +# warn $survivor; +# warn $local_root_id; +# warn $node; + + warn "survivor: $survivor" if $DEBUG; + warn "tree: " . $tree->as_HTML if $DEBUG; + + $survivor_node or die "search for @id_survivor failed in tree($tree): " . $tree->as_HTML; + + my $survivor_node_parent = $survivor_node->parent; + $survivor_node = $survivor_node->clone; + $survivor_node_parent->replace_content($survivor_node); + + warn "new tree: " . $tree->as_HTML if $DEBUG; + + $survivor_node; +} + + +sub HTML::Element::highlander2 { + my $tree = shift; + + my %p = validate(@_, { + cond => { type => ARRAYREF }, + cond_arg => { type => ARRAYREF, + default => [] + }, + debug => { default => 0 } + } + ); + + + my @cond = @{$p{cond}}; + @cond % 2 == 0 or confess + "supplied array ref must have an even number of entries"; + + warn __PACKAGE__ if $p{debug}; + + my @cond_arg = @{$p{cond_arg}}; + + my $survivor; my $then; + while (my ($id, $if_then) = splice @cond, 0, 2) { + + warn $id if $p{debug}; + my ($if, $_then); + + if (ref $if_then eq 'ARRAY') { + ($if, $_then) = @$if_then; + } else { + ($if, $_then) = ($if_then, sub {}); + } + + if ($if->(@cond_arg)) { + $survivor = $id; + $then = $_then; + last; + } + + } + + my @ld = (ref $survivor eq 'ARRAY') + ? @$survivor + : (id => $survivor) + ; + + warn "survivor: ", $survivor if $p{debug}; + warn "survivor_ld: ", Dumper \@ld if $p{debug}; + + + my $survivor_node = $tree->look_down(@ld); + + $survivor_node or confess + "search for @ld failed in tree($tree): " . $tree->as_HTML; + + my $survivor_node_parent = $survivor_node->parent; + $survivor_node = $survivor_node->clone; + $survivor_node_parent->replace_content($survivor_node); + + + # **************** NEW FUNCTIONALITY ******************* + + # apply transforms on survivor node + + + warn "SURV::pre_trans " . $survivor_node->as_HTML if $p{debug}; + $then->($survivor_node, @cond_arg); + warn "SURV::post_trans " . $survivor_node->as_HTML if $p{debug}; + + # **************** NEW FUNCTIONALITY ******************* + + + + + $survivor_node; +} + + +sub overwrite_action { + my ($mute_node, %X) = @_; + + $mute_node->attr($X{local_attr}{name} => $X{local_attr}{value}{new}); +} + + +sub HTML::Element::overwrite_attr { + my $tree = shift; + + $tree->mute_elem(@_, \&overwrite_action); +} + + + +sub HTML::Element::mute_elem { + my ($tree, $mute_attr, $closures, $post_hook) = @_; + + warn "my mute_node = $tree->look_down($mute_attr => qr/.*/) ;"; + my @mute_node = $tree->look_down($mute_attr => qr/.*/) ; + + for my $mute_node (@mute_node) { + my ($local_attr,$mute_key) = split /\s+/, $mute_node->attr($mute_attr); + my $local_attr_value_current = $mute_node->attr($local_attr); + my $local_attr_value_new = $closures->{$mute_key}->($tree, $mute_node, $local_attr_value_current); + $post_hook->( + $mute_node, + tree => $tree, + local_attr => { + name => $local_attr, + value => { + current => $local_attr_value_current, + new => $local_attr_value_new + } + } + ) if ($post_hook) ; + } +} + + + +sub HTML::Element::table { + + my ($s, %table) = @_; + + my $table = {}; + + # use Data::Dumper; warn Dumper \%table; + + # ++$DEBUG if $table{debug} ; + + + # Get the table element + $table->{table_node} = $s->look_down(id => $table{gi_table}); + $table->{table_node} or confess + "table tag not found via (id => $table{gi_table}"; + + # Get the prototype tr element(s) + my @table_gi_tr = listify $table{gi_tr} ; + my @iter_node = map + { + my $tr = $table->{table_node}->look_down(id => $_); + $tr or confess "tr with id => $_ not found"; + $tr; + } @table_gi_tr; + + warn "found " . @iter_node . " iter nodes " if $DEBUG; + # tie my $iter_node, 'Tie::Cycle', \@iter_node; + my $iter_node = List::Rotation::Cycle->new(@iter_node); + + # warn $iter_node; + warn Dumper ($iter_node, \@iter_node) if $DEBUG; + + # $table->{content} = $table{content}; + #$table->{parent} = $table->{table_node}->parent; + + + # $table->{table_node}->detach; + # $_->detach for @iter_node; + + my @table_rows; + + { + my $row = $table{tr_data}->($table, $table{table_data}); + last unless defined $row; + + # get a sample table row and clone it. + my $I = $iter_node->next; + warn "I: $I" if $DEBUG; + my $new_iter_node = $I->clone; + + + $table{td_data}->($new_iter_node, $row); + push @table_rows, $new_iter_node; + + redo; + } + + if (@table_rows) { + + my $replace_with_elem = $s->look_down(id => shift @table_gi_tr) ; + for (@table_gi_tr) { + $s->look_down(id => $_)->detach; + } + + $replace_with_elem->replace_with(@table_rows); + + } + +} + +sub ref_or_ld { + + my ($tree, $slot) = @_; + + if (ref($slot) eq 'CODE') { + $slot->($tree); + } else { + $tree->look_down(@$slot); + } +} + + + +sub HTML::Element::table2 { + + my $tree = shift; + + + + my %p = validate( + @_, { + table_ld => { default => ['_tag' => 'table'] }, + table_data => 1, + table_proc => { default => undef }, + + tr_ld => { default => ['_tag' => 'tr'] }, + tr_data => { default => sub { my ($self, $data) = @_; + shift(@{$data}) ; + }}, + tr_base_id => { default => undef }, + tr_proc => { default => sub {} }, + td_proc => 1, + debug => {default => 0} + } + ); + + warn "INPUT TO TABLE2: ", Dumper \@_ if $p{debug}; + + warn "table_data: " . Dumper $p{table_data} if $p{debug} ; + + my $table = {}; + + # use Data::Dumper; warn Dumper \%table; + + # ++$DEBUG if $table{debug} ; + + # Get the table element + warn 1; + $table->{table_node} = ref_or_ld( $tree, $p{table_ld} ) ; + warn 2; + $table->{table_node} or confess + "table tag not found via " . Dumper($p{table_ld}) ; + + warn "table: " . $table->{table_node}->as_HTML if $p{debug}; + + + # Get the prototype tr element(s) + my @proto_tr = ref_or_ld( $table->{table_node}, $p{tr_ld} ) ; + + warn "found " . @proto_tr . " iter nodes " if $p{debug}; + + @proto_tr or return ; + + if ($p{debug}) { + warn $_->as_HTML for @proto_tr; + } + my $proto_tr = List::Rotation::Cycle->new(@proto_tr); + + my $tr_parent = $proto_tr[0]->parent; + warn "parent element of trs: " . $tr_parent->as_HTML if $p{debug}; + + my $row_count; + + my @table_rows; + + { + my $row = $p{tr_data}->($table, $p{table_data}, $row_count); + warn "data row: " . Dumper $row if $p{debug}; + last unless defined $row; + + # wont work: my $new_iter_node = $table->{iter_node}->clone; + my $new_tr_node = $proto_tr->next->clone; + warn "new_tr_node: $new_tr_node" if $p{debug}; + + $p{tr_proc}->($tree, $new_tr_node, $row, $p{tr_base_id}, ++$row_count) + if defined $p{tr_proc}; + + warn "data row redux: " . Dumper $row if $p{debug}; + warn 3.3; + + $p{td_proc}->($new_tr_node, $row); + push @table_rows, $new_tr_node; + + warn 4.4; + + redo; + } + + $_->detach for @proto_tr; + + $tr_parent->push_content(@table_rows) if (@table_rows) ; + +} + + +sub HTML::Element::unroll_select { + + my ($s, %select) = @_; + + my $select = {}; + + my $select_node = $s->look_down(id => $select{select_label}); + + my $option = $select_node->look_down('_tag' => 'option'); + +# warn $option; + + + $option->detach; + + while (my $row = $select{data_iter}->($select{data})) + { +# warn Dumper($row); + my $o = $option->clone; + $o->attr('value', $select{option_value}->($row)); + $o->attr('SELECTED', 1) if ($select{option_selected}->($row)) ; + + $o->replace_content($select{option_content}->($row)); + $select_node->push_content($o); + } + + +} + + + +sub HTML::Element::set_sibling_content { + my ($elt, $content) = @_; + + $elt->parent->splice_content($elt->pindex + 1, 1, $content); + +} + +sub HTML::TreeBuilder::parse_string { + my ($package, $string) = @_; + + my $h = HTML::TreeBuilder->new; + HTML::TreeBuilder->parse($string); + +} + + + +1; +__END__ +# Below is stub documentation for your module. You'd better edit it! + +=head1 NAME + +HTML::Element::Library - HTML::Element convenience functions + +=head1 SYNOPSIS + + use HTML::Element::Library; + use HTML::TreeBuilder; + +=head1 DESCRIPTION + +This method provides API calls for common actions on trees when using +L. + +=head1 METHODS + +The test suite contains examples of each of these methods in a +file C + +=head2 Positional Querying Methods + +=head3 $elem->siblings + +Return a list of all nodes under the same parent. + +=head3 $elem->sibdex + +Return the index of C<$elem> into the array of siblings of which it is +a part. L calls this method C but I don't think +that is a descriptive name. And such naming is deceptively close to the +C
function of C. HOWEVER, in the interest of +backwards compatibility, both methods are available. + +=head3 $elem->addr + +Same as sibdex + +=head3 $elem->position() + +Returns the coordinates of this element in the tree it inhabits. +This is accomplished by succesively calling addr() on ancestor +elements until either a) an element that does not support these +methods is found, or b) there are no more parents. The resulting +list is the n-dimensional coordinates of the element in the tree. + +=head2 Element Decoration Methods + +=head3 HTML::Element::Library::super_literal($text) + +In L, Sean Burke discusses super-literals. They are +text which does not get escaped. Great for includng Javascript in +HTML. Also great for including foreign language into a document. + +So, you basically toss C your text and back comes +your text wrapped in a C<~literal> element. + +One of these days, I'll around to writing a nice C section. + +=head2 Tree Rewriting Methods + +=head3 $elem->replace_content(@new_elem) + +Replaces all of C<$elem>'s content with C<@new_elem>. + +=head3 $elem->wrap_content($wrapper_element) + +Wraps the existing content in the provided element. If the provided element +happens to be a non-element, a push_content is performed instead. + +=head3 $elem->set_child_content(@look_down, $content) + + This method looks down $tree using the criteria specified in @look_down using the the HTML::Element look_down() method. + +After finding the node, it detaches the node's content and pushes $content as the node's content. + +=head3 $tree->content_handler($sid_value , $content) + +This is a convenience method. Because the look_down criteria will often simply be: + + id => 'fixme' + +to find things like: + + replace_content + +You can call this method to shorten your typing a bit. You can simply type + + $elem->content_handler( fixme => 'new text' ) + +Instead of typing: + + $elem->set_child_content(sid => 'fixme', 'new text') + +=head3 $tree->highlander($subtree_span_id, $conditionals, @conditionals_args) + +This allows for "if-then-else" style processing. Highlander was a movie in +which only one would survive. Well, in terms of a tree when looking at a +structure that you want to process in C style, only one child +will survive. For example, given this HTML template: + + + + Hello, does your mother know you're + using her AOL account? + + + Sorry, you're not old enough to enter + (and too dumb to lie about your age) + + + Welcome + + + +We only want one child of the C tag with id C to remain +based on the age of the person visiting the page. + +So, let's setup a call that will prune the subtree as a function of age: + + sub process_page { + my $age = shift; + my $tree = HTML::TreeBuilder->new_from_file('t/html/highlander.html'); + + $tree->highlander + (age_dialog => + [ + under10 => sub { $_[0] < 10} , + under18 => sub { $_[0] < 18} , + welcome => sub { 1 } + ], + $age + ); + +And there we have it. If the age is less than 10, then the node with +id C remains. For age less than 18, the node with id C +remains. +Otherwise our "else" condition fires and the child with id C remains. + +=head3 $tree->highlander2($tree, $conditionals, @conditionals_args) + +Right around the same time that C came into being, Seamstress +began to tackle tougher and tougher processing problems. It became clear that +a more powerful highlander was needed... one that not only snipped the tree +of the nodes that should not survive, but one that allows for +post-processing of the survivor node. And one that was more flexible with +how to find the nodes to snip. + +Thus (drum roll) C. + +So let's look at our HTML which requires post-selection processing: + + + + Hello, little AGE-year old, + does your mother know you're using her AOL account? + + + Sorry, you're only AGE + (and too dumb to lie about your age) + + + Welcome, isn't it good to be AGE years old? + + + +In this case, a branch survives, but it has dummy data in it. We must take +the surviving segment of HTML and rewrite the age C with the age. +Here is how we use C to do so: + + sub replace_age { + my $branch = shift; + my $age = shift; + $branch->look_down(id => 'age')->replace_content($age); + } + + my $if_then = $tree->look_down(id => 'age_dialog'); + + $if_then->highlander2( + cond => [ + under10 => [ + sub { $_[0] < 10} , + \&replace_age + ], + under18 => [ + sub { $_[0] < 18} , + \&replace_age + ], + welcome => [ + sub { 1 }, + \&replace_age + ] + ], + cond_arg => [ $age ] + ); + +We pass it the tree (C<$if_then>), an arrayref of conditions +(C) and an arrayref of arguments which are passed to the +Cs and to the replacement subs. + +The C, C and C are id attributes in the +tree of the siblings of which only one will survive. However, +should you need to do +more complex look-downs to find the survivor, +then supply an array ref instead of a simple +scalar: + + + $if_then->highlander2( + cond => [ + [class => 'r12'] => [ + sub { $_[0] < 10} , + \&replace_age + ], + [class => 'z22'] => [ + sub { $_[0] < 18} , + \&replace_age + ], + [class => 'w88'] => [ + sub { 1 }, + \&replace_age + ] + ], + cond_arg => [ $age ] + ); + + +=head3 $tree->overwrite_attr($mutation_attr => $mutating_closures) + +This method is designed for taking a tree and reworking a set of nodes in +a stereotyped fashion. For instance let's say you have 3 remote image +archives, but you don't want to put long URLs in your img src +tags for reasons of abstraction, re-use and brevity. So instead you do this: + + + + + +and then when the tree of HTML is being processed, you make this call: + + my %closures = ( + lnc => sub { my ($tree, $mute_node, $attr_value)= @_; "http://lnc.usc.edu$attr_value" }, + playboy => sub { my ($tree, $mute_node, $attr_value)= @_; "http://playboy.com$attr_value" } + foobar => sub { my ($tree, $mute_node, $attr_value)= @_; "http://foobar.info$attr_value" } + ) + + $tree->overwrite_attr(fixup => \%closures) ; + +and the tags come out modified like so: + + + + + +=head3 $tree->mute_elem($mutation_attr => $mutating_closures, [ $post_hook ] ) + +This is a generalization of C. C +assumes the return value of the +closure is supposed overwrite an attribute value and does it for you. +C is a more general function which does nothing but +hand the closure the element and let it mutate it as it jolly well pleases :) + +In fact, here is the implementation of C +to give you a taste of how C is used: + + sub overwrite_action { + my ($mute_node, %X) = @_; + + $mute_node->attr($X{local_attr}{name} => $X{local_attr}{value}{new}); + } + + + sub HTML::Element::overwrite_attr { + my $tree = shift; + + $tree->mute_elem(@_, \&overwrite_action); + } + + + + +=head2 Tree-Building Methods: Unrolling an array via a single sample element (
    container) + +This is best described by example. Given this HTML: + + Here are the things I need from the store: +
      +
    • Sample item
    • +
    + +We can unroll it like so: + + my $li = $tree->look_down(class => 'store_items'); + + my @items = qw(bread butter vodka); + + $tree->iter($li => @items); + +To produce this: + + + + + Here are the things I need from the store: +
      +
    • bread
    • +
    • butter
    • +
    • vodka
    • +
    + + + +=head2 Tree-Building Methods: Unrolling an array via n sample elements (
    container) + +C was fine for awhile, but some things +(e.g. definition lists) need a more general function to make them easy to +do. Hence C. This function will be explained by example of unrolling +a simple definition list. + +So here's our mock-up HTML from the designer: + +
    +
    + Artist +
    +
    + A person who draws blood. +
    + +
    + Musician +
    +
    + A clone of Iggy Pop. +
    + +
    + Poet +
    +
    + A relative of Edgar Allan Poe. +
    + +
    sample header
    +
    sample data
    + +
    + + +And we want to unroll our data set: + + my @items = ( + ['the pros' => 'never have to worry about service again'], + ['the cons' => 'upfront extra charge on purchase'], + ['our choice' => 'go with the extended service plan'] + ); + + +Now, let's make this problem a bit harder to show off the power of C. +Let's assume that we want only the last
    and it's accompanying
    +(the one with "sample data") to be used as the sample data +for unrolling with our data set. Let's further assume that we want them to +remain in the final output. + +So now, the API to C will be discussed and we will explain how our +goal of getting our data into HTML fits into the API. + +=over 4 + +=item * wrapper_ld + +This is how to look down and find the container of all the elements we will +be unrolling. The
    tag is the container for the dt and dd tags we will be +unrolling. + +If you pass an anonymous subroutine, then it is presumed that execution of +this subroutine will return the HTML::Element representing the container tag. +If you pass an array ref, then this will be dereferenced and passed to +C. + +default value: C<< ['_tag' => 'dl'] >> + +Based on the mock HTML above, this default is fine for finding our container +tag. So let's move on. + +=item * wrapper_data + +This is an array reference of data that we will be putting into the container. +You must supply this. C<@items> above is our C. + +=item * wrapper_proc + +After we find the container via C, we may want to pre-process +some aspect of this tree. In our case the first two sets of dt and dd need +to be removed, leaving the last dt and dd. So, we supply a C +which will do this. + +default: undef + +=item * item_ld + +This anonymous subroutine returns an array ref of Cs that will +be cloned and populated with item data +(item data is a "row" of C). + +default: returns an arrayref consisting of the dt and dd element inside the +container. + +=item * item_data + +This is a subroutine that takes C and retrieves one "row" +to be "pasted" into the array ref of Cs found via C. +I hope that makes sense. + +default: shifts C. + +=item * item_proc + +This is a subroutine that takes the C and the Cs +found via C and produces an arrayref of Cs which will +eventually be spliced into the container. + +Note that this subroutine MUST return the new items. This is done +So that more items than were passed in can be returned. This is +useful when, for example, you must return 2 dts for an input data item. +And when would you do this? When a single term has multiple spellings +for instance. + +default: expects C to be an arrayref of two elements and +C to be an arrayref of two Cs. It replaces the +content of the Cs with the C. + +=item * splice + +After building up an array of C<@item_elems>, the subroutine passed as +C will be given the parent container HTML::Element and the +C<@item_elems>. How the C<@item_elems> end up in the container is up to this +routine: it could put half of them in. It could unshift them or whatever. + +default: C<< $container->splice_content(0, 2, @item_elems) >> +In other words, kill the 2 sample elements with the newly generated +@item_elems + +=back + +So now that we have documented the API, let's see the call we need: + + $tree->iter2( + # default wrapper_ld ok. + wrapper_data => \@items, + wrapper_proc => sub { + my ($container) = @_; + + # only keep the last 2 dts and dds + my @content_list = $container->content_list; + $container->splice_content(0, @content_list - 2); + }, + + # default item_ld is fine. + # default item_data is fine. + # default item_proc is fine. + splice => sub { + my ($container, @item_elems) = @_; + $container->unshift_content(@item_elems); + }, + debug => 1, + ); + + +=head2 Tree-Building Methods: Select Unrolling + +The C method has this API: + + $tree->unroll_select( + select_label => $id_label, + option_value => $closure, # how to get option value from data row + option_content => $closure, # how to get option content from data row + option_selected => $closure, # boolean to decide if SELECTED + data => $data # the data to be put into the SELECT + data_iter => $closure # the thing that will get a row of data + ); + +Here's an example: + + $tree->unroll_select( + select_label => 'clan_list', + option_value => sub { my $row = shift; $row->clan_id }, + option_content => sub { my $row = shift; $row->clan_name }, + option_selected => sub { my $row = shift; $row->selected }, + data => \@query_results, + data_iter => sub { my $data = shift; $data->next } + ) + + + +=head2 Tree-Building Methods: Table Generation + +Matthew Sisk has a much more intuitive (imperative) +way to generate tables via his module +L. +However, for those with callback fever, the following +method is available. First, we look at a nuts and bolts way to build a table +using only standard L API calls. Then the C method +available here is discussed. + +=head3 Sample Model + + package Simple::Class; + + use Set::Array; + + my @name = qw(bob bill brian babette bobo bix); + my @age = qw(99 12 44 52 12 43); + my @weight = qw(99 52 80 124 120 230); + + + sub new { + my $this = shift; + bless {}, ref($this) || $this; + } + + sub load_data { + my @data; + + for (0 .. 5) { + push @data, { + age => $age[rand $#age] + int rand 20, + name => shift @name, + weight => $weight[rand $#weight] + int rand 40 + } + } + + Set::Array->new(@data); + } + + + 1; + + +=head4 Sample Usage: + + my $data = Simple::Class->load_data; + ++$_->{age} for @$data + +=head3 Inline Code to Unroll a Table + +=head4 HTML + + + +
    + + + + + + + + + + + +
    nameageweight
    NATURE BOY RIC FLAIR 35 220
    + + + + +=head4 The manual way (*NOT* recommended) + + require 'simple-class.pl'; + use HTML::Seamstress; + + # load the view + my $seamstress = HTML::Seamstress->new_from_file('simple.html'); + + # load the model + my $o = Simple::Class->new; + my $data = $o->load_data; + + # find the and + my $table_node = $seamstress->look_down('id', 'load_data'); + my $iter_node = $table_node->look_down('id', 'iterate'); + my $table_parent = $table_node->parent; + + + # drop the sample
    and from the HTML + # only add them in if there is data in the model + # this is achieved via the $add_table flag + + $table_node->detach; + $iter_node->detach; + my $add_table; + + # Get a row of model data + while (my $row = shift @$data) { + + # We got row data. Set the flag indicating ok to hook the table into the HTML + ++$add_table; + + # clone the sample + my $new_iter_node = $iter_node->clone; + + # find the tags labeled name age and weight and + # set their content to the row data + $new_iter_node->content_handler($_ => $row->{$_}) + for qw(name age weight); + + $table_node->push_content($new_iter_node); + + } + + # reattach the table to the HTML tree if we loaded data into some table rows + + $table_parent->push_content($table_node) if $add_table; + + print $seamstress->as_HTML; + + + +=head3 $tree->table() : API call to Unroll a Table + + require 'simple-class.pl'; + use HTML::Seamstress; + + # load the view + my $seamstress = HTML::Seamstress->new_from_file('simple.html'); + # load the model + my $o = Simple::Class->new; + + $seamstress->table + ( + # tell seamstress where to find the table, via the method call + # ->look_down('id', $gi_table). Seamstress detaches the table from the + # HTML tree automatically if no table rows can be built + + gi_table => 'load_data', + + # tell seamstress where to find the tr. This is a bit useless as + # the usually can be found as the first child of the parent + + gi_tr => 'iterate', + + # the model data to be pushed into the table + + table_data => $o->load_data, + + # the way to take the model data and obtain one row + # if the table data were a hashref, we would do: + # my $key = (keys %$data)[0]; my $val = $data->{$key}; delete $data->{$key} + + tr_data => sub { my ($self, $data) = @_; + shift(@{$data}) ; + }, + + # the way to take a row of data and fill the + + + + + + + + diff --git a/t/html/table2-tr_ld-arrayref.gen b/t/html/table2-tr_ld-arrayref.gen new file mode 100644 index 0000000..0b96ad5 --- /dev/null +++ b/t/html/table2-tr_ld-arrayref.gen @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/t/html/table2-tr_ld-arrayref.html b/t/html/table2-tr_ld-arrayref.html new file mode 100644 index 0000000..19e0c51 --- /dev/null +++ b/t/html/table2-tr_ld-arrayref.html @@ -0,0 +1,80 @@ + + + + Complex HTML Table + + + +

    Complex HTML Table

    + +

    + This table comes from + + the w3 spec on tables + . I am using it to try out the table2() API call + that is part of the new release of + + HTML::Element::Library + . +

    + + +

    + +

    tags + + td_data => sub { my ($tr_node, $tr_data) = @_; + $tr_node->content_handler($_ => $tr_data->{$_}) + for qw(name age weight) } + + ); + + + print $seamstress->as_HTML; + + + +=head4 Looping over Multiple Sample Rows + +* HTML + + + + + + + + + + + + + + + + + + + + + + +
    nameageweight
    NATURE BOY RIC FLAIR 35 220
    NATURE BOY RIC FLAIR 35 220
    + + + + +* Only one change to last API call. + +This: + + gi_tr => 'iterate', + +becomes this: + + gi_tr => ['iterate1', 'iterate2'] + +=head3 $tree->table2() : New API Call to Unroll a Table + +After 2 or 3 years with C, I began to develop +production websites with it and decided it needed a cleaner +interface, particularly in the area of handling the fact that +C tags will be the same after cloning a table row. + +First, I will give a dry listing of the function's argument parameters. +This will not be educational most likely. A better way to understand how +to use the function is to read through the incremental unrolling of the +function's interface given in conversational style after the dry listing. +But take your pick. It's the same information given in two different +ways. + +=head4 Dry/technical parameter documentation + +C<< $tree->table2(%param) >> takes the following arguments: + +=over + +=item * C<< table_ld => $look_down >> : optional + +How to find the C element in C<$tree>. If C<$look_down> is an +arrayref, then use C. If it is a CODE ref, then call it, +passing it C<$tree>. + +Defaults to C<< ['_tag' => 'table'] >> if not passed in. + +=item * C<< table_data => $tabular_data >> : required + +The data to fill the table with. I be passed in. + +=item * C<< table_proc => $code_ref >> : not implemented + +A subroutine to do something to the table once it is found. +Not currently implemented. Not obviously necessary. Just +created because there is a C and C. + +=item * C<< tr_ld => $look_down >> : optional + +Same as C but for finding the table row elements. Please note +that the C is done on the table node that was found I +of the whole HTML tree. This makes sense. The Cs that you want exist +below the table that was just found. + +Defaults to C<< ['_tag' => 'tr'] >> if not passed in. + +=item * C<< tr_data => $code_ref >> : optional + +How to take the C and return a row. Defaults to: + + sub { my ($self, $data) = @_; + shift(@{$data}) ; + } + +=item * C<< tr_proc => $code_ref >> : optional + +Something to do to the table row we are about to add to the +table we are making. Defaults to a routine which makes the C +attribute unique: + + sub { + my ($self, $tr, $tr_data, $tr_base_id, $row_count) = @_; + $tr->attr(id => sprintf "%s_%d", $tr_base_id, $row_count); + } + +=item * C<< td_proc => $code_ref >> : required + +This coderef will take the row of data and operate on the C. See C for several usage examples. + +Here's a sample one: + + sub { + my ($tr, $data) = @_; + my @td = $tr->look_down('_tag' => 'td'); + for my $i (0..$#td) { + $td[$i]->splice_content(0, 1, $data->[$i]); + } + } + +=cut + +=head4 Conversational parameter documentation + +The first thing you need is a table. So we need a look down for that. If you +don't give one, it defaults to + + ['_tag' => 'table'] + +What good is a table to display in without data to display?! +So you must supply a scalar representing your tabular +data source. This scalar might be an array reference, a Cable iterator, +a DBI statement handle. Whatever it is, it can be iterated through to build +up rows of table data. +These two required fields (the way to find the table and the data to +display in the table) are C and C +respectively. A little more on C. If this happens to be a CODE ref, +then execution +of the code ref is presumed to return the C +representing the table in the HTML tree. + +Next, we get the row or rows which serve as sample C elements by doing +a C from the C. While normally one sample row +is enough to unroll a table, consider when you have alternating +table rows. This API call would need one of each row so that it can +cycle through the +sample rows as it loops through the data. +Alternatively, you could always just use one row and +make the necessary changes to the single C row by +mutating the element in C, +discussed below. The default C is +C<< ['_tag' => 'tr'] >> but you can overwrite it. Note well, if you overwrite +it with a subroutine, then it is expected that the subroutine will return +the C(s) +which are C element(s). +The reason a subroutine might be preferred is in the case +that the HTML designers gave you 8 sample C rows but only one +prototype row is needed. +So you can write a subroutine, to splice out the 7 rows you don't need +and leave the one sample +row remaining so that this API call can clone it and supply it to +the C and C calls. + +Now, as we move through the table rows with table data, +we need to do two different things on +each table row: + +=over 4 + +=item * get one row of data from the C via C + +The default procedure assumes the C is an array reference and +shifts a row off of it: + + sub { my ($self, $data) = @_; + shift(@{$data}) ; + } + +Your function MUST return undef when there is no more rows to lay out. + +=item * take the C element and mutate it via C + +The default procedure simply makes the id of the table row unique: + + sub { my ($self, $tr, $tr_data, $row_count, $root_id) = @_; + $tr->attr(id => sprintf "%s_%d", $root_id, $row_count); + } + +=back + +Now that we have our row of data, we call C so that it can +take the data and the C and process them. +This function I be supplied. + + +=head3 Whither a Table with No Rows + +Often when a table has no rows, we want to display a message +indicating this to the view. Use conditional processing to decide what +to display: + + +
    cells that +are children of the C
    cells in this C
    No Data is Good Data
    + + + + + + + + + + + + + + + + +
    nameageweight
    NATURE BOY RIC FLAIR 35 220
    + + + +
    + + + + +=head1 SEE ALSO + +=over + +=item * L + +A perl package for creating and manipulating HTML trees + +=item * L + +An L - based module which allows for manipulation of HTML +trees using cartesian coordinations. + +=item * L + +An L - based module inspired by +XMLC (L), allowing for dynamic +HTML generation via tree rewriting. + +=head1 TODO + +=over + +=item * highlander2 + +currently the API expects the subtrees to survive or be pruned to be +identified by id: + + $if_then->highlander2([ + under10 => sub { $_[0] < 10} , + under18 => sub { $_[0] < 18} , + welcome => [ + sub { 1 }, + sub { + my $branch = shift; + $branch->look_down(id => 'age')->replace_content($age); + } + ] + ], + $age + ); + +but, it should be more flexible. the C, and C are +expected to be ids in the tree... but it is not hard to have a check to +see if this field is an array reference and if it, then to do a look +down instead: + + $if_then->highlander2([ + [class => 'under10'] => sub { $_[0] < 10} , + [class => 'under18'] => sub { $_[0] < 18} , + [class => 'welcome'] => [ + sub { 1 }, + sub { + my $branch = shift; + $branch->look_down(id => 'age')->replace_content($age); + } + ] + ], + $age + ); + + + +=cut + +=head1 SEE ALSO + +L + +=head1 AUTHOR + +Terrence Brannon, Etbone@cpan.orgE + +Many thanks to BARBIE for his RT bug report. + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2004 by Terrence Brannon + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself, either Perl version 5.8.4 or, +at your option, any later version of Perl 5 you may have available. + + +=cut diff --git a/lib/HTML/Element/Library/Changes.pod b/lib/HTML/Element/Library/Changes.pod new file mode 100644 index 0000000..10abda7 --- /dev/null +++ b/lib/HTML/Element/Library/Changes.pod @@ -0,0 +1,6 @@ +=head1 CHANGES + +=head2 1.9 + +Added the C method to make creating HTML tables easier. Based +on 2 years of using the original C method diff --git a/t/00system.t b/t/00system.t new file mode 100644 index 0000000..10066ce --- /dev/null +++ b/t/00system.t @@ -0,0 +1,46 @@ +# Welcome to a -*- perl -*- test script +use strict; +use Test::More qw(no_plan); + +sub req_ver { + my $string = shift; + my $eval = "#Using $string version v\$${string}::VERSION\n"; + my $eval2 = sprintf 'warn "%s"', $eval; + require_ok($string); + eval $eval2 ; +} + +my @module = + qw( + Array::Group + File::Slurp + + HTML::PrettyPrinter + HTML::Tree + HTML::Element + HTML::Parser + HTML::Entities + HTML::Tagset + + List::Rotation::Cycle + List::MoreUtils + + Params::Validate + + Scalar::Listify + ) ; + +req_ver($_) for @module; + +warn "# Running under perl version $] for $^O", + (chr(65) eq 'A') ? "\n" : " in a non-ASCII world\n"; +warn "# Win32::BuildNumber ", &Win32::BuildNumber(), "\n" + if defined(&Win32::BuildNumber) and defined &Win32::BuildNumber(); +warn "# MacPerl verison $MacPerl::Version\n" + if defined $MacPerl::Version; +warn sprintf + "# Current time local: %s\n# Current time GMT: %s\n", + scalar(localtime($^T)), scalar(gmtime($^T)); + +ok 1; + diff --git a/t/Arsenal.pl b/t/Arsenal.pl new file mode 100644 index 0000000..eb18749 --- /dev/null +++ b/t/Arsenal.pl @@ -0,0 +1,4 @@ +use lib '.'; +use Arsenal; + +Arsenal->new->load_data; diff --git a/t/Arsenal.pm b/t/Arsenal.pm new file mode 100644 index 0000000..62a45fe --- /dev/null +++ b/t/Arsenal.pm @@ -0,0 +1,70 @@ +package Arsenal; + +use strict; +use Data::Dumper; + +my %player; + +sub new { + my $this = shift; + bless {}, ref($this) || $this; +} + +my $number = qr!\d{1,2}!; +my $name = qr!\w+(?:\s\w{2,}){1,2}!; +my $position = qr!\w!; +my $height = qr!\d[-]\d{1,2}!; +my $weight = qr!\d{2,3}!; +my $birthday = qr!\w{3}\s\d{1,2},\s\d{4}!; +my $birthplace= qr!\w+(?:\s\w+)*(?:,\s\S+)*!; + +sub load_data { + my @data; + + while () { + last if /__END__/; + + @player{qw(number name pos height weight birthday birthplace)} + = + m! + ($number)\s+ + ($name)\s+ + ($position)\s+ + ($height)\s+ + ($weight)\s+ + ($birthday)\s+ + ($birthplace) + !x; + + warn $_; + warn Dumper \%player; + } +} + +1; +__DATA__ +24 Manuel Almunia G 6-3 190 May 19, 1977 Pamplona, Spain + 10 Dennis Bergkamp F 6-0 172 May 10, 1969 Amsterdam, Netherlands + 23 Sol Campbell D 6-2 201 Sep 18, 1974 Newham, England + 22 Gael Clichy D 5-11 159 Jul 26, 1985 Clichy, France + 3 Ashley Cole D 5-7 148 Dec 20, 1980 Stepney, England + 18 Pascal Cygan D 6-4 192 Apr 19, 1974 Lens, France + 27 Emmanuel Eboue D 5-10 159 Jun 4, 1983 Abidjan, Cote d'Ivoire + 15 Francesc Fabregas Soler M 5-7 152 Apr 4, 1987 Arenys del Mar, Spain + 16 Mathieu Flamini M 5-10 148 Mar 7, 1984 Marseille, France + 40 Ryan Garry D 6-2 181 Sep 29, 1983 Hornchurch, England + 14 Thierry Henry F 6-2 179 Aug 17, 1977 Paris, France + 13 Aliksandr Hleb M 6-1 154 May 1, 1981 Minsk, USSR + 12 Lauren D 5-11 157 Jan 19, 1977 Londi Kribi, Cameroon + 1 Jens Lehmann G 6-3 192 Nov 10, 1969 Essen, West Germany + 8 Fredrik Ljungberg M 5-9 165 Apr 16, 1977 Halmstads, Sweden + 26 Quincy Owusu Abeyie F 5-11 163 Apr 15, 1986 Amsterdam, Netherlands + 7 Robert Pires M 6-1 163 Oct 29, 1973 Reims, France + 21 Mart Poom G 6-4 187 Feb 3, 1972 Tallinn, USSR + 9 Jose Antonio Reyes F 6-0 181 Sep 1, 1983 Utrera, Spain + 20 Philippe Senderos D 6-3 185 Feb 14, 1985 Geneva, Switzerland + 19 Gilberto Silva M 6-3 172 Oct 7, 1976 Belo Horizonte, Brazil + 17 Alexandre Song M 6-0 168 Apr 9, 1987 Cameroon + 28 Kolo Toure D 6-0 168 Mar 19, 1981 Sokoura Bouake, Cote d'Ivoire + 11 Robin van Persie F 6-0 157 Aug 6, 1983 Rotterdam, Netherlands +__END__ diff --git a/t/HTML-Element-Library.t b/t/HTML-Element-Library.t new file mode 100644 index 0000000..83f9e44 --- /dev/null +++ b/t/HTML-Element-Library.t @@ -0,0 +1,17 @@ +# Before `make install' is performed this script should be runnable with +# `make test'. After `make install' it should work as `perl HTML-Element-Library.t' + +######################### + +# change 'tests => 1' to 'tests => last_test_to_print'; + +use Test; +BEGIN { plan tests => 1 }; +use HTML::Element::Library; +ok(1); # If we made it this far, we're ok. + +######################### + +# Insert your test code below, the Test::More module is use()ed here so read +# its man page ( perldoc Test::More ) for help writing this test script. + diff --git a/t/SelectData.pm b/t/SelectData.pm new file mode 100644 index 0000000..65ce175 --- /dev/null +++ b/t/SelectData.pm @@ -0,0 +1,22 @@ +package SelectData; + + + +my @clan_data = ( + { clan_name => 'janglers', clan_id => 12, selected => 1 }, + { clan_name => 'thugknights', clan_id => 14 }, + { clan_name => 'cavaliers' , clan_id => 13 } + ); + + +sub new { + my $this = shift; + bless {}, ref($this) || $this; +} + +sub load_data { + \@clan_data +} + + +1; diff --git a/t/SimpleClass.pm b/t/SimpleClass.pm new file mode 100644 index 0000000..d0f4a75 --- /dev/null +++ b/t/SimpleClass.pm @@ -0,0 +1,29 @@ +package SimpleClass; + + +my @name = qw(bob bill brian babette bobo bix); +my @age = qw(99 12 44 52 12 43); +my @weight = qw(99 52 80 124 120 230); + + +sub new { + my $this = shift; + bless {}, ref($this) || $this; +} + +sub load_data { + my @data; + + for (0 .. 5) { + push @data, { + age => shift @age, + name => shift @name, + weight => shift @weight + } + } + + \@data +} + + +1; diff --git a/t/TestUtils.pm b/t/TestUtils.pm new file mode 100644 index 0000000..e2d2222 --- /dev/null +++ b/t/TestUtils.pm @@ -0,0 +1,29 @@ +package TestUtils; + +use HTML::PrettyPrinter; +use FileHandle; +use File::Slurp; + +require Exporter; +@ISA=qw(Exporter); +@EXPORT = qw(ptree html_dir); + +sub html_dir { + 't/html/' +} + +sub ptree { + my $tree = shift or die 'must supply tree'; + my $out = shift or die 'must supply outfile'; + + my $hpp = HTML::PrettyPrinter->new + (tabify => 0, allow_forced_nl => 1, quote_attr => 1); + my $lines = $hpp->format($tree); + + write_file $out, @$lines; + join '', @$lines; +} + + + +1; diff --git a/t/content_handler.t b/t/content_handler.t new file mode 100644 index 0000000..6913cce --- /dev/null +++ b/t/content_handler.t @@ -0,0 +1,34 @@ +use strict; +use Test::More qw(no_plan); + +use HTML::Element::Library; + + +my $t1; +my $lol; +$t1 = HTML::Element->new_from_lol + ( + $lol = + ['html', + ['head', + [ 'title', 'I like stuff!' ], + ], + ['body', {id => 'corpus'}, + { + 'lang', 'en-JP'}, + 'stuff', + ['p', 'um, p < 4!', {'class' => 'par123'}], + ['div', {foo => 'bar'}, '123'], # at 0.1.2 + ['div', {jack => 'olantern'}, '456'], # at 0.1.2 + ] + ] + ) + ; + + +#$t1->look_down('_tag' => 'body')->replace_content('all gone!'); +$t1->content_handler(corpus => 'all gone!'); +is( $t1->as_HTML, 'I like stuff!all gone! +', "replaced all of body"); + + diff --git a/t/data/3dig.dat b/t/data/3dig.dat new file mode 100644 index 0000000..439cfca --- /dev/null +++ b/t/data/3dig.dat @@ -0,0 +1,5 @@ +437,MS-DOS,United States,0,1,1,1,1 +708,Arabic (ASMO 708),0,1,0,0,1 +709,Arabic (ASMO 449+ BCON V4),0,1,0,0,1 +710,Arabic (Transparent Arabic),0,1,0,0,1 +720,Arabic (Transparent ASMO),0,1,0,0,1 \ No newline at end of file diff --git a/t/data/4dig.dat b/t/data/4dig.dat new file mode 100644 index 0000000..030affd --- /dev/null +++ b/t/data/4dig.dat @@ -0,0 +1,10 @@ +1200,Unicode (BMP of ISO 10646),0,0,1,1,2 +1250,Windows 3.1 Eastern European,1,0,1,1,1 +1251,Windows 3.1 Cyrillic,1,0,1,1,1 +1252,Windows 3.1 US (ANSI),1,0,1,1,1 +1253,Windows 3.1 Greek,1,0,1,1,1 +1254,Windows 3.1 Turkish,1,0,1,1,1 +1255,Hebrew,1,0,0,0,1 +1256,Arabic,1,0,0,0,1 +1257,Baltic,1,0,0,0,1 +1361,Korean (Johab),1,0,0,3,1 \ No newline at end of file diff --git a/t/data/table2.pm b/t/data/table2.pm new file mode 100644 index 0000000..7b5eaf5 --- /dev/null +++ b/t/data/table2.pm @@ -0,0 +1,37 @@ +package data::table2; + +use strict; +use warnings; + +use Cwd; +use Data::Dumper; + +#warn __PACKAGE__ . ' cwd - ' . getcwd() ; + +sub new { + my $this = shift; + bless {}, ref($this) || $this; +} + +sub load_data { + + my @file = qw(4dig 3dig); + + my %data; + + for my $file (@file) { + my $f = "t/data/$file.dat"; + my @data; + open F, $f or die "couldnt open $f: $!"; + while () { + push @data, [ split ',', $_ ] ; + } + $data{$file} = \@data; + } + #warn Dumper \%data; + \%data; + +} + +1; + diff --git a/t/dual_iter.t b/t/dual_iter.t new file mode 100644 index 0000000..dfe5b2f --- /dev/null +++ b/t/dual_iter.t @@ -0,0 +1,53 @@ +# This might look like shell script, but it's actually -*- perl -*- +use strict; +use lib qw(t/ t/m/); + +use File::Slurp; +use Test::More qw(no_plan); + +use TestUtils; +use HTML::TreeBuilder; +use HTML::Element::Library; + +# this is a simpler call to iter2() + +my $root = 't/html/dual_iter'; + +my $tree = HTML::TreeBuilder->new_from_file("$root.html"); + +my $dl = $tree->look_down(id => 'service_plan'); + + +my @items = ( + ['the pros' => 'never have to worry about service again'], + ['the cons' => 'upfront extra charge on purchase'], + ['our choice' => 'go with the extended service plan'] + ); + + +$tree->iter2( + + wrapper_data => \@items, + + wrapper_proc => sub { + my ($container) = @_; + + # only keep the last 2 dts and dds + my @content_list = $container->content_list; + $container->splice_content(0, @content_list - 2); + }, + + + splice => sub { + my ($container, @item_elems) = @_; + $container->unshift_content(@item_elems); + }, + + debug => 1, + + ); + + my $generated_html = ptree($tree, "$root.gen"); + + is ($generated_html, File::Slurp::read_file("$root.exp"), + "HTML for generated li"); diff --git a/t/highlander.t b/t/highlander.t new file mode 100644 index 0000000..061cc5f --- /dev/null +++ b/t/highlander.t @@ -0,0 +1,36 @@ +# This might look like shell script, but it's actually -*- perl -*- +use strict; +use lib qw(t/ t/m/); + +use File::Slurp; +use Test::More qw(no_plan); + +use TestUtils; +use HTML::TreeBuilder; +use HTML::Element::Library; + + +sub tage { + my $age = shift; + my $tree = HTML::TreeBuilder->new_from_file('t/html/highlander.html'); + + + $tree->highlander + (age_dialog => + [ + under10 => sub { $_[0] < 10} , + under18 => sub { $_[0] < 18} , + welcome => sub { 1 } + ], + $age + ); + + my $root = "t/html/highlander-$age"; + + my $generated_html = ptree($tree, "$root.gen"); + + is ($generated_html, File::Slurp::read_file("$root.exp"), "HTML for $age"); +} + + +tage($_) for qw(5 15 50); diff --git a/t/highlander2.t b/t/highlander2.t new file mode 100644 index 0000000..479553f --- /dev/null +++ b/t/highlander2.t @@ -0,0 +1,50 @@ +# This might look like shell script, but it's actually -*- perl -*- +use strict; +use lib qw(t/ t/m/); + +use File::Slurp; +use Test::More qw(no_plan); + +use TestUtils; +use HTML::TreeBuilder; +use HTML::Element::Library; + +sub replace_age { + my $branch = shift; + my $age = shift; + $branch->look_down(id => 'age')->replace_content($age); +} + + +sub tage { + my $age = shift; + my $tree = HTML::TreeBuilder->new_from_file('t/html/highlander2.html'); + my $if_then = $tree->look_down(id => 'age_dialog'); + + $if_then->highlander2( + cond => [ + under10 => [ + sub { $_[0] < 10} , + \&replace_age + ], + under18 => [ + sub { $_[0] < 18} , + \&replace_age + ], + welcome => [ + sub { 1 }, + \&replace_age + ] + ], + cond_arg => [ $age ] + ); + + my $root = "t/html/highlander2-$age"; + + my $generated_html = ptree($tree, "$root.gen"); + + is ($generated_html, File::Slurp::read_file("$root.exp"), "HTML for $age"); +} + + +tage($_) for qw(5 15 27); diff --git a/t/html/dual_iter.exp b/t/html/dual_iter.exp new file mode 100644 index 0000000..64c6c8f --- /dev/null +++ b/t/html/dual_iter.exp @@ -0,0 +1,15 @@ + + + +
    +
    the pros
    +
    never have to worry about service again
    +
    the cons
    +
    upfront extra charge on purchase
    +
    our choice
    +
    go with the extended service plan
    +
    sample header
    +
    sample data
    +
    + + diff --git a/t/html/dual_iter.gen b/t/html/dual_iter.gen new file mode 100644 index 0000000..64c6c8f --- /dev/null +++ b/t/html/dual_iter.gen @@ -0,0 +1,15 @@ + + + +
    +
    the pros
    +
    never have to worry about service again
    +
    the cons
    +
    upfront extra charge on purchase
    +
    our choice
    +
    go with the extended service plan
    +
    sample header
    +
    sample data
    +
    + + diff --git a/t/html/dual_iter.html b/t/html/dual_iter.html new file mode 100644 index 0000000..d5c1adf --- /dev/null +++ b/t/html/dual_iter.html @@ -0,0 +1,25 @@ +
    +
    + Artist +
    +
    + A person who draws blood. +
    + +
    + Musician +
    +
    + A clone of Iggy Pop. +
    + +
    + Poet +
    +
    + A relative of Edgar Allan Poe. +
    + +
    sample header
    +
    sample data
    +
    \ No newline at end of file diff --git a/t/html/highlander-15.exp b/t/html/highlander-15.exp new file mode 100644 index 0000000..48fe062 --- /dev/null +++ b/t/html/highlander-15.exp @@ -0,0 +1,6 @@ + + + Sorry, + you're not old enough to enter (and too dumb to lie about your age) + + diff --git a/t/html/highlander-15.gen b/t/html/highlander-15.gen new file mode 100644 index 0000000..48fe062 --- /dev/null +++ b/t/html/highlander-15.gen @@ -0,0 +1,6 @@ + + + Sorry, + you're not old enough to enter (and too dumb to lie about your age) + + diff --git a/t/html/highlander-5.exp b/t/html/highlander-5.exp new file mode 100644 index 0000000..96df6fc --- /dev/null +++ b/t/html/highlander-5.exp @@ -0,0 +1,6 @@ + + + Hello, + does your mother know you're using her AOL account? + + diff --git a/t/html/highlander-5.gen b/t/html/highlander-5.gen new file mode 100644 index 0000000..96df6fc --- /dev/null +++ b/t/html/highlander-5.gen @@ -0,0 +1,6 @@ + + + Hello, + does your mother know you're using her AOL account? + + diff --git a/t/html/highlander-50.exp b/t/html/highlander-50.exp new file mode 100644 index 0000000..1f03edd --- /dev/null +++ b/t/html/highlander-50.exp @@ -0,0 +1,5 @@ + + + Welcome + + diff --git a/t/html/highlander-50.gen b/t/html/highlander-50.gen new file mode 100644 index 0000000..1f03edd --- /dev/null +++ b/t/html/highlander-50.gen @@ -0,0 +1,5 @@ + + + Welcome + + diff --git a/t/html/highlander.html b/t/html/highlander.html new file mode 100644 index 0000000..70ece55 --- /dev/null +++ b/t/html/highlander.html @@ -0,0 +1,13 @@ + + + Hello, does your mother know you're + using her AOL account? + + + Sorry, you're not old enough to enter + (and too dumb to lie about your age) + + + Welcome + + diff --git a/t/html/highlander2-15.exp b/t/html/highlander2-15.exp new file mode 100644 index 0000000..20be935 --- /dev/null +++ b/t/html/highlander2-15.exp @@ -0,0 +1,6 @@ + + + Sorry, + you're only 15 (and too dumb to lie about your + age) + diff --git a/t/html/highlander2-15.gen b/t/html/highlander2-15.gen new file mode 100644 index 0000000..20be935 --- /dev/null +++ b/t/html/highlander2-15.gen @@ -0,0 +1,6 @@ + + + Sorry, + you're only 15 (and too dumb to lie about your + age) + diff --git a/t/html/highlander2-27.exp b/t/html/highlander2-27.exp new file mode 100644 index 0000000..dd7b2fa --- /dev/null +++ b/t/html/highlander2-27.exp @@ -0,0 +1,6 @@ + + + Welcome, + isn't it good to be 27 years old? + + diff --git a/t/html/highlander2-27.gen b/t/html/highlander2-27.gen new file mode 100644 index 0000000..dd7b2fa --- /dev/null +++ b/t/html/highlander2-27.gen @@ -0,0 +1,6 @@ + + + Welcome, + isn't it good to be 27 years old? + + diff --git a/t/html/highlander2-5.exp b/t/html/highlander2-5.exp new file mode 100644 index 0000000..b62e6e0 --- /dev/null +++ b/t/html/highlander2-5.exp @@ -0,0 +1,6 @@ + + + Hello, + little 5-year old, does your mother know you're + using her AOL account? + diff --git a/t/html/highlander2-5.gen b/t/html/highlander2-5.gen new file mode 100644 index 0000000..b62e6e0 --- /dev/null +++ b/t/html/highlander2-5.gen @@ -0,0 +1,6 @@ + + + Hello, + little 5-year old, does your mother know you're + using her AOL account? + diff --git a/t/html/highlander2.html b/t/html/highlander2.html new file mode 100644 index 0000000..2009d79 --- /dev/null +++ b/t/html/highlander2.html @@ -0,0 +1,15 @@ + + + Hello, little + AGE-year old, + does your mother know you're + using her AOL account? + + + Sorry, you're only AGE + (and too dumb to lie about your age) + + + Welcome, isn't it good to be AGE years old? + + diff --git a/t/html/iter.exp b/t/html/iter.exp new file mode 100644 index 0000000..746633e --- /dev/null +++ b/t/html/iter.exp @@ -0,0 +1,10 @@ + + + Here are the things I need from the store: +
      +
    • bread
    • +
    • butter
    • +
    • vodka
    • +
    + + diff --git a/t/html/iter.gen b/t/html/iter.gen new file mode 100644 index 0000000..746633e --- /dev/null +++ b/t/html/iter.gen @@ -0,0 +1,10 @@ + + + Here are the things I need from the store: +
      +
    • bread
    • +
    • butter
    • +
    • vodka
    • +
    + + diff --git a/t/html/iter.html b/t/html/iter.html new file mode 100644 index 0000000..289809f --- /dev/null +++ b/t/html/iter.html @@ -0,0 +1,4 @@ +Here are the things I need from the store: +
      +
    • Sample item
    • +
    \ No newline at end of file diff --git a/t/html/iter2.exp b/t/html/iter2.exp new file mode 100644 index 0000000..17148cf --- /dev/null +++ b/t/html/iter2.exp @@ -0,0 +1,15 @@ + + + Here are the type of people you meet at XYZ, inc: +
    +
    Programmer
    +
    one who likes Perl and Seamstress
    +
    DBA
    +
    one who does business as
    +
    Admin
    +
    one who plays Tetris all day
    +
    Poet
    +
    A relative of Edgar Allan Poe.
    +
    + + diff --git a/t/html/iter2.gen b/t/html/iter2.gen new file mode 100644 index 0000000..17148cf --- /dev/null +++ b/t/html/iter2.gen @@ -0,0 +1,15 @@ + + + Here are the type of people you meet at XYZ, inc: +
    +
    Programmer
    +
    one who likes Perl and Seamstress
    +
    DBA
    +
    one who does business as
    +
    Admin
    +
    one who plays Tetris all day
    +
    Poet
    +
    A relative of Edgar Allan Poe.
    +
    + + diff --git a/t/html/iter2.html b/t/html/iter2.html new file mode 100644 index 0000000..1a93671 --- /dev/null +++ b/t/html/iter2.html @@ -0,0 +1,27 @@ +Here are the type of people you meet at XYZ, inc: + +
    + +
    + Artist +
    +
    + A person who draws blood. +
    + +
    + Musician +
    +
    + A clone of Iggy Pop. +
    + +
    + Poet +
    +
    + A relative of Edgar Allan Poe. +
    + + +
    diff --git a/t/html/table-alt.exp b/t/html/table-alt.exp new file mode 100644 index 0000000..60c9f06 --- /dev/null +++ b/t/html/table-alt.exp @@ -0,0 +1,42 @@ + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    nameage weight
    bob9999
    bill1252
    brian4480
    babette52124
    bobo12120
    bix43230
    + + diff --git a/t/html/table-alt.gen b/t/html/table-alt.gen new file mode 100644 index 0000000..60c9f06 --- /dev/null +++ b/t/html/table-alt.gen @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    nameage weight
    bob9999
    bill1252
    brian4480
    babette52124
    bobo12120
    bix43230
    + + diff --git a/t/html/table-alt.html b/t/html/table-alt.html new file mode 100644 index 0000000..463bb2f --- /dev/null +++ b/t/html/table-alt.html @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + +
    nameage weight
    NATURE BOY RIC FLAIR 35 220
    NATURE BOY RIC FLAIR 35 220
    diff --git a/t/html/table.exp b/t/html/table.exp new file mode 100644 index 0000000..c11b8f4 --- /dev/null +++ b/t/html/table.exp @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    nameage weight
    bob9999
    bill1252
    brian4480
    babette52124
    bobo12120
    bix43230
    + + diff --git a/t/html/table.gen b/t/html/table.gen new file mode 100644 index 0000000..c11b8f4 --- /dev/null +++ b/t/html/table.gen @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    nameage weight
    bob9999
    bill1252
    brian4480
    babette52124
    bobo12120
    bix43230
    + + diff --git a/t/html/table.html b/t/html/table.html new file mode 100644 index 0000000..0125784 --- /dev/null +++ b/t/html/table.html @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + +
    nameage weight
    diff --git a/t/html/table2-table_ld-arrayref.exp b/t/html/table2-table_ld-arrayref.exp new file mode 100644 index 0000000..ed2919a --- /dev/null +++ b/t/html/table2-table_ld-arrayref.exp @@ -0,0 +1,160 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
    Code-Page
    ID
    Name ACP OEMCP Windows
    NT 3.1
    Windows
    NT 3.51
    Windows
    95
    1200Unicode (BMP of ISO/IEC-10646)XX*
    1250Windows 3.1 Eastern EuropeanXXXX
    1251Windows 3.1 CyrillicXXXX
    1252Windows 3.1 US (ANSI)XXXX
    1253Windows 3.1 GreekXXXX
    1254Windows 3.1 TurkishXXXX
    1255HebrewXX
    1256ArabicXX
    1257BalticXX
    1361Korean (Johab)X**X
    437MS-DOS United StatesXXXX
    708Arabic (ASMO 708)XX
    709Arabic (ASMO 449+, BCON V4)XX
    710Arabic (Transparent Arabic)XX
    720Arabic (Transparent ASMO)XX
    diff --git a/t/html/table2-table_ld-arrayref.gen b/t/html/table2-table_ld-arrayref.gen new file mode 100644 index 0000000..ed2919a --- /dev/null +++ b/t/html/table2-table_ld-arrayref.gen @@ -0,0 +1,160 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
    Code-Page
    ID
    Name ACP OEMCP Windows
    NT 3.1
    Windows
    NT 3.51
    Windows
    95
    1200Unicode (BMP of ISO/IEC-10646)XX*
    1250Windows 3.1 Eastern EuropeanXXXX
    1251Windows 3.1 CyrillicXXXX
    1252Windows 3.1 US (ANSI)XXXX
    1253Windows 3.1 GreekXXXX
    1254Windows 3.1 TurkishXXXX
    1255HebrewXX
    1256ArabicXX
    1257BalticXX
    1361Korean (Johab)X**X
    437MS-DOS United StatesXXXX
    708Arabic (ASMO 708)XX
    709Arabic (ASMO 449+, BCON V4)XX
    710Arabic (Transparent Arabic)XX
    720Arabic (Transparent ASMO)XX
    diff --git a/t/html/table2-table_ld-arrayref.html b/t/html/table2-table_ld-arrayref.html new file mode 100644 index 0000000..544553b --- /dev/null +++ b/t/html/table2-table_ld-arrayref.html @@ -0,0 +1,80 @@ + + + + Complex HTML Table + + + +

    Complex HTML Table

    + +

    + This table comes from + + the w3 spec on tables + . I am using it to try out the table2() API call + that is part of the new release of + + HTML::Element::Library + . +

    + + +

    + + + + + + + + + + + + + + + + + + + + +
    CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
    Code-Page
    ID +
    Name + ACP + OEMCP + Windows
    NT 3.1 +
    Windows
    NT 3.51 +
    Windows
    95 +
    1200Unicode (BMP of ISO/IEC-10646)XX* +
    1250Windows 3.1 Eastern EuropeanXXXX +
    1251Windows 3.1 CyrillicXXXX +
    1252Windows 3.1 US (ANSI)XXXX +
    1253Windows 3.1 GreekXXXX +
    1254Windows 3.1 TurkishXXXX +
    1255HebrewXX +
    1256ArabicXX +
    1257BalticXX +
    1361Korean (Johab)X**X +
    437MS-DOS United StatesXXXX +
    708Arabic (ASMO 708)XX +
    709Arabic (ASMO 449+, BCON V4)XX +
    710Arabic (Transparent Arabic)XX +
    720Arabic (Transparent ASMO)XX
    + + + + +


    +
    metaperl
    + + +Last modified: Fri Nov 25 08:57:41 PST 2005 + + + diff --git a/t/html/table2-table_ld-coderef.exp b/t/html/table2-table_ld-coderef.exp new file mode 100644 index 0000000..ed2919a --- /dev/null +++ b/t/html/table2-table_ld-coderef.exp @@ -0,0 +1,160 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
    Code-Page
    ID
    Name ACP OEMCP Windows
    NT 3.1
    Windows
    NT 3.51
    Windows
    95
    1200Unicode (BMP of ISO/IEC-10646)XX*
    1250Windows 3.1 Eastern EuropeanXXXX
    1251Windows 3.1 CyrillicXXXX
    1252Windows 3.1 US (ANSI)XXXX
    1253Windows 3.1 GreekXXXX
    1254Windows 3.1 TurkishXXXX
    1255HebrewXX
    1256ArabicXX
    1257BalticXX
    1361Korean (Johab)X**X
    437MS-DOS United StatesXXXX
    708Arabic (ASMO 708)XX
    709Arabic (ASMO 449+, BCON V4)XX
    710Arabic (Transparent Arabic)XX
    720Arabic (Transparent ASMO)XX
    diff --git a/t/html/table2-table_ld-coderef.gen b/t/html/table2-table_ld-coderef.gen new file mode 100644 index 0000000..ed2919a --- /dev/null +++ b/t/html/table2-table_ld-coderef.gen @@ -0,0 +1,160 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
    Code-Page
    ID
    Name ACP OEMCP Windows
    NT 3.1
    Windows
    NT 3.51
    Windows
    95
    1200Unicode (BMP of ISO/IEC-10646)XX*
    1250Windows 3.1 Eastern EuropeanXXXX
    1251Windows 3.1 CyrillicXXXX
    1252Windows 3.1 US (ANSI)XXXX
    1253Windows 3.1 GreekXXXX
    1254Windows 3.1 TurkishXXXX
    1255HebrewXX
    1256ArabicXX
    1257BalticXX
    1361Korean (Johab)X**X
    437MS-DOS United StatesXXXX
    708Arabic (ASMO 708)XX
    709Arabic (ASMO 449+, BCON V4)XX
    710Arabic (Transparent Arabic)XX
    720Arabic (Transparent ASMO)XX
    diff --git a/t/html/table2-table_ld-coderef.html b/t/html/table2-table_ld-coderef.html new file mode 100644 index 0000000..544553b --- /dev/null +++ b/t/html/table2-table_ld-coderef.html @@ -0,0 +1,80 @@ + + + + Complex HTML Table + + + +

    Complex HTML Table

    + +

    + This table comes from + + the w3 spec on tables + . I am using it to try out the table2() API call + that is part of the new release of + + HTML::Element::Library + . +

    + + +

    + + + + + + + + + + + + + + + + + + + + +
    CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
    Code-Page
    ID +
    Name + ACP + OEMCP + Windows
    NT 3.1 +
    Windows
    NT 3.51 +
    Windows
    95 +
    1200Unicode (BMP of ISO/IEC-10646)XX* +
    1250Windows 3.1 Eastern EuropeanXXXX +
    1251Windows 3.1 CyrillicXXXX +
    1252Windows 3.1 US (ANSI)XXXX +
    1253Windows 3.1 GreekXXXX +
    1254Windows 3.1 TurkishXXXX +
    1255HebrewXX +
    1256ArabicXX +
    1257BalticXX +
    1361Korean (Johab)X**X +
    437MS-DOS United StatesXXXX +
    708Arabic (ASMO 708)XX +
    709Arabic (ASMO 449+, BCON V4)XX +
    710Arabic (Transparent Arabic)XX +
    720Arabic (Transparent ASMO)XX
    + + + + +


    +
    metaperl
    + + +Last modified: Fri Nov 25 08:57:41 PST 2005 + + + diff --git a/t/html/table2-table_ld-default.exp b/t/html/table2-table_ld-default.exp new file mode 100644 index 0000000..ed2919a --- /dev/null +++ b/t/html/table2-table_ld-default.exp @@ -0,0 +1,160 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
    Code-Page
    ID
    Name ACP OEMCP Windows
    NT 3.1
    Windows
    NT 3.51
    Windows
    95
    1200Unicode (BMP of ISO/IEC-10646)XX*
    1250Windows 3.1 Eastern EuropeanXXXX
    1251Windows 3.1 CyrillicXXXX
    1252Windows 3.1 US (ANSI)XXXX
    1253Windows 3.1 GreekXXXX
    1254Windows 3.1 TurkishXXXX
    1255HebrewXX
    1256ArabicXX
    1257BalticXX
    1361Korean (Johab)X**X
    437MS-DOS United StatesXXXX
    708Arabic (ASMO 708)XX
    709Arabic (ASMO 449+, BCON V4)XX
    710Arabic (Transparent Arabic)XX
    720Arabic (Transparent ASMO)XX
    diff --git a/t/html/table2-table_ld-default.gen b/t/html/table2-table_ld-default.gen new file mode 100644 index 0000000..ed2919a --- /dev/null +++ b/t/html/table2-table_ld-default.gen @@ -0,0 +1,160 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
    Code-Page
    ID
    Name ACP OEMCP Windows
    NT 3.1
    Windows
    NT 3.51
    Windows
    95
    1200Unicode (BMP of ISO/IEC-10646)XX*
    1250Windows 3.1 Eastern EuropeanXXXX
    1251Windows 3.1 CyrillicXXXX
    1252Windows 3.1 US (ANSI)XXXX
    1253Windows 3.1 GreekXXXX
    1254Windows 3.1 TurkishXXXX
    1255HebrewXX
    1256ArabicXX
    1257BalticXX
    1361Korean (Johab)X**X
    437MS-DOS United StatesXXXX
    708Arabic (ASMO 708)XX
    709Arabic (ASMO 449+, BCON V4)XX
    710Arabic (Transparent Arabic)XX
    720Arabic (Transparent ASMO)XX
    diff --git a/t/html/table2-table_ld-default.html b/t/html/table2-table_ld-default.html new file mode 100644 index 0000000..544553b --- /dev/null +++ b/t/html/table2-table_ld-default.html @@ -0,0 +1,80 @@ + + + + Complex HTML Table + + + +

    Complex HTML Table

    + +

    + This table comes from + + the w3 spec on tables + . I am using it to try out the table2() API call + that is part of the new release of + + HTML::Element::Library + . +

    + + +

    + + + + + + + + + + + + + + + + + + + + +
    CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
    Code-Page
    ID +
    Name + ACP + OEMCP + Windows
    NT 3.1 +
    Windows
    NT 3.51 +
    Windows
    95 +
    1200Unicode (BMP of ISO/IEC-10646)XX* +
    1250Windows 3.1 Eastern EuropeanXXXX +
    1251Windows 3.1 CyrillicXXXX +
    1252Windows 3.1 US (ANSI)XXXX +
    1253Windows 3.1 GreekXXXX +
    1254Windows 3.1 TurkishXXXX +
    1255HebrewXX +
    1256ArabicXX +
    1257BalticXX +
    1361Korean (Johab)X**X +
    437MS-DOS United StatesXXXX +
    708Arabic (ASMO 708)XX +
    709Arabic (ASMO 449+, BCON V4)XX +
    710Arabic (Transparent Arabic)XX +
    720Arabic (Transparent ASMO)XX
    + + + + +


    +
    metaperl
    + + +Last modified: Fri Nov 25 08:57:41 PST 2005 + + + diff --git a/t/html/table2-tr_ld-arrayref.exp b/t/html/table2-tr_ld-arrayref.exp new file mode 100644 index 0000000..0b96ad5 --- /dev/null +++ b/t/html/table2-tr_ld-arrayref.exp @@ -0,0 +1,9 @@ +
    437MS-DOS United StatesXXXX
    437MS-DOS United StatesXXXX
    + + + + + + + + + + + + + + + + + + +
    CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
    Code-Page
    ID +
    Name + ACP + OEMCP + Windows
    NT 3.1 +
    Windows
    NT 3.51 +
    Windows
    95 +
    1200Unicode (BMP of ISO/IEC-10646)XX* +
    1250Windows 3.1 Eastern EuropeanXXXX +
    1251Windows 3.1 CyrillicXXXX +
    1252Windows 3.1 US (ANSI)XXXX +
    1253Windows 3.1 GreekXXXX +
    1254Windows 3.1 TurkishXXXX +
    1255HebrewXX +
    1256ArabicXX +
    1257BalticXX +
    1361Korean (Johab)X**X +
    437MS-DOS United StatesXXXX +
    708Arabic (ASMO 708)XX +
    709Arabic (ASMO 449+, BCON V4)XX +
    710Arabic (Transparent Arabic)XX +
    720Arabic (Transparent ASMO)XX
    + + + + +
    +
    metaperl
    + + +Last modified: Fri Nov 25 19:38:43 PST 2005 + + + diff --git a/t/html/table2-tr_ld-coderef.exp b/t/html/table2-tr_ld-coderef.exp new file mode 100644 index 0000000..6df0c73 --- /dev/null +++ b/t/html/table2-tr_ld-coderef.exp @@ -0,0 +1,134 @@ + + + Complex HTML Table + + +

    Complex HTML Table

    +

    This table comes from the + w3 spec on tables . I am using it to try out the + table2() API call that is part of the new release of + HTML::Element::Library .

    +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
    Code-Page
    ID
    Name ACP OEMCP Windows
    NT 3.1
    Windows
    NT 3.51
    Windows
    95
    1200Unicode (BMP of ISO/IEC-10646)XX*
    1255HebrewXX
    1256ArabicXX
    1257BalticXX
    1361Korean (Johab)X**X
    437MS-DOS United StatesXXXX
    708Arabic (ASMO 708)XX
    709Arabic (ASMO 449+, BCON V4)XX
    710Arabic (Transparent Arabic)XX
    720Arabic (Transparent ASMO)XX
    +


    +
    metaperl
    + Last modified: Fri Nov 25 08:57:41 PST 2005

    + + diff --git a/t/html/table2-tr_ld-coderef.gen b/t/html/table2-tr_ld-coderef.gen new file mode 100644 index 0000000..6df0c73 --- /dev/null +++ b/t/html/table2-tr_ld-coderef.gen @@ -0,0 +1,134 @@ + + + Complex HTML Table + + +

    Complex HTML Table

    +

    This table comes from the + w3 spec on tables . I am using it to try out the + table2() API call that is part of the new release of + HTML::Element::Library .

    +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
    Code-Page
    ID
    Name ACP OEMCP Windows
    NT 3.1
    Windows
    NT 3.51
    Windows
    95
    1200Unicode (BMP of ISO/IEC-10646)XX*
    1255HebrewXX
    1256ArabicXX
    1257BalticXX
    1361Korean (Johab)X**X
    437MS-DOS United StatesXXXX
    708Arabic (ASMO 708)XX
    709Arabic (ASMO 449+, BCON V4)XX
    710Arabic (Transparent Arabic)XX
    720Arabic (Transparent ASMO)XX
    +


    +
    metaperl
    + Last modified: Fri Nov 25 08:57:41 PST 2005

    + + diff --git a/t/html/table2-tr_ld-coderef.html b/t/html/table2-tr_ld-coderef.html new file mode 100644 index 0000000..544553b --- /dev/null +++ b/t/html/table2-tr_ld-coderef.html @@ -0,0 +1,80 @@ + + + + Complex HTML Table + + + +

    Complex HTML Table

    + +

    + This table comes from + + the w3 spec on tables + . I am using it to try out the table2() API call + that is part of the new release of + + HTML::Element::Library + . +

    + + +

    + + + + + + + + + + + + + + + + + + + + +
    CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
    Code-Page
    ID +
    Name + ACP + OEMCP + Windows
    NT 3.1 +
    Windows
    NT 3.51 +
    Windows
    95 +
    1200Unicode (BMP of ISO/IEC-10646)XX* +
    1250Windows 3.1 Eastern EuropeanXXXX +
    1251Windows 3.1 CyrillicXXXX +
    1252Windows 3.1 US (ANSI)XXXX +
    1253Windows 3.1 GreekXXXX +
    1254Windows 3.1 TurkishXXXX +
    1255HebrewXX +
    1256ArabicXX +
    1257BalticXX +
    1361Korean (Johab)X**X +
    437MS-DOS United StatesXXXX +
    708Arabic (ASMO 708)XX +
    709Arabic (ASMO 449+, BCON V4)XX +
    710Arabic (Transparent Arabic)XX +
    720Arabic (Transparent ASMO)XX
    + + + + +


    +
    metaperl
    + + +Last modified: Fri Nov 25 08:57:41 PST 2005 + + + diff --git a/t/html/table2-tr_ld-default.gen b/t/html/table2-tr_ld-default.gen new file mode 100644 index 0000000..ed2919a --- /dev/null +++ b/t/html/table2-tr_ld-default.gen @@ -0,0 +1,160 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
    Code-Page
    ID
    Name ACP OEMCP Windows
    NT 3.1
    Windows
    NT 3.51
    Windows
    95
    1200Unicode (BMP of ISO/IEC-10646)XX*
    1250Windows 3.1 Eastern EuropeanXXXX
    1251Windows 3.1 CyrillicXXXX
    1252Windows 3.1 US (ANSI)XXXX
    1253Windows 3.1 GreekXXXX
    1254Windows 3.1 TurkishXXXX
    1255HebrewXX
    1256ArabicXX
    1257BalticXX
    1361Korean (Johab)X**X
    437MS-DOS United StatesXXXX
    708Arabic (ASMO 708)XX
    709Arabic (ASMO 449+, BCON V4)XX
    710Arabic (Transparent Arabic)XX
    720Arabic (Transparent ASMO)XX
    diff --git a/t/html/table2-tr_ld-default.html b/t/html/table2-tr_ld-default.html new file mode 100644 index 0000000..544553b --- /dev/null +++ b/t/html/table2-tr_ld-default.html @@ -0,0 +1,80 @@ + + + + Complex HTML Table + + + +

    Complex HTML Table

    + +

    + This table comes from + + the w3 spec on tables + . I am using it to try out the table2() API call + that is part of the new release of + + HTML::Element::Library + . +

    + + +

    + + + + + + + + + + + + + + + + + + + + +
    CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
    Code-Page
    ID +
    Name + ACP + OEMCP + Windows
    NT 3.1 +
    Windows
    NT 3.51 +
    Windows
    95 +
    1200Unicode (BMP of ISO/IEC-10646)XX* +
    1250Windows 3.1 Eastern EuropeanXXXX +
    1251Windows 3.1 CyrillicXXXX +
    1252Windows 3.1 US (ANSI)XXXX +
    1253Windows 3.1 GreekXXXX +
    1254Windows 3.1 TurkishXXXX +
    1255HebrewXX +
    1256ArabicXX +
    1257BalticXX +
    1361Korean (Johab)X**X +
    437MS-DOS United StatesXXXX +
    708Arabic (ASMO 708)XX +
    709Arabic (ASMO 449+, BCON V4)XX +
    710Arabic (Transparent Arabic)XX +
    720Arabic (Transparent ASMO)XX
    + + + + +


    +
    metaperl
    + + +Last modified: Fri Nov 25 08:57:41 PST 2005 + + + diff --git a/t/html/table2-tr_ld_coderef.exp b/t/html/table2-tr_ld_coderef.exp new file mode 100644 index 0000000..6df0c73 --- /dev/null +++ b/t/html/table2-tr_ld_coderef.exp @@ -0,0 +1,134 @@ + + + Complex HTML Table + + +

    Complex HTML Table

    +

    This table comes from the + w3 spec on tables . I am using it to try out the + table2() API call that is part of the new release of + HTML::Element::Library .

    +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
    Code-Page
    ID
    Name ACP OEMCP Windows
    NT 3.1
    Windows
    NT 3.51
    Windows
    95
    1200Unicode (BMP of ISO/IEC-10646)XX*
    1255HebrewXX
    1256ArabicXX
    1257BalticXX
    1361Korean (Johab)X**X
    437MS-DOS United StatesXXXX
    708Arabic (ASMO 708)XX
    709Arabic (ASMO 449+, BCON V4)XX
    710Arabic (Transparent Arabic)XX
    720Arabic (Transparent ASMO)XX
    +


    +
    metaperl
    + Last modified: Fri Nov 25 08:57:41 PST 2005

    + + diff --git a/t/html/table2.exp b/t/html/table2.exp new file mode 100644 index 0000000..5ec9675 --- /dev/null +++ b/t/html/table2.exp @@ -0,0 +1,179 @@ + + + Complex HTML Table + + +

    Complex HTML Table

    +

    This table comes from the + w3 spec on tables . I am using it to try out the + table2() API call that is part of the new release of + HTML::Element::Library .

    +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
    Code-Page
    ID
    Name ACP OEMCP Windows
    NT 3.1
    Windows
    NT 3.51
    Windows
    95
    1200Unicode (BMP of ISO 10646)00112
    1250Windows 3.1 Eastern European10111
    1251Windows 3.1 Cyrillic10111
    1252Windows 3.1 US (ANSI)10111
    1253Windows 3.1 Greek10111
    1254Windows 3.1 Turkish10111
    1255Hebrew10001
    1256Arabic10001
    1257Baltic10001
    1361Korean (Johab)10031
    437MS-DOSUnited States0111
    708Arabic (ASMO 708)01001
    709Arabic (ASMO 449+ BCON V4)01001
    710Arabic (Transparent Arabic)01001
    720Arabic (Transparent ASMO)01001
    +


    +
    metaperl
    + Last modified: Fri Nov 25 08:57:41 PST 2005

    + + diff --git a/t/html/table2.gen b/t/html/table2.gen new file mode 100644 index 0000000..5ec9675 --- /dev/null +++ b/t/html/table2.gen @@ -0,0 +1,179 @@ + + + Complex HTML Table + + +

    Complex HTML Table

    +

    This table comes from the + w3 spec on tables . I am using it to try out the + table2() API call that is part of the new release of + HTML::Element::Library .

    +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
    Code-Page
    ID
    Name ACP OEMCP Windows
    NT 3.1
    Windows
    NT 3.51
    Windows
    95
    1200Unicode (BMP of ISO 10646)00112
    1250Windows 3.1 Eastern European10111
    1251Windows 3.1 Cyrillic10111
    1252Windows 3.1 US (ANSI)10111
    1253Windows 3.1 Greek10111
    1254Windows 3.1 Turkish10111
    1255Hebrew10001
    1256Arabic10001
    1257Baltic10001
    1361Korean (Johab)10031
    437MS-DOSUnited States0111
    708Arabic (ASMO 708)01001
    709Arabic (ASMO 449+ BCON V4)01001
    710Arabic (Transparent Arabic)01001
    720Arabic (Transparent ASMO)01001
    +


    +
    metaperl
    + Last modified: Fri Nov 25 08:57:41 PST 2005

    + + diff --git a/t/html/table2.html b/t/html/table2.html new file mode 100644 index 0000000..544553b --- /dev/null +++ b/t/html/table2.html @@ -0,0 +1,80 @@ + + + + Complex HTML Table + + + +

    Complex HTML Table

    + +

    + This table comes from + + the w3 spec on tables + . I am using it to try out the table2() API call + that is part of the new release of + + HTML::Element::Library + . +

    + + +

    + + + + + + + + + + + + + + + + + + + + +
    CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
    Code-Page
    ID +
    Name + ACP + OEMCP + Windows
    NT 3.1 +
    Windows
    NT 3.51 +
    Windows
    95 +
    1200Unicode (BMP of ISO/IEC-10646)XX* +
    1250Windows 3.1 Eastern EuropeanXXXX +
    1251Windows 3.1 CyrillicXXXX +
    1252Windows 3.1 US (ANSI)XXXX +
    1253Windows 3.1 GreekXXXX +
    1254Windows 3.1 TurkishXXXX +
    1255HebrewXX +
    1256ArabicXX +
    1257BalticXX +
    1361Korean (Johab)X**X +
    437MS-DOS United StatesXXXX +
    708Arabic (ASMO 708)XX +
    709Arabic (ASMO 449+, BCON V4)XX +
    710Arabic (Transparent Arabic)XX +
    720Arabic (Transparent ASMO)XX
    + + + + +


    +
    metaperl
    + + +Last modified: Fri Nov 25 08:57:41 PST 2005 + + + diff --git a/t/html/table2_code.html b/t/html/table2_code.html new file mode 100644 index 0000000..56e4d04 --- /dev/null +++ b/t/html/table2_code.html @@ -0,0 +1,68 @@ + + + + Complex HTML Table + + + +

    Complex HTML Table

    + +

    + This table comes from + + the w3 spec on tables + . I am using it to try out the table2() API call + that is part of the new release of + + HTML::Element::Library + . +

    + + +

    + + + + + + + + + + + + + + + + + + + + +
    CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
    Code-Page
    ID +
    Name + ACP + OEMCP + Windows
    NT 3.1 +
    Windows
    NT 3.51 +
    Windows
    95 +
    1200Sample Row of 4dig dataXX* +
    437Sample Row of 3dig dataXXXX +
    + + + + +


    +
    metaperl
    + + +Last modified: Fri Nov 25 17:35:17 PST 2005 + + + diff --git a/t/html/table2_id.exp b/t/html/table2_id.exp new file mode 100644 index 0000000..544553b --- /dev/null +++ b/t/html/table2_id.exp @@ -0,0 +1,80 @@ + + + + Complex HTML Table + + + +

    Complex HTML Table

    + +

    + This table comes from + + the w3 spec on tables + . I am using it to try out the table2() API call + that is part of the new release of + + HTML::Element::Library + . +

    + + +

    + + + + + + + + + + + + + + + + + + + + +
    CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
    Code-Page
    ID +
    Name + ACP + OEMCP + Windows
    NT 3.1 +
    Windows
    NT 3.51 +
    Windows
    95 +
    1200Unicode (BMP of ISO/IEC-10646)XX* +
    1250Windows 3.1 Eastern EuropeanXXXX +
    1251Windows 3.1 CyrillicXXXX +
    1252Windows 3.1 US (ANSI)XXXX +
    1253Windows 3.1 GreekXXXX +
    1254Windows 3.1 TurkishXXXX +
    1255HebrewXX +
    1256ArabicXX +
    1257BalticXX +
    1361Korean (Johab)X**X +
    437MS-DOS United StatesXXXX +
    708Arabic (ASMO 708)XX +
    709Arabic (ASMO 449+, BCON V4)XX +
    710Arabic (Transparent Arabic)XX +
    720Arabic (Transparent ASMO)XX
    + + + + +


    +
    metaperl
    + + +Last modified: Fri Nov 25 08:57:41 PST 2005 + + + diff --git a/t/html/table2_id.html b/t/html/table2_id.html new file mode 100644 index 0000000..be0a347 --- /dev/null +++ b/t/html/table2_id.html @@ -0,0 +1,68 @@ + + + + Complex HTML Table + + + +

    Complex HTML Table

    + +

    + This table comes from + + the w3 spec on tables + . I am using it to try out the table2() API call + that is part of the new release of + + HTML::Element::Library + . +

    + + +

    + + + + + + + + + + + + + + + + + + + + +
    CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
    Code-Page
    ID +
    Name + ACP + OEMCP + Windows
    NT 3.1 +
    Windows
    NT 3.51 +
    Windows
    95 +
    1200Sample Row of 4dig dataXX* +
    437Sample Row of 3dig dataXXXX +
    + + + + +


    +
    metaperl
    + + +Last modified: Fri Nov 25 17:33:43 PST 2005 + + + diff --git a/t/html/table2_tr_proc.html b/t/html/table2_tr_proc.html new file mode 100644 index 0000000..544553b --- /dev/null +++ b/t/html/table2_tr_proc.html @@ -0,0 +1,80 @@ + + + + Complex HTML Table + + + +

    Complex HTML Table

    + +

    + This table comes from + + the w3 spec on tables + . I am using it to try out the table2() API call + that is part of the new release of + + HTML::Element::Library + . +

    + + +

    + + + + + + + + + + + + + + + + + + + + +
    CODE-PAGE SUPPORT IN MICROSOFT WINDOWS
    Code-Page
    ID +
    Name + ACP + OEMCP + Windows
    NT 3.1 +
    Windows
    NT 3.51 +
    Windows
    95 +
    1200Unicode (BMP of ISO/IEC-10646)XX* +
    1250Windows 3.1 Eastern EuropeanXXXX +
    1251Windows 3.1 CyrillicXXXX +
    1252Windows 3.1 US (ANSI)XXXX +
    1253Windows 3.1 GreekXXXX +
    1254Windows 3.1 TurkishXXXX +
    1255HebrewXX +
    1256ArabicXX +
    1257BalticXX +
    1361Korean (Johab)X**X +
    437MS-DOS United StatesXXXX +
    708Arabic (ASMO 708)XX +
    709Arabic (ASMO 449+, BCON V4)XX +
    710Arabic (Transparent Arabic)XX +
    720Arabic (Transparent ASMO)XX
    + + + + +


    +
    metaperl
    + + +Last modified: Fri Nov 25 08:57:41 PST 2005 + + + diff --git a/t/html/unroll_select.exp b/t/html/unroll_select.exp new file mode 100644 index 0000000..f44f26a --- /dev/null +++ b/t/html/unroll_select.exp @@ -0,0 +1,54 @@ + + + ctf gimble challenge ladder - signup + + +

    signup

    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Screen Name + +
    Login Name (use this to login next time) + +
    Clan Name + +
    Password (Don't choose one you use elsewhere.) + +
    Password (Again) + +
    Email + +
    + +
    + + diff --git a/t/html/unroll_select.gen b/t/html/unroll_select.gen new file mode 100644 index 0000000..f44f26a --- /dev/null +++ b/t/html/unroll_select.gen @@ -0,0 +1,54 @@ + + + ctf gimble challenge ladder - signup + + +

    signup

    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Screen Name + +
    Login Name (use this to login next time) + +
    Clan Name + +
    Password (Don't choose one you use elsewhere.) + +
    Password (Again) + +
    Email + +
    + +
    + + diff --git a/t/html/unroll_select.html b/t/html/unroll_select.html new file mode 100644 index 0000000..e9ac45c --- /dev/null +++ b/t/html/unroll_select.html @@ -0,0 +1,56 @@ + + +ctf gimble challenge ladder - signup + + + +

    signup

    + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Screen Name
    Login Name (use this to login next time)
    Clan Name + +
    Password (Don't choose one you use elsewhere.)
    Password (Again)
    Email
    + + + +
    + + \ No newline at end of file diff --git a/t/iter.t b/t/iter.t new file mode 100644 index 0000000..fe064e0 --- /dev/null +++ b/t/iter.t @@ -0,0 +1,26 @@ +# This might look like shell script, but it's actually -*- perl -*- +use strict; +use lib qw(t/ t/m/); + + +use File::Slurp; +use Test::More qw(no_plan); + +use TestUtils; +use HTML::TreeBuilder; +use HTML::Element::Library; + +my $root = 't/html/iter'; + +my $tree = HTML::TreeBuilder->new_from_file("$root.html"); + +my $li = $tree->look_down(class => 'store_items'); + +my @items = qw(bread butter vodka); + +$tree->iter($li, @items); + + my $generated_html = ptree($tree, "$root.gen"); + + is ($generated_html, File::Slurp::read_file("$root.exp"), + "HTML for generated li"); diff --git a/t/iter2.t b/t/iter2.t new file mode 100644 index 0000000..1a79501 --- /dev/null +++ b/t/iter2.t @@ -0,0 +1,48 @@ +# This might look like shell script, but it's actually -*- perl -*- +use strict; +use lib qw(t/ t/m/); + + +use File::Slurp; +use Test::More qw(no_plan); + +use TestUtils; +use HTML::TreeBuilder; +use HTML::Element::Library; + +my $root = 't/html/iter2'; + +my $tree = HTML::TreeBuilder->new_from_file("$root.html"); + +my @items = ( + [ Programmer => 'one who likes Perl and Seamstress', ], + [ DBA => 'one who does business as', ], + [ Admin => 'one who plays Tetris all day' ] + ); + +$tree->iter2( + # default wrapper_ld ok + wrapper_data => \@items, + wrapper_proc => sub { + my ($container) = @_; + + # only keep the last 2 dts and dds + my @content_list = $container->content_list; + $container->splice_content(0, @content_list - 2); + }, + # default item_ld is k00l + # default item_data is phrEsh + # default item_proc will do w0rk + splice => sub { + my ($container, @item_elems) = @_; + $container->unshift_content(@item_elems); + }, + + debug => 1, + ); + + + my $generated_html = ptree($tree, "$root.gen"); + + is ($generated_html, File::Slurp::read_file("$root.exp"), + "HTML for generated li"); diff --git a/t/m/SelectData.pm b/t/m/SelectData.pm new file mode 100644 index 0000000..65ce175 --- /dev/null +++ b/t/m/SelectData.pm @@ -0,0 +1,22 @@ +package SelectData; + + + +my @clan_data = ( + { clan_name => 'janglers', clan_id => 12, selected => 1 }, + { clan_name => 'thugknights', clan_id => 14 }, + { clan_name => 'cavaliers' , clan_id => 13 } + ); + + +sub new { + my $this = shift; + bless {}, ref($this) || $this; +} + +sub load_data { + \@clan_data +} + + +1; diff --git a/t/m/SimpleClass.pm b/t/m/SimpleClass.pm new file mode 100644 index 0000000..d0f4a75 --- /dev/null +++ b/t/m/SimpleClass.pm @@ -0,0 +1,29 @@ +package SimpleClass; + + +my @name = qw(bob bill brian babette bobo bix); +my @age = qw(99 12 44 52 12 43); +my @weight = qw(99 52 80 124 120 230); + + +sub new { + my $this = shift; + bless {}, ref($this) || $this; +} + +sub load_data { + my @data; + + for (0 .. 5) { + push @data, { + age => shift @age, + name => shift @name, + weight => shift @weight + } + } + + \@data +} + + +1; diff --git a/t/m/TestUtils.pm b/t/m/TestUtils.pm new file mode 100644 index 0000000..e5f2b69 --- /dev/null +++ b/t/m/TestUtils.pm @@ -0,0 +1,31 @@ +package TestUtils; + +use HTML::PrettyPrinter; +use FileHandle; +use File::Slurp; + +use Carp qw(carp cluck croak confess); + +require Exporter; +@ISA=qw(Exporter); +@EXPORT = qw(ptree html_dir); + +sub html_dir { + 't/html/' +} + +sub ptree { + my $tree = shift or confess 'must supply tree'; + my $out = shift or confess 'must supply outfile'; + + my $hpp = HTML::PrettyPrinter->new + (tabify => 0, allow_forced_nl => 1, quote_attr => 1); + my $lines = $hpp->format($tree); + + write_file $out, @$lines; + join '', @$lines; +} + + + +1; diff --git a/t/not-used/Arsenal.pl b/t/not-used/Arsenal.pl new file mode 100644 index 0000000..eb18749 --- /dev/null +++ b/t/not-used/Arsenal.pl @@ -0,0 +1,4 @@ +use lib '.'; +use Arsenal; + +Arsenal->new->load_data; diff --git a/t/not-used/Arsenal.pm b/t/not-used/Arsenal.pm new file mode 100644 index 0000000..62a45fe --- /dev/null +++ b/t/not-used/Arsenal.pm @@ -0,0 +1,70 @@ +package Arsenal; + +use strict; +use Data::Dumper; + +my %player; + +sub new { + my $this = shift; + bless {}, ref($this) || $this; +} + +my $number = qr!\d{1,2}!; +my $name = qr!\w+(?:\s\w{2,}){1,2}!; +my $position = qr!\w!; +my $height = qr!\d[-]\d{1,2}!; +my $weight = qr!\d{2,3}!; +my $birthday = qr!\w{3}\s\d{1,2},\s\d{4}!; +my $birthplace= qr!\w+(?:\s\w+)*(?:,\s\S+)*!; + +sub load_data { + my @data; + + while () { + last if /__END__/; + + @player{qw(number name pos height weight birthday birthplace)} + = + m! + ($number)\s+ + ($name)\s+ + ($position)\s+ + ($height)\s+ + ($weight)\s+ + ($birthday)\s+ + ($birthplace) + !x; + + warn $_; + warn Dumper \%player; + } +} + +1; +__DATA__ +24 Manuel Almunia G 6-3 190 May 19, 1977 Pamplona, Spain + 10 Dennis Bergkamp F 6-0 172 May 10, 1969 Amsterdam, Netherlands + 23 Sol Campbell D 6-2 201 Sep 18, 1974 Newham, England + 22 Gael Clichy D 5-11 159 Jul 26, 1985 Clichy, France + 3 Ashley Cole D 5-7 148 Dec 20, 1980 Stepney, England + 18 Pascal Cygan D 6-4 192 Apr 19, 1974 Lens, France + 27 Emmanuel Eboue D 5-10 159 Jun 4, 1983 Abidjan, Cote d'Ivoire + 15 Francesc Fabregas Soler M 5-7 152 Apr 4, 1987 Arenys del Mar, Spain + 16 Mathieu Flamini M 5-10 148 Mar 7, 1984 Marseille, France + 40 Ryan Garry D 6-2 181 Sep 29, 1983 Hornchurch, England + 14 Thierry Henry F 6-2 179 Aug 17, 1977 Paris, France + 13 Aliksandr Hleb M 6-1 154 May 1, 1981 Minsk, USSR + 12 Lauren D 5-11 157 Jan 19, 1977 Londi Kribi, Cameroon + 1 Jens Lehmann G 6-3 192 Nov 10, 1969 Essen, West Germany + 8 Fredrik Ljungberg M 5-9 165 Apr 16, 1977 Halmstads, Sweden + 26 Quincy Owusu Abeyie F 5-11 163 Apr 15, 1986 Amsterdam, Netherlands + 7 Robert Pires M 6-1 163 Oct 29, 1973 Reims, France + 21 Mart Poom G 6-4 187 Feb 3, 1972 Tallinn, USSR + 9 Jose Antonio Reyes F 6-0 181 Sep 1, 1983 Utrera, Spain + 20 Philippe Senderos D 6-3 185 Feb 14, 1985 Geneva, Switzerland + 19 Gilberto Silva M 6-3 172 Oct 7, 1976 Belo Horizonte, Brazil + 17 Alexandre Song M 6-0 168 Apr 9, 1987 Cameroon + 28 Kolo Toure D 6-0 168 Mar 19, 1981 Sokoura Bouake, Cote d'Ivoire + 11 Robin van Persie F 6-0 157 Aug 6, 1983 Rotterdam, Netherlands +__END__ diff --git a/t/position.t b/t/position.t new file mode 100644 index 0000000..b48463d --- /dev/null +++ b/t/position.t @@ -0,0 +1,37 @@ +use strict; +use Test::More qw(no_plan); + +use HTML::TreeBuilder; +use HTML::Element::Library; + +my $html =<<'EOHTML'; + + + + + + + + + +
    a a a a +
    a a a a +
    + + +EOHTML + +my $t1; +my $lol; + +$t1 = HTML::TreeBuilder->new_from_content ( $html ) ; + +my $found= $t1->look_down(id => 'findme'); + + +my @found = $found->position; +#warn "@found"; + +is("@found", '-1 1 0 1 2'); + + diff --git a/t/q b/t/q new file mode 100644 index 0000000..d0796e2 --- /dev/null +++ b/t/q @@ -0,0 +1,23 @@ +# I am trying to run this code: + +$t1 = HTML::TreeBuilder->new_from_content ( $html ) ; + +my $found= $t1->look_down(id => 'findme'); + +warn "blessed as: $found"; +bless $found, 'HTML::Element::Library'; +warn "blessed as: $found"; + +my @found = $found->position; +warn "@found"; + +# But I get this error (it is part of a test suite): + +blessed as: HTML::Element=HASH(0x81632d8) at t/position.t line 31. +blessed as: HTML::Element::Library=HASH(0x81632d8) at t/position.t line 33. +Can't locate object method "addr" via package "HTML::Element" at /home/terry/perl/hax/HTML-Element-Library/blib/lib/HTML/Element/Library.pm line 66. + +# What I don't understand is why it says it can't locate the method "addr" +# in package HTML::Element when the method was reblessed as +# HTML::Element::Library and sub addr is right here in the package +# HTML::Element::Library diff --git a/t/replace_content.t b/t/replace_content.t new file mode 100644 index 0000000..f814599 --- /dev/null +++ b/t/replace_content.t @@ -0,0 +1,33 @@ +use strict; +use Test::More qw(no_plan); + +use HTML::Element::Library; + + +my $t1; +my $lol; +$t1 = HTML::Element->new_from_lol + ( + $lol = + ['html', + ['head', + [ 'title', 'I like stuff!' ], + ], + ['body', + { + 'lang', 'en-JP'}, + 'stuff', + ['p', 'um, p < 4!', {'class' => 'par123'}], + ['div', {foo => 'bar'}, '123'], # at 0.1.2 + ['div', {jack => 'olantern'}, '456'], # at 0.1.2 + ] + ] + ) + ; + + +$t1->look_down('_tag' => 'body')->replace_content('all gone!'); +is( $t1->as_HTML, 'I like stuff!all gone! +', "replaced all of body"); + + diff --git a/t/set_child_content.t b/t/set_child_content.t new file mode 100644 index 0000000..dd6673a --- /dev/null +++ b/t/set_child_content.t @@ -0,0 +1,34 @@ +use strict; +use Test::More qw(no_plan); + +use HTML::Element::Library; + + +my $t1; +my $lol; +$t1 = HTML::Element->new_from_lol + ( + $lol = + ['html', + ['head', + [ 'title', 'I like stuff!' ], + ], + ['body', {id => 'corpus'}, + { + 'lang', 'en-JP'}, + 'stuff', + ['p', 'um, p < 4!', {'class' => 'par123'}], + ['div', {foo => 'bar'}, '123'], # at 0.1.2 + ['div', {jack => 'olantern'}, '456'], # at 0.1.2 + ] + ] + ) + ; + + +#$t1->look_down('_tag' => 'body')->replace_content('all gone!'); +$t1->set_child_content(id => 'corpus', 'all gone!'); +is( $t1->as_HTML, 'I like stuff!all gone! +', "replaced all of body"); + + diff --git a/t/sibdex.t b/t/sibdex.t new file mode 100644 index 0000000..7c959f5 --- /dev/null +++ b/t/sibdex.t @@ -0,0 +1,32 @@ +use strict; +use Test::More qw(no_plan); + +use HTML::Element::Library; + + +my $t1; +my $lol; +$t1 = HTML::Element->new_from_lol + ( + $lol = + ['html', + ['head', + [ 'title', 'I like stuff!' ], + ], + ['body', + { + 'lang', 'en-JP'}, + 'stuff', + ['p', 'um, p < 4!', {'class' => 'par123'}], + ['div', {foo => 'bar'}, '123'], # at 0.1.2 + ['div', {jack => 'olantern'}, '456'], # at 0.1.2 + ] + ] + ) + ; + +my $p = $t1->look_down('_tag' => 'body')->look_down(_tag => 'p'); + +is($p->sibdex, 1, "does the p tag have 1 as its index"); + + diff --git a/t/siblings.t b/t/siblings.t new file mode 100644 index 0000000..d1e753e --- /dev/null +++ b/t/siblings.t @@ -0,0 +1,40 @@ +# Before `make install' is performed this script should be runnable with +# `make test'. After `make install' it should work as `perl HTML-Element-Library.t' + + + + +use strict; +use Test::More qw(no_plan); + +use HTML::Element::Library; + + +my $t1; +my $lol; +$t1 = HTML::Element->new_from_lol + ( + $lol = + ['html', + ['head', + [ 'title', 'I like stuff!' ], + ], + ['body', + { + 'lang', 'en-JP'}, + 'stuff', + ['p', 'um, p < 4!', {'class' => 'par123'}], + ['div', {foo => 'bar'}, '123'], # at 0.1.2 + ['div', {jack => 'olantern'}, '456'], # at 0.1.2 + ] + ] + ) + ; + +my $div = $t1->look_down('_tag' => 'body')->look_down(_tag => 'p'); +my @sibs = $div->siblings; + +is($sibs[0], 'stuff', "first sibling is simple text"); +is($sibs[2]->tag, 'div', "3rd tag a div tag"); +is(scalar @sibs, 4, "4 siblings total"); + diff --git a/t/table-alt.t b/t/table-alt.t new file mode 100644 index 0000000..2880b48 --- /dev/null +++ b/t/table-alt.t @@ -0,0 +1,56 @@ +# This might look like shell script, but it's actually -*- perl -*- +use strict; +use lib qw(t/ t/m/); + + +use File::Slurp; +use Test::More qw(no_plan); + +use TestUtils; +use HTML::TreeBuilder; +use HTML::Element::Library; + +use SimpleClass; + +my $root = 't/html/table-alt'; +my $o = SimpleClass->new; +my $tree = HTML::TreeBuilder->new_from_file("$root.html"); + + +$tree->table + ( + # tell seamstress where to find the table, via the method call + # ->look_down('id', $gi_table). Seamstress detaches the table from the + # HTML tree automatically if no table rows can be built + + gi_table => 'load_data', + + # tell seamstress where to find the tr. This is a bit useless as + # the
tags + + td_data => sub { my ($tr_node, $tr_data) = @_; + $tr_node->content_handler($_ => $tr_data->{$_}) + for qw(name age weight) } + + ); + + my $generated_html = ptree($tree, "$root.gen"); + + is ($generated_html, File::Slurp::read_file("$root.exp"), + "HTML for non-alternating table"); diff --git a/t/table.t b/t/table.t new file mode 100644 index 0000000..54ff6a2 --- /dev/null +++ b/t/table.t @@ -0,0 +1,56 @@ +# This might look like shell script, but it's actually -*- perl -*- +use strict; +use lib qw(t/ t/m/); + + +use File::Slurp; +use Test::More qw(no_plan); + +use TestUtils; +use HTML::TreeBuilder; +use HTML::Element::Library; + +use SimpleClass; + +my $root = 't/html/table'; +my $o = SimpleClass->new; +my $tree = HTML::TreeBuilder->new_from_file("$root.html"); + + +$tree->table + ( + # tell seamstress where to find the table, via the method call + # ->look_down('id', $gi_table). Seamstress detaches the table from the + # HTML tree automatically if no table rows can be built + + gi_table => 'load_data', + + # tell seamstress where to find the tr. This is a bit useless as + # the
tags + + td_data => sub { my ($tr_node, $tr_data) = @_; + $tr_node->content_handler($_ => $tr_data->{$_}) + for qw(name age weight) } + + ); + + my $generated_html = ptree($tree, "$root.gen"); + + is ($generated_html, File::Slurp::read_file("$root.exp"), + "HTML for non-alternating table"); diff --git a/t/table2-table_ld.t b/t/table2-table_ld.t new file mode 100644 index 0000000..ba7bdab --- /dev/null +++ b/t/table2-table_ld.t @@ -0,0 +1,71 @@ +# This might look like shell script, but it's actually -*- perl -*- +# Test the 3 possible look_down calls to table2() +# a = default +# b = supplied array ref +# c = supplied code ref + +use strict; +use lib qw(t/ t/m/); + + +use File::Slurp; +use Test::More qw(no_plan); + +use TestUtils; +use HTML::TreeBuilder; +use HTML::Element::Library; + +use data::table2; + + +my $o = data::table2->new; + +# a - default table_ld + +my $root = 't/html/table2-table_ld-default'; +my $tree = HTML::TreeBuilder->new_from_file("$root.html"); + + +my $table = HTML::Element::Library::ref_or_ld( + $tree, + ['_tag' => 'table'] + ); + +my $generated_html = ptree($table, "$root.gen"); + +is ($generated_html, File::Slurp::read_file("$root.exp"), $root); + +# b - arrayref table_ld + +$root = 't/html/table2-table_ld-arrayref'; +$tree = HTML::TreeBuilder->new_from_file("$root.html"); + + +$table = HTML::Element::Library::ref_or_ld( + $tree, + [frame => 'hsides', rules => 'groups'] + ); + +$generated_html = ptree($table, "$root.gen"); + +is ($generated_html, File::Slurp::read_file("$root.exp"), $root); + +# c - coderef table_ld + +$root = 't/html/table2-table_ld-coderef'; +$tree = HTML::TreeBuilder->new_from_file("$root.html"); + + +$table = HTML::Element::Library::ref_or_ld( + $tree, + sub { + my ($t) = @_; + my $caption = $t->look_down('_tag' => 'caption'); + $caption->parent; + } + ); + +$generated_html = ptree($table, "$root.gen"); + +is ($generated_html, File::Slurp::read_file("$root.exp"), $root); + diff --git a/t/table2-tr_ld.t b/t/table2-tr_ld.t new file mode 100644 index 0000000..8e364ec --- /dev/null +++ b/t/table2-tr_ld.t @@ -0,0 +1,87 @@ +# This might look like shell script, but it's actually -*- perl -*- +# Test the 3 possible look_down calls to table2() +# a = default +# b = supplied array ref +# c = supplied code ref + +use strict; +use lib qw(t/ t/m/); + + +use File::Slurp; +use Test::More qw(no_plan); + +use TestUtils; +use HTML::TreeBuilder; +use HTML::Element::Library; +use Scalar::Listify; + +use data::table2; + + +my $o = data::table2->new; + +# a - default table_ld + +my $root = 't/html/table2-tr_ld-default'; +my $tree = HTML::TreeBuilder->new_from_file("$root.html"); + + +my @tr = HTML::Element::Library::ref_or_ld( + $tree, + ['_tag' => 'tr'] + ); + +is (scalar @tr, 16, 'default ld_tr'); + +# b - arrayref tr_ld + +$root = 't/html/table2-tr_ld-arrayref'; +$tree = HTML::TreeBuilder->new_from_file("$root.html"); + + +my $tr = HTML::Element::Library::ref_or_ld( + $tree, + [class => 'findMe'] + ); + +my $generated_html = ptree($tr, "$root.gen"); + +is ($generated_html, File::Slurp::read_file("$root.exp"), $root); + +# c - coderef tr_ld +# removes windows listings before returning @tr + +$root = 't/html/table2-tr_ld-coderef'; +$tree = HTML::TreeBuilder->new_from_file("$root.html"); + + +@tr = HTML::Element::Library::ref_or_ld( + $tree, + sub { + my ($t) = @_; + my @tr = $t->look_down('_tag' => 'tr'); + my @keep; + for my $tr (@tr) { + + my @td = $tr->look_down ('_tag' => 'td') ; + my $detached; + for my $td (@td) { + if (grep { $_ =~ /Windows/ } $td->content_list) { + $tr->detach(); + ++$detached; + last; + } + } + push @keep, $tr unless $detached; + } + @keep; + } + ); + +#warn $_->as_HTML, $/ for @tr; + +$generated_html = ptree($tree, "$root.gen"); + +is ($generated_html, File::Slurp::read_file("$root.exp"), $root); + diff --git a/t/table2.t b/t/table2.t new file mode 100644 index 0000000..eb0bb02 --- /dev/null +++ b/t/table2.t @@ -0,0 +1,52 @@ +# This might look like shell script, but it's actually -*- perl -*- +use strict; +use lib qw(t/ t/m/); + + +use File::Slurp; +use Test::More qw(no_plan); + +use TestUtils; + +use Data::Dumper; +use HTML::TreeBuilder; +use HTML::Element::Library; + +use data::table2; + +my $root = 't/html/table2'; +my $o = data::table2->new; +my $d = data::table2->load_data; +my $tree = HTML::TreeBuilder->new_from_file("$root.html"); + +#warn 'D:', Dumper $d; + +for my $dataset (keys %$d) { + my %tbody = ('4dig' => 0, '3dig' => 1); + $tree->table2 ( +# debug => 1, + table_data => $d->{$dataset}, + tr_base_id => $dataset, + tr_ld => sub { + my $t = shift; + my $tbody = ($t->look_down('_tag' => 'tbody'))[$tbody{$dataset}]; + my @tbody_child = $tbody->content_list; + $tbody_child[$_]->detach for (1 .. $#tbody_child) ; + $tbody->content_list; + }, + td_proc => sub { + my ($tr, $data) = @_; + my @td = $tr->look_down('_tag' => 'td'); + for my $i (0..$#td) { +# warn $i; + $td[$i]->splice_content(0, 1, $data->[$i]); + } + } + ); +} + + +my $generated_html = ptree($tree, "$root.gen"); + +is ($generated_html, File::Slurp::read_file("$root.exp"), + "HTML for non-alternating table"); diff --git a/t/unroll_select.t b/t/unroll_select.t new file mode 100644 index 0000000..90b87b7 --- /dev/null +++ b/t/unroll_select.t @@ -0,0 +1,33 @@ +# This might look like shell script, but it's actually -*- perl -*- +use strict; +use lib qw(t/ t/m/); + + +use File::Slurp; +use Test::More qw(no_plan); + +use TestUtils; +use HTML::TreeBuilder; +use HTML::Element::Library; + +use SelectData; + +my $root = 't/html/unroll_select'; + +my $tree = HTML::TreeBuilder->new_from_file("$root.html"); + + +$tree->unroll_select + ( + select_label => 'clan_list', + option_value => sub { my $row = shift; $row->{clan_id} }, + option_content => sub { my $row = shift; $row->{clan_name} }, + option_selected => sub { my $row = shift; $row->{selected} }, + data => SelectData->load_data, + data_iter => sub { my $data = shift; shift @$data } + ); + + my $generated_html = ptree($tree, "$root.gen"); + + is ($generated_html, File::Slurp::read_file("$root.exp"), + "HTML for non-alternating table"); diff --git a/t/wrap_content.t b/t/wrap_content.t new file mode 100644 index 0000000..d81abe8 --- /dev/null +++ b/t/wrap_content.t @@ -0,0 +1,39 @@ +use strict; +use Test::More qw(no_plan); + +use HTML::Element::Library; + + +my $t1; +my $lol; +$t1 = HTML::Element->new_from_lol + ( + $lol = + ['html', + ['head', + [ 'title', 'I like stuff!' ], + ], + ['body', + { + 'lang', 'en-JP'}, + 'stuff', + ['p', + ['span', {id => 'wrapme'}, + 'um, p < 4!', + ], + {'class' => 'par123'}], + ['div', {foo => 'bar'}, '123'], # at 0.1.2 + ['div', {jack => 'olantern'}, '456'], # at 0.1.2 + ] + ] + ) + ; + +my $bold = HTML::Element->new('b', id => 'wrapper'); + +my $W = $t1->look_down('id' => 'wrapme'); +$W->wrap_content($bold); +is( $W->as_HTML, 'um, p < 4! +', "wrapped text"); + + -- 2.39.2