data_map method
authorTerrence Brannon <TBrannon@SmartFinancial.com>
Mon, 2 Feb 2009 22:05:06 +0000 (17:05 -0500)
committerTerrence Brannon <TBrannon@SmartFinancial.com>
Mon, 2 Feb 2009 22:05:06 +0000 (17:05 -0500)
.emacs.desktop [new file with mode: 0644]
lib/HTML/Element/Library.pm
t/html/same_as.html [new file with mode: 0644]
t/html/same_as/same_as.exp [new file with mode: 0644]
t/html/same_as/same_as.gen [new file with mode: 0644]
t/html/same_as/same_as.initial [new file with mode: 0644]
t/same_as.t [new file with mode: 0644]

diff --git a/.emacs.desktop b/.emacs.desktop
new file mode 100644 (file)
index 0000000..4c1ddc3
--- /dev/null
@@ -0,0 +1,160 @@
+;; -*- mode: emacs-lisp; coding: emacs-mule; -*-
+;; --------------------------------------------------------------------------
+;; Desktop File for Emacs
+;; --------------------------------------------------------------------------
+;; Created Tue Jan 13 20:12:45 2009
+;; Desktop file format version 206
+;; Emacs version 22.3.1
+
+;; Global section:
+(setq desktop-missing-file-warning nil)
+(setq tags-file-name nil)
+(setq tags-table-list nil)
+(setq search-ring '("pay" "factory" "TREE_" "tree_content" "tree_con" "shell_content" "contact" "passover" "content_handler" "'"))
+(setq regexp-search-ring nil)
+(setq register-alist nil)
+
+;; Buffer section -- buffers listed in same order as in buffer list:
+(desktop-create-buffer 206
+  "/tmp/leads2/admin/affiliates.cgi"
+  "affiliates.cgi"
+  'cperl-mode
+  '(global-auto-revert-mode)
+  3601
+  '(4531 t)
+  nil
+  nil
+  '((buffer-file-coding-system . undecided-unix)))
+
+(desktop-create-buffer 206
+  nil
+  "admin"
+  'dired-mode
+  '(global-auto-revert-mode)
+  542
+  '(nil nil)
+  t
+  '("/tmp/leads2/admin/")
+  nil)
+
+(desktop-create-buffer 206
+  "/home/tbrannon/prg/html-seamstress/lib/HTML/Seamstress.pm"
+  "Seamstress.pm"
+  'cperl-mode
+  '(global-auto-revert-mode)
+  661
+  '(nil nil)
+  nil
+  nil
+  '((buffer-file-coding-system . undecided-unix)))
+
+(desktop-create-buffer 206
+  "/var/log/httpd/error_log"
+  "error_log"
+  'fundamental-mode
+  '(global-auto-revert-mode)
+  154167
+  '(151473 t)
+  t
+  nil
+  '((buffer-file-coding-system . undecided-unix)))
+
+(desktop-create-buffer 206
+  nil
+  "html-seamstress"
+  'dired-mode
+  '(global-auto-revert-mode)
+  669
+  '(1778 t)
+  t
+  '("/home/tbrannon/prg/html-seamstress/" "/home/tbrannon/prg/html-seamstress/lib/" "/home/tbrannon/prg/html-seamstress/lib/HTML/")
+  nil)
+
+(desktop-append-buffer-args 206
+  nil
+  "lib"
+  'dired-mode
+  '(global-auto-revert-mode)
+  251
+  '(nil nil)
+  t
+  '("/home/tbrannon/prg/html-seamstress/lib/")
+  nil)
+
+(desktop-append-buffer-args 206
+  nil
+  "HTML"
+  'dired-mode
+  '(global-auto-revert-mode)
+  257
+  '(nil nil)
+  t
+  '("/home/tbrannon/prg/html-seamstress/lib/HTML/")
+  nil)
+
+(desktop-append-buffer-args 206
+  nil
+  "html-element-library"
+  'dired-mode
+  '(global-auto-revert-mode)
+  1834
+  '(1496 t)
+  t
+  '("/home/tbrannon/prg/html-element-library/" "/home/tbrannon/prg/html-element-library/lib/" "/home/tbrannon/prg/html-element-library/lib/HTML/" "/home/tbrannon/prg/html-element-library/lib/HTML/Element/")
+  nil)
+
+(desktop-append-buffer-args 206
+  "/home/tbrannon/emacs/init.el"
+  "init.el"
+  'emacs-lisp-mode
+  '(global-auto-revert-mode)
+  1
+  '(3680 t)
+  nil
+  nil
+  '((buffer-file-coding-system . undecided-unix)))
+
+(desktop-append-buffer-args 206
+  nil
+  "leads2"
+  'dired-mode
+  '(global-auto-revert-mode)
+  227
+  '(nil nil)
+  t
+  '("/tmp/leads2/")
+  nil)
+
+(desktop-append-buffer-args 206
+  nil
+  "tmp"
+  'dired-mode
+  '(global-auto-revert-mode)
+  405
+  '(nil nil)
+  t
+  '("/tmp/")
+  nil)
+
+(desktop-append-buffer-args 206
+  "/home/tbrannon/prg/html-element-library/lib/HTML/Element/Library.pm"
+  "Library.pm"
+  'cperl-mode
+  '(global-auto-revert-mode)
+  18597
+  '(17049 t)
+  nil
+  nil
+  '((buffer-file-coding-system . undecided-unix)))
+
+(desktop-append-buffer-args 206
+  nil
+  "emacs"
+  'dired-mode
+  '(global-auto-revert-mode)
+  1608
+  '(nil nil)
+  t
+  '("/home/tbrannon/emacs/")
+  nil)
+
index 99abc3d39f7c534ce6eff10ac7cbba1cbedcbbeb..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_id)";
+  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) {
@@ -188,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} ;
diff --git a/t/html/same_as.html b/t/html/same_as.html
new file mode 100644 (file)
index 0000000..f70d378
--- /dev/null
@@ -0,0 +1,16 @@
+<html>
+<head>
+  <title>HO HO HA HA HA</title>
+</head>
+
+<body>
+  <table>
+    <tr sclass="tr" class="alt" align="left" valign="top">
+      <td sid="people_id">1</td>
+      <td sid="phone">(877) 255-3239</td>
+      <td sid="email"><a sid="a_email" href="mailto:jim@gmail.com">jim@gmail.com</a></td>
+    </tr>
+  </table>
+</body>
+
+</html>
\ No newline at end of file
diff --git a/t/html/same_as/same_as.exp b/t/html/same_as/same_as.exp
new file mode 100644 (file)
index 0000000..3eac36a
--- /dev/null
@@ -0,0 +1,15 @@
+<html>
+  <head>
+    <title>HO HO HA HA HA</title>
+  </head>
+  <body>
+    <table>
+      <tr align="left" sclass="tr" valign="top" class="alt">
+        <td sid="people_id">1</td>
+        <td sid="phone">(877) 255-3239</td>
+        <td sid="email"><a sid="a_email" href="mailto:leave-me-alone@gmail.com"
+            >should-not-be-touched@seamstress.com</a></td>
+      </tr>
+    </table>
+  </body>
+</html>
diff --git a/t/html/same_as/same_as.gen b/t/html/same_as/same_as.gen
new file mode 100644 (file)
index 0000000..3eac36a
--- /dev/null
@@ -0,0 +1,15 @@
+<html>
+  <head>
+    <title>HO HO HA HA HA</title>
+  </head>
+  <body>
+    <table>
+      <tr align="left" sclass="tr" valign="top" class="alt">
+        <td sid="people_id">1</td>
+        <td sid="phone">(877) 255-3239</td>
+        <td sid="email"><a sid="a_email" href="mailto:leave-me-alone@gmail.com"
+            >should-not-be-touched@seamstress.com</a></td>
+      </tr>
+    </table>
+  </body>
+</html>
diff --git a/t/html/same_as/same_as.initial b/t/html/same_as/same_as.initial
new file mode 100644 (file)
index 0000000..555abaa
--- /dev/null
@@ -0,0 +1,16 @@
+<html>
+<head>
+  <title>HO HO HA HA HA</title>
+</head>
+
+<body>
+  <table>
+    <tr sclass="tr" class="alt" align="left" valign="top">
+      <td sid="people_id">1</td>
+      <td sid="phone">(877) 255-3239</td>
+      <td sid="email"><a sid="a_email" href="mailto:leave-me-alone@gmail.com">should-not-be-touched@seamstress.com</a></td>
+    </tr>
+  </table>
+</body>
+
+</html>
\ No newline at end of file
diff --git a/t/same_as.t b/t/same_as.t
new file mode 100644 (file)
index 0000000..1fc78ba
--- /dev/null
@@ -0,0 +1,38 @@
+# 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 => 'dont-you-dare-render@xml.com');
+
+  $tree->data_map(href => \%data, with_attr => 'sid', excluding => ['email']);
+
+  my $generated_html = ptree($tree, "$root.gen");
+
+  is ($generated_html, File::Slurp::read_file("$root.exp"), "HTML for same_as");
+}
+
+
+tage();
+
This page took 0.018057 seconds and 4 git commands to generate.