]> iEval git - html-element-library.git/blobdiff - lib/HTML/Element/Library.pm
data_map method
[html-element-library.git] / lib / HTML / Element / Library.pm
index 08f6ee5cf0fa293fd3203880f37938e9cfbde61a..ef03c78f0f9cb83b292bc907c4f25c64cf2b5091 100644 (file)
@@ -12,6 +12,7 @@ use Array::Group qw(:all);
 use Carp qw(confess);
 use Data::Dumper;
 use HTML::Element;
+use List::Util qw(first);
 use List::MoreUtils qw/:all/;
 use Params::Validate qw(:all);
 use Scalar::Listify;
@@ -36,13 +37,38 @@ sub HTML::Element::siblings {
   $p->content_list;
 }
 
+sub HTML::Element::data_map {
+
+    my ($container, @rest) = @_;
+
+
+  my %p = validate(@rest, {
+    href      => 1,
+    with_attr => 1,
+    excluding => { type => ARRAYREF, default => [] }
+   }
+                 );
+
+  my @same_as = $container->look_down('_attr' => $p{with_attr});
+
+  for my $same_as (@same_as) {
+      next if first { $same_as eq $_ } @{$p{excluding}}  ;
+      $same_as->replace_content( $p{href}->{ $same_as->attr( $p{with_attr} ) } ) ;
+  }
+
+}
+
+
 sub HTML::Element::passover {
   my ($tree, $child_id) = @_;
   
-  #warn "ARGS:   my ($tree, $child)";
+  warn "ARGS:   my ($tree, $child_id)" if $DEBUG;
+  warn $tree->as_HTML(undef, ' ') if $DEBUG;
 
   my $exodus = $tree->look_down(id => $child_id);
 
+  warn "E: $exodus" if $DEBUG;
+
   my @s = HTML::Element::siblings($exodus);
 
   for my $s (@s) {
@@ -111,9 +137,12 @@ sub HTML::Element::position {
 
 
 sub HTML::Element::content_handler {
-  my ($tree, $id_name, $content) = @_;
+  my ($tree, %content_hash) = @_;
+
+  for my $k (keys %content_hash) {
+      $tree->set_child_content(id => $k, $content_hash{$k});      
+  }
 
-  $tree->set_child_content(id => $id_name, $content);
 
 }
 
@@ -185,6 +214,7 @@ sub HTML::Element::iter2 {
   warn "wrapper_data: " . Dumper $p{wrapper_data} if $p{debug} ;
 
   my $container = ref_or_ld($tree, $p{wrapper_ld});
+  warn "container: " . $container if $p{debug} ;
   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} ;
@@ -737,7 +767,7 @@ happens to be a non-element, a push_content is performed instead.
 
 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)
+=head3 $tree->content_handler(%id_content)
 
 This is a convenience method. Because the look_down criteria will often simply be:
 
@@ -755,6 +785,15 @@ Instead of typing:
 
   $elem->set_child_content(sid => 'fixme', 'new text') 
 
+PLEASE NOTE: you can pass a hash whose keys are C<id>s and whose values are the content you want there and it will perform the replacement on each hash member:
+
+  my %id_content = (name => "Terrence Brannon",      
+                    email => 'tbrannon@in.com',
+                    balance => 666,                         
+                    content => $main_content);             
+
+  $tree->content_handler(%id_content);  
+
 =head3 $tree->highlander($subtree_span_id, $conditionals, @conditionals_args)
 
 This allows for "if-then-else" style processing. Highlander was a movie in
This page took 0.018738 seconds and 4 git commands to generate.