1 # This might look like shell script, but it's actually -*- perl -*-
7 use Test::More qw(no_plan);
10 use HTML::TreeBuilder;
11 use HTML::Element::Library;
15 my $root = 't/html/table-alt';
16 my $o = SimpleClass->new;
17 my $tree = HTML::TreeBuilder->new_from_file("$root.html");
22 # tell seamstress where to find the table, via the method call
23 # ->look_down('id', $gi_table). Seamstress detaches the table from the
24 # HTML tree automatically if no table rows can be built
26 gi_table => 'load_data',
28 # tell seamstress where to find the tr. This is a bit useless as
29 # the <tr> usually can be found as the first child of the parent
31 gi_tr => ['iterate1', 'iterate2'],
33 # the model data to be pushed into the table
35 table_data => $o->load_data,
37 # the way to take the model data and obtain one row
38 # if the table data were a hashref, we would do:
39 # my $key = (keys %$data)[0]; my $val = $data->{$key}; delete $data->{$key}
41 tr_data => sub { my ($self, $data) = @_;
45 # the way to take a row of data and fill the <td> tags
47 td_data => sub { my ($tr_node, $tr_data) = @_;
48 $tr_node->content_handler($_ => $tr_data->{$_})
49 for qw(name age weight) }
53 my $generated_html = ptree($tree, "$root.gen");
55 is ($generated_html, File::Slurp::read_file("$root.exp"),
56 "HTML for non-alternating table");