$p->content_list;
}
+sub HTML::Element::defmap {
+ my($tree,$attr,$hashref)=@_;
+
+ while (my ($k, $v) = (each %$hashref)) {
+ my $found = $tree->look_down($attr => $k);
+ if ($found) {
+ $found->replace_content( $v );
+ }
+ }
+
+}
+
+
sub HTML::Element::hash_map {
my $container = shift;
warn 'The container tag is ', $container->tag if $p{debug} ;
warn 'hash' . Dumper($p{hash}) if $p{debug} ;
- warn 'at_under' . Dumper(\@_);
+ warn 'at_under' . Dumper(\@_) if $p{debug} ;
my @same_as = $container->look_down( $p{to_attr} => qr/.+/ ) ;
}
+sub HTML::Element::hashmap {
+ my ($container, $attr_name, $hashref, $excluding, $debug) = @_;
+
+ $excluding ||= [] ;
+
+ $container->hash_map(hash => $hashref,
+ to_attr => $attr_name,
+ excluding => $excluding,
+ debug => $debug);
+
+}
+
sub HTML::Element::passover {
my ($tree, $child_id) = @_;
my $select = {};
+ warn "Select Hash: " . Dumper(\%select) if $select{debug};
+
my $select_node = $s->look_down(id => $select{select_label});
warn "Select Node: " . $select_node if $select{debug};
=head2 Tree Rewriting Methods
-=head3 $elem->hash_map(hash => \%h, to_attr => $attr, excluding => \@excluded)
+=head3 $elem->hashmap($attr_name, \%hashref, \@excluded, $debug)
This method is designed to take a hashref and populate a series of elements. For example:
Then a single API call allows us to populate the HTML while excluding those ones we dont:
- $tree->hash_map(hash => \%data, to_attr => 'sid', excluding => ['password']);
+ $tree->hashmap('sid' => \%data, ['password']);
+
-Of course, the other way to prevent rendering some of the hash mapping is to not give that element the attr
+Note: the other way to prevent rendering some of the hash mapping is to not give that element the attr
you plan to use for hash mapping.
+Also note: the function C<< hashmap >> has a simple easy-to-type API. Interally, it calls C<< hash_map >>
+(which has a more verbose keyword calling API). Thus, the above call to C<hashmap()> results in this call:
+
+ $tree->hash_map(hash => \%data, to_attr => 'sid', excluding => ['password']);
+
=head3 $elem->replace_content(@new_elem)
L<HTML::Seamstress>
-=head1 AUTHOR
+=head1 AUTHOR / SOURCE
Terrence Brannon, E<lt>tbone@cpan.orgE<gt>
Many thanks to BARBIE for his RT bug report.
+The source is at L<http://github.com/metaperl/html-element-library/tree/master>
+
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2004 by Terrence Brannon
--- /dev/null
+# This might look like shell script, but it's actually -*- perl -*-
+use strict;use warnings;
+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 $root = "t/html/defmap/defmap";
+
+ my $tree = HTML::TreeBuilder->new_from_file("$root.initial")->guts;
+
+ #warn "TREE: $tree" . $tree->as_HTML;
+
+ my %data = (pause => 'arsenal rules');
+
+ $tree->defmap(smap => \%data);
+
+ my $generated_html = ptree($tree, "$root.gen");
+
+ is ($generated_html, File::Slurp::read_file("$root.exp"), "HTML for same_as");
+}
+
+
+tage();
+
--- /dev/null
+# 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 $root = "t/html/same_as/same_as";
+
+ my $tree = HTML::TreeBuilder->new_from_file("$root.initial");
+
+ #warn "TREE: $tree" . $tree->as_HTML;
+
+ my %data = (people_id => 888, phone => '444-4444', email => 'm@xml.com');
+
+ $tree->hash_map
+ (hash => \%data,
+ to_attr => 'sid',
+ excluding => [ 'email' ],
+ debug => 1
+ );
+
+ my $generated_html = ptree($tree, "$root.gen");
+
+ is ($generated_html, File::Slurp::read_file("$root.exp"), "HTML for same_as");
+}
+
+
+tage();
+
--- /dev/null
+<tr>
+ <td smap="active">Yes</td>
+ <td smap="pause">arsenal rules</td>
+ <td smap="hold">No</td>
+</tr>
--- /dev/null
+<tr>
+ <td smap="active">Yes</td>
+ <td smap="pause">arsenal rules</td>
+ <td smap="hold">No</td>
+</tr>
--- /dev/null
+<tr>
+ <td smap="active" >Yes</td>
+
+ <td smap="pause">No</td>
+
+ <td smap="hold">No</td>
+</tr>
<td>Clan Name</td>
<td>
<select name="name" id="clan_list">
- <option value="12" id="clan_name" selected="1">janglers</option>
- <option value="14" id="clan_name">thugknights</option>
- <option value="13" id="clan_name">cavaliers</option>
+ <option value="12" selected="1">janglers</option>
+ <option value="14">thugknights</option>
+ <option value="13">cavaliers</option>
</select>
</td>
</tr>
<td>Clan Name</td>
<td>
<select name="name" id="clan_list">
- <option value="12" id="clan_name" selected="1">janglers</option>
- <option value="14" id="clan_name">thugknights</option>
- <option value="13" id="clan_name">cavaliers</option>
+ <option value="12" selected="1">janglers</option>
+ <option value="14">thugknights</option>
+ <option value="13">cavaliers</option>
</select>
</td>
</tr>
+++ /dev/null
-# 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 $root = "t/html/same_as/same_as";
-
- my $tree = HTML::TreeBuilder->new_from_file("$root.initial");
-
- #warn "TREE: $tree" . $tree->as_HTML;
-
- my %data = (people_id => 888, phone => '444-4444', email => 'm@xml.com');
-
- $tree->hash_map
- (hash => \%data,
- to_attr => 'sid',
- excluding => [ 'email' ],
- debug => 1
- );
-
- my $generated_html = ptree($tree, "$root.gen");
-
- is ($generated_html, File::Slurp::read_file("$root.exp"), "HTML for same_as");
-}
-
-
-tage();
-