23510387575f9d692788e6b1bec19ee35425df5b
[html-element-library.git] / t / table.t
1 # This might look like shell script, but it's actually -*- perl -*-
2 use strict;
3 use lib qw(t/ t/m/);
4
5
6 use File::Slurp;
7 use Test::More qw(no_plan);
8
9 use HTML::TreeBuilder;
10 use HTML::Element::Library;
11 use Test::XML;
12
13 use SimpleClass;
14
15 my $root = 't/html/table';
16 my $o = SimpleClass->new;
17 my $tree = HTML::TreeBuilder->new_from_file("$root.html");
18
19
20 $tree->table
21 (
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
25
26 gi_table => 'load_data',
27
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
30
31 gi_tr => 'data_row',
32
33 # the model data to be pushed into the table
34
35 table_data => $o->load_data,
36
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}
40
41 tr_data => sub { my ($self, $data) = @_;
42 shift(@{$data}) ;
43 },
44
45 # the way to take a row of data and fill the <td> tags
46
47 td_data => sub { my ($tr_node, $tr_data) = @_;
48 $tr_node->content_handler($_ => $tr_data->{$_})
49 for qw(name age weight) }
50
51 );
52
53 is_xml ($tree->as_XML, scalar File::Slurp::read_file("$root.exp"),
54 "HTML for non-alternating table");
This page took 0.022755 seconds and 3 git commands to generate.