[Catalyst-commits] r14110 - in trunk/examples/CatalystAdvent: . lib lib/CatalystAdvent/Controller root root/static/css

dpetrov at dev.catalyst.perl.org dpetrov at dev.catalyst.perl.org
Tue Sep 27 12:40:35 GMT 2011


Author: dpetrov
Date: 2011-09-27 12:40:35 +0000 (Tue, 27 Sep 2011)
New Revision: 14110

Modified:
   trunk/examples/CatalystAdvent/Changes
   trunk/examples/CatalystAdvent/lib/CatalystAdvent.pm
   trunk/examples/CatalystAdvent/lib/CatalystAdvent/Controller/Calendar.pm
   trunk/examples/CatalystAdvent/root/static/css/screen.css
   trunk/examples/CatalystAdvent/root/year.tt
Log:
Display article list with names underneath the calendar on the per-year page

Modified: trunk/examples/CatalystAdvent/Changes
===================================================================
--- trunk/examples/CatalystAdvent/Changes	2011-09-27 11:56:34 UTC (rev 14109)
+++ trunk/examples/CatalystAdvent/Changes	2011-09-27 12:40:35 UTC (rev 14110)
@@ -1,5 +1,9 @@
 This file documents the revision history for Perl extension CatalystAdvent.
 
+0.04
+        - Display article list with names underneath the calendar on the
+          per-year page 
+
 0.03
         - By default, display the most recent year for which we have
           entries

Modified: trunk/examples/CatalystAdvent/lib/CatalystAdvent/Controller/Calendar.pm
===================================================================
--- trunk/examples/CatalystAdvent/lib/CatalystAdvent/Controller/Calendar.pm	2011-09-27 11:56:34 UTC (rev 14109)
+++ trunk/examples/CatalystAdvent/lib/CatalystAdvent/Controller/Calendar.pm	2011-09-27 12:40:35 UTC (rev 14110)
@@ -48,10 +48,10 @@
     closedir DIR;
 
     my $year = pop @years || $c->stash->{now}->year;
-#    $c->go( $self->action_for('year'), [$year], []);
-    $c->stash->{year}     = $year;
-    $c->stash->{calendar} = calendar( 12, $year );
-    $c->stash->{template} = 'year.tt';
+    $c->go( $self->action_for('year'), [$year], []);
+#    $c->stash->{year}     = $year;
+#    $c->stash->{calendar} = calendar( 12, $year );
+#    $c->stash->{template} = 'year.tt';
 
 }
 
@@ -71,6 +71,35 @@
 
     $c->stash->{year}     = $year;
     $c->stash->{calendar} = calendar( 12, $year );
+
+    opendir my $DIR, $c->path_to('root', $year) or die "Error opening root: $!";
+    my @days = sort { $a <=> $b }
+               map  { m/(\d+)\.pod/ }
+               grep { /(\d+)\.pod/ && $1 <= $c->stash->{now}->day } 
+               readdir $DIR;
+    closedir $DIR;
+    
+    my @links;
+    foreach my $day (@days) {
+        my $file = $c->path_to( 'root', $year )->file( "$day.pod" );
+
+        my $mtime        = ( stat $file )->mtime;
+        my $cached_title = $c->cache->get("title $file $mtime");
+        if ( !$cached_title ) {
+            my $parser = CatalystAdvent::Pod->new();
+
+            open my $fh, '<:utf8', $file or die "Failed to open $file: $!";
+            $parser->parse_from_filehandle($fh);
+            close $fh;
+            
+            $cached_title = $parser->title || '(no title)';
+            $c->cache->set( "title $file $mtime", $cached_title, '12h' );
+        }
+
+        push @links, { day => $day, title => $cached_title };
+    }
+
+    $c->stash->{links} = \@links;
 }
 
 =head2 year

Modified: trunk/examples/CatalystAdvent/lib/CatalystAdvent.pm
===================================================================
--- trunk/examples/CatalystAdvent/lib/CatalystAdvent.pm	2011-09-27 11:56:34 UTC (rev 14109)
+++ trunk/examples/CatalystAdvent/lib/CatalystAdvent.pm	2011-09-27 12:40:35 UTC (rev 14110)
@@ -8,7 +8,7 @@
                  Unicode
               );
 
-our $VERSION = '0.03';
+our $VERSION = '0.04';
 
 __PACKAGE__->config(
   name => 'CatalystAdvent',

Modified: trunk/examples/CatalystAdvent/root/static/css/screen.css
===================================================================
--- trunk/examples/CatalystAdvent/root/static/css/screen.css	2011-09-27 11:56:34 UTC (rev 14109)
+++ trunk/examples/CatalystAdvent/root/static/css/screen.css	2011-09-27 12:40:35 UTC (rev 14110)
@@ -135,6 +135,16 @@
     text-align: left;
 }
 
+#links {
+    border-top: 1px solid #ddd;
+    clear: both;
+}
+
+#links h2 {
+    margin-top: 0.5em;
+    text-align: left;
+}
+
 .rss {
     font-size: x-small;
     text-align: right;
@@ -175,4 +185,4 @@
         color: black !important;
         border: 0 !important;
     }
-}
\ No newline at end of file
+}

Modified: trunk/examples/CatalystAdvent/root/year.tt
===================================================================
--- trunk/examples/CatalystAdvent/root/year.tt	2011-09-27 11:56:34 UTC (rev 14109)
+++ trunk/examples/CatalystAdvent/root/year.tt	2011-09-27 12:40:35 UTC (rev 14110)
@@ -36,6 +36,14 @@
 </tr>
 [% END %]
 </table>
+[% IF c.stash.links.size > 0 %]
+<div id="links">
+    <h2>Articles</h2>
+    [% FOREACH link IN c.stash.links %]
+    <p>Day [% link.day %]: <a href="[% c.uri_for('/', year, link.day) %]">[% link.title %]</a></p>
+    [% END %]
+</div>
+[% END %]
 [% TRY %]
 <div id="notes">
     [% INCLUDE "notes/${year}.tt" %]




More information about the Catalyst-commits mailing list