[Catalyst-commits] r12410 - in trunk/examples/CatalystAdvent: . lib/CatalystAdvent/Controller root

t0m at dev.catalyst.perl.org t0m at dev.catalyst.perl.org
Wed Dec 16 22:35:59 GMT 2009


Author: t0m
Date: 2009-12-16 22:35:59 +0000 (Wed, 16 Dec 2009)
New Revision: 12410

Modified:
   trunk/examples/CatalystAdvent/Makefile.PL
   trunk/examples/CatalystAdvent/lib/CatalystAdvent/Controller/Calendar.pm
   trunk/examples/CatalystAdvent/root/year.tt
Log:
Let is never speak of this again

Modified: trunk/examples/CatalystAdvent/Makefile.PL
===================================================================
--- trunk/examples/CatalystAdvent/Makefile.PL	2009-12-16 21:04:25 UTC (rev 12409)
+++ trunk/examples/CatalystAdvent/Makefile.PL	2009-12-16 22:35:59 UTC (rev 12410)
@@ -20,6 +20,7 @@
 requires 'XML::Atom::SimpleFeed';
 requires 'HTTP::Date';
 requires 'List::Util';
+requires 'Template::Plugin::DateTime'; # EWWWWW
 
 test_requires 'Test::More' => '0.88';
 

Modified: trunk/examples/CatalystAdvent/lib/CatalystAdvent/Controller/Calendar.pm
===================================================================
--- trunk/examples/CatalystAdvent/lib/CatalystAdvent/Controller/Calendar.pm	2009-12-16 21:04:25 UTC (rev 12409)
+++ trunk/examples/CatalystAdvent/lib/CatalystAdvent/Controller/Calendar.pm	2009-12-16 22:35:59 UTC (rev 12410)
@@ -92,6 +92,12 @@
     $c->detach( '/calendar/index' ) unless $day =~ /^\d{1,2}$/;
 
     my $year = $c->stash->{year};
+
+    # Don't show articles before the appropriate day, even if they're ready
+    if (!$c->debug && $year == $c->stash->{now}->year) {
+        $c->detach( 'year', [$year] ) unless ($day <= $c->stash->{now}->day);
+    }
+
     $c->detach( 'year', [$year] )
         unless ( -e ( my $file = $c->path_to( 'root', $year, "$day.pod" ) ) );
 

Modified: trunk/examples/CatalystAdvent/root/year.tt
===================================================================
--- trunk/examples/CatalystAdvent/root/year.tt	2009-12-16 21:04:25 UTC (rev 12409)
+++ trunk/examples/CatalystAdvent/root/year.tt	2009-12-16 22:35:59 UTC (rev 12410)
@@ -10,6 +10,9 @@
     <th>Friday</th>
     <th>Saturday</th>
 </tr>
+[%# Just to make this totally clear, this template is hatefule, and is an example of what not to do, ever
+    We embed all the datetime handling logic in here, whereas it should be in a model object which is passed into the template.
+%]
 [% USE date %]
 [% calc = date.calc %]
 [% FOR week = calendar %]
@@ -23,8 +26,10 @@
 [% today = 1 UNLESS calc.Delta_Days( now.year, now.month, now.day, year, 12, day ) %]
         [% TRY %]
             [% USE File( c.path_to( 'root', year, "${day}.pod" ) ) %]
+			[% USE date = DateTime(year = year, month = 12, day = day) %]
+			[% IF c.stash.now < date; THROW too.early; END; %]
     <td class="link[% IF today %] today[% END %]"><a href="[% c.uri_for( '/', year, day ) %]">[% day %]</a></td>
-        [% CATCH File %]
+        [% CATCH %]
     <td[% IF today %] class="today"[% END %]>[% day  %]</td>
         [% END %]
     [% END %]




More information about the Catalyst-commits mailing list