]> iEval git - html-element-library.git/blame - t/table-alt.t
hash_map method about to be public for real
[html-element-library.git] / t / table-alt.t
CommitLineData
67e78ff2 1# This might look like shell script, but it's actually -*- perl -*-
2use strict;
3use lib qw(t/ t/m/);
4
5
6use File::Slurp;
7use Test::More qw(no_plan);
8
9use TestUtils;
10use HTML::TreeBuilder;
11use HTML::Element::Library;
12
13use SimpleClass;
14
15my $root = 't/html/table-alt';
16my $o = SimpleClass->new;
17my $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 => ['iterate1', 'iterate2'],
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 my $generated_html = ptree($tree, "$root.gen");
54
55 is ($generated_html, File::Slurp::read_file("$root.exp"),
56 "HTML for non-alternating table");
This page took 0.027933 seconds and 4 git commands to generate.