[BACK]Return to dudelicious.pl CVS log [TXT][DIR] Up to [local] / todotxt / Text-Todo / bin

Diff for /todotxt/Text-Todo/bin/dudelicious.pl between version 1.8 and 1.11

version 1.8, 2010/04/30 18:17:40 version 1.11, 2010/05/01 21:26:17
Line 2 
Line 2 
   
 package Dudelicious;  package Dudelicious;
   
   use 5.010;
 use Data::Dumper;  use Data::Dumper;
 use version; our $VERSION = qv('0.1.0');  use version; our $VERSION = qv('0.1.0');
   
Line 25 
Line 26 
     default => { todo_dir => $ENV{DUDELICIOUS_HOME} || '.', },      default => { todo_dir => $ENV{DUDELICIOUS_HOME} || '.', },
 };  };
   
   app->renderer->add_helper(
       todo => sub {
           state $todo = Text::Todo->new( shift->stash('config') );
           return $todo;
       }
   );
   
   app->renderer->add_helper(
       get_list => sub {
           my ( $self, $file ) = @_;
   
           $self->helper('todo')->load($file) if $file;
   
           my $line = 1;
           return [
               map {
                   line     => $line++,
                       md5  => md5_hex( $_->text ),
                       text => $_->text,
                       done => $_->done,
               },
               $self->helper('todo')->list
           ];
       }
   );
   
 get '/' => sub {  get '/' => sub {
     my $self = shift;      my $self = shift;
   
     my $dir = _todo($self)->file('todo_dir');      my $dir = $self->helper('todo')->file('todo_dir');
     opendir my $dh, $dir or croak "Unable to opendir $dir: $!";      opendir my $dh, $dir or croak "Unable to opendir $dir: $!";
     my @files = grep {/\.te?xt$/ixms} readdir $dh;      my @files = grep {/\.te?xt$/ixms} readdir $dh;
     closedir $dh;      closedir $dh;
Line 36 
Line 63 
     $self->render( files => \@files, layout => 'todotxt' );      $self->render( files => \@files, layout => 'todotxt' );
 } => 'index';  } => 'index';
   
   get '/todotxt' => 'todotxt';
   
 get '/l/:file' => sub {  get '/l/:file' => sub {
     my $self   = shift;      my $self   = shift;
     my $file   = $self->stash('file') . '.txt';      my $file   = $self->stash('file') . '.txt';
     my $format = $self->stash('format') || 'html';      my $format = $self->stash('format') || 'html';
     my $list   = _get_list( $self, $file );      my $list   = $self->helper( 'get_list' => $file );
   
     if ( $format eq 'json' ) {      if ( $format eq 'json' ) {
         $self->render_json($list);          $self->render_json($list);
Line 54 
Line 83 
     my $self   = shift;      my $self   = shift;
     my $file   = $self->stash('file') . '.txt';      my $file   = $self->stash('file') . '.txt';
     my $format = $self->stash('format') || 'html';      my $format = $self->stash('format') || 'html';
     my $entry  = _get_list( $self, $file )->[ $self->stash('line') - 1 ];      my $entry
           = $self->helper( 'get_list' => $file )->[ $self->stash('line') - 1 ];
   
     if ( $format eq 'json' ) {      if ( $format eq 'json' ) {
         $self->render_json($entry);          $self->render_json($entry);
Line 64 
Line 94 
     }      }
 } => 'entry';  } => 'entry';
   
 app->start unless caller();  app->start if !caller();
   
 sub _todo {  
     my ($c) = @_;  
   
     if ( !$c->stash('todo') ) {  
         my $todo = Text::Todo->new( $c->stash('config') );  
         $c->stash( 'todo' => $todo );  
     }  
   
     return $c->stash('todo');  
 }  
   
 sub _get_list {  
     my ( $c, $file ) = @_;  
   
     my $line = 1;  
     return [  
         map ( { line => $line++,  
                 md5  => md5_hex( $_->text ),  
                 text => $_->text,  
                 done => $_->done,  
             },  
             _todo($c)->listfile($file),  
         )  
     ];  
 }  
   
 __DATA__  __DATA__
   
 @@ list.txt.ep  @@ list.txt.ep
Line 125 
Line 129 
   
 @@ layouts/todotxt.html.ep  @@ layouts/todotxt.html.ep
 <!doctype html><html>  <!doctype html><html>
     <head><title>Funky!</title></head>      <head>
           <title>Funky!</title>
           <link rel="stylesheet" href="<%= url_for 'todotxt', format => 'css' %>">
       </head>
     <body><%== content %></body>      <body><%== content %></body>
 </html>  </html>
   
   @@ todotxt.css.ep
   body {
           background: LightGoldenRodYellow;
           color: DarkSlateBlue;
   }
   
   .inplaceeditor-saving {
           background: url(images/saving.gif) bottom right no-repeat;
   }
   
   
 __END__  __END__
   

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.11

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>