port to new zoom api
Matt S Trout [Sat, 20 Feb 2010 04:50:26 +0000 (04:50 +0000)]
lib/App/IdiotBox.pm
share/html/bucket.html
share/html/front_page.html
share/html/video.html

index 0d7956a..4a11aca 100644 (file)
@@ -49,7 +49,6 @@ sub BUILD {
   $store_class->bind($self);
 }
   
-
 dispatch {
   sub (/) { $self->show_front_page },
   subdispatch sub (/*/...) {
@@ -72,76 +71,55 @@ method buckets { $self->{buckets} }
 method show_front_page {
   my $ann = $self->recent_announcements;
   $self->html_response(
-    front_page => [
-      '#announcement-list' => [
-        -repeat_content => {
-          repeat_for => $ann->map(sub { [
-            '.fill-bucket-name' => [
-              -replace_content => { replace_with => $_->bucket->name }
-            ],
-            '.fill-bucket-link' => [
-              -set_attribute => { name => 'href', value => $_->bucket->slug.'/' }
-            ],
-            '.fill-new-videos' => [
-              -replace_content => { replace_with => $_->video_count }
-            ],
-            '.fill-total-videos' => [
-              -replace_content => { replace_with => $_->bucket->video_count }
-            ],
-          ] })->as_stream
-        }
-      ]
-    ]
+    front_page => sub {
+      $_->select('#announcement-list')
+        ->repeat_content($ann->map(sub {
+            my $obj = $_;
+            sub {
+              $_->select('.bucket-name')->replace_content($obj->bucket->name)
+                ->select('.bucket-link')->set_attribute({
+                    name => 'href', value => $obj->bucket->slug.'/'
+                  })
+                ->select('.new-videos')->replace_content($obj->video_count)
+                ->select('.total-videos')->replace_content(
+                    $obj->bucket->video_count
+                  )
+            }
+          }))
+    }
   );
 }
 
 method show_bucket ($bucket) {
-  $self->html_response(bucket => [
-    '.fill-bucket-name' => [
-      -replace_content => { replace_with => $bucket->name }
-    ],
-    '#video-list' => [
-      -repeat_content => {
-        repeat_for => $bucket->videos->map(sub { [
-          '.fill-video-name' => [
-            -replace_content => { replace_with => $_->name }
-          ],
-          '.fill-video-author' => [
-            -replace_content => { replace_with => $_->author }
-          ],
-          '.fill-video-link' => [
-            -set_attribute => {
-              name => 'href', value => $_->slug.'/'
-            }
-          ],
-        ] })->as_stream
-      }
-    ]
-  ]);
+  $self->html_response(bucket => sub {
+    $_->select('.bucket-name')->replace_content($bucket->name)
+      ->select('#video-list')->repeat_content($bucket->videos->map(sub {
+          my $video = $_;
+          sub {
+            $_->select('.video-name')->replace_content($video->name)
+              ->select('.video-author')->replace_content($video->author)
+              ->select('.video-link')->set_attribute(
+                  { name => 'href', value => $video->slug.'/' }
+                )
+          }
+        }))
+  });
 }
 
 method show_video ($video) {
-  $self->html_response(video => [
-    '.fill-video-name' => [
-      -replace_content => { replace_with => $video->name }
-    ],
-    '.fill-author-name' => [
-      -replace_content => { replace_with => $video->author }
-    ],
-    '.fill-bucket-link' => [
-      -set_attribute => { name => 'href', value => '../' }
-    ],
-    '.fill-bucket-name' => [
-      -replace_content => { replace_with => $video->bucket->name }
-    ],
-    '.fill-video-details' => [
-      -replace_content => { replace_with => $video->details }
-    ]
-  ]);
+  $self->html_response(video => sub {
+    $_->select('.video-name')->replace_content($video->name)
+      ->select('.author-name')->replace_content($video->author)
+      ->select('.bucket-link')->set_attribute(
+          { name => 'href', value => '../' }
+        )
+      ->select('.bucket-name')->replace_content($video->bucket->name)
+      ->select('.video-details')->replace_content($video->details)
+  });
 }
 
 method html_response ($template_name, $selectors) {
-  my $io = $self->_zoom_for($template_name => $selectors)->as_readable_fh;
+  my $io = $self->_zoom_for($template_name => $selectors)->to_fh;
   return [ 200, [ 'Content-Type' => 'text/html' ], $io ]
 }
 
@@ -161,18 +139,12 @@ method _zoom_for ($template_name, $selectors) {
     HTML::Zoom->from_file(
                   $self->_template_filename_for($template_name)
                 )
-              ->with_selectors(
-                  '#main-content' => [
-                    -capture_events => { into => \@body }
-                  ]
-                )
+              ->select('#main-content')->collect_content({ into => \@body })
               ->run;
-    $self->_layout_zoom->with_selectors(
-      '#main-content' => [
-        -replace_content_events => { replace_with => \@body }
-      ]
-    )->to_zoom;
-  })->with_selectors($selectors)
+    $self->_layout_zoom
+         ->select('#main-content')->replace_content(\@body)
+         ->memoize;
+  })->apply($selectors);
 }
 
 1;
index 9609d88..9a0b96a 100644 (file)
@@ -1,10 +1,10 @@
 <html>
 <body>
   <div id="main-content">
-    <h4 class="fill-bucket-name">THIS IZ MAI BUKKIT</h4>
+    <h4 class="bucket-name">THIS IZ MAI BUKKIT</h4>
     <ul id="video-list">
       <li class="video">
-        <a class="fill-video-link fill-video-name">Really Imaginative Video Name</a>
+        <a class="video-link video-name">Really Imaginative Video Name</a>
       </li>
     </ul>
   </div>
index a2bea84..e55b38a 100644 (file)
@@ -3,13 +3,13 @@
   <div id="main-content">
     <ul id="announcement-list">
       <li class="announcement">
-        <span class="fill-made-at">29th February 2010</span>
-        <a class="fill-bucket-link">
-          <span class="fill-bucket-name">Some Random Event</span>
-          - (<span class="fill-new-videos">2</span> new of <span call="fill-total-videos">4</span> total)
+        <span class="made-at">29th February 2010</span>
+        <a class="bucket-link">
+          <span class="bucket-name">Some Random Event</span>
+          - (<span class="new-videos">2</span> new of <span call="total-videos">4</span> total)
         </a>
       </li>
-    </il>
+    </ul>
   </div>
 </body>
 </html>
index a8cd02e..2e5a30c 100644 (file)
@@ -1,17 +1,17 @@
 <html>
 <body>
   <div id="main-content">
-    <h2 class="fill-video-name">Really Imaginative Video Name</h2>
-    <h4 class="fill-author-name">Just Another Audience Hacker</h4>
-    <a class="fill-bucket-link">
+    <h2 class="video-name">Really Imaginative Video Name</h2>
+    <h4 class="author-name">Just Another Audience Hacker</h4>
+    <a class="bucket-link">
       To go back to the
-      <b class="fill-bucket-name">Some Random Event</b>
+      <b class="bucket-name">Some Random Event</b>
       group of videos, click here.
     </a>
-    <span class="fill-player">
+    <span class="player">
       The crawling horror of javascript and flash will appear here
     </span>
-    <div class="fill-video-details">
+    <div class="video-details">
       The presenter might have provided a link to their slides here. Or they might not. If their name's Matt then they probably didn't remember to upload them yet. Oh well ...
     </div>
   </div>