make comments and doctypes get passed through
Matt S Trout [Wed, 26 May 2010 19:51:55 +0000 (20:51 +0100)]
lib/HTML/Zoom/Parser/BuiltIn.pm
t/synopsis.t

index ba6f41a..cfe21de 100644 (file)
@@ -32,28 +32,31 @@ sub _hacky_tag_parser {
       ([^<]*)
     }sxg
   ) {
-    my ($whole, $is_close, $tag_name, $attributes, $is_comment,
+    my ($whole, $is_close, $tag_name, $attributes, $is_special,
         $in_place_close, $content)
       = ($1, $2, $3, $4, $5, $6, $7, $8);
-    next if defined $is_comment;
-    $tag_name =~ tr/A-Z/a-z/;
-    if ($is_close) {
-      $handler->({ type => 'CLOSE', name => $tag_name, raw => $whole });
+    if ($is_special) {
+      $handler->({ type => 'SPECIAL', raw => $whole });
     } else {
-      $attributes = '' if !defined($attributes) or $attributes =~ /^ +$/;
-      $handler->({
-        type => 'OPEN',
-        name => $tag_name,
-        is_in_place_close => $in_place_close,
-        _hacky_attribute_parser($attributes),
-        raw_attrs => $attributes||'',
-        raw => $whole,
-      });
-      if ($in_place_close) {
+      $tag_name =~ tr/A-Z/a-z/;
+      if ($is_close) {
+        $handler->({ type => 'CLOSE', name => $tag_name, raw => $whole });
+      } else {
+        $attributes = '' if !defined($attributes) or $attributes =~ /^ +$/;
         $handler->({
-          type => 'CLOSE', name => $tag_name, raw => '',
-          is_in_place_close => 1
+          type => 'OPEN',
+          name => $tag_name,
+          is_in_place_close => $in_place_close,
+          _hacky_attribute_parser($attributes),
+          raw_attrs => $attributes||'',
+          raw => $whole,
         });
+        if ($in_place_close) {
+          $handler->({
+            type => 'CLOSE', name => $tag_name, raw => '',
+            is_in_place_close => 1
+          });
+        }
       }
     }
     if (length $content) {
index 4089bf9..8a3ac11 100644 (file)
@@ -1,3 +1,71 @@
+use strict;
+use warnings FATAL => 'all';
 use Test::More qw(no_plan);
 
-fail 'You forgot to run maint/synopsis-extract. Go do that.';
+use HTML::Zoom;
+my $template = <<HTML;
+<html>
+  <head>
+    <title>Hello people</title>
+  </head>
+  <body>
+    <h1 id="greeting">Placeholder</h1>
+    <div id="list">
+      <span>
+        <p>Name: <span class="name">Bob</span></p>
+        <p>Age: <span class="age">23</span></p>
+      </span>
+      <hr class="between" />
+    </div>
+  </body>
+</html>
+HTML
+my $output = HTML::Zoom
+  ->from_html($template)
+  ->select('title, #greeting')->replace_content('Hello world & dog!')
+  ->select('#list')->repeat_content(
+      [
+        sub {
+          $_->select('.name')->replace_content('Matt')
+            ->select('.age')->replace_content('26')
+        },
+        sub {
+          $_->select('.name')->replace_content('Mark')
+            ->select('.age')->replace_content('0x29')
+        },
+        sub {
+          $_->select('.name')->replace_content('Epitaph')
+            ->select('.age')->replace_content('<redacted>')
+        },
+      ],
+      { repeat_between => '.between' }
+    )
+  ->to_html;
+my $expect = <<HTML;
+<html>
+  <head>
+    <title>Hello world &amp; dog!</title>
+  </head>
+  <body>
+    <h1 id="greeting">Hello world &amp; dog!</h1>
+    <div id="list">
+      <span>
+        <p>Name: <span class="name">Matt</span></p>
+        <p>Age: <span class="age">26</span></p>
+      </span>
+      <hr class="between" />
+      <span>
+        <p>Name: <span class="name">Mark</span></p>
+        <p>Age: <span class="age">0x29</span></p>
+      </span>
+      <hr class="between" />
+      <span>
+        <p>Name: <span class="name">Epitaph</span></p>
+        <p>Age: <span class="age">&lt;redacted&gt;</span></p>
+      </span>
+      
+    </div>
+  </body>
+</html>
+HTML
+is($output, $expect, 'Synopsis code works ok');;