[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.4 and 1.8

version 1.4, 2010/04/28 01:50:47 version 1.8, 2010/04/30 18:17:40
Line 1 
Line 1 
 #!/usr/bin/env perl  #!/usr/bin/perl
   
 package Dudelicious;  package Dudelicious;
   
   use Data::Dumper;
 use version; our $VERSION = qv('0.1.0');  use version; our $VERSION = qv('0.1.0');
   
 BEGIN { use FindBin; use lib "$FindBin::Bin/mojo/lib" }  BEGIN {
       use FindBin;
       use lib "$FindBin::Bin/../lib";
       use lib "$FindBin::Bin/../mojo/lib";
   }
   
   use Carp qw/ carp croak /;
   use Digest::MD5 qw/ md5_hex /;
   use Text::Todo;
   
 use Mojolicious::Lite;  use Mojolicious::Lite;
   use Mojo::JSON;
   
 get '/' => 'index';  app->home->parse( $ENV{DUDELICIOUS_HOME} ) if $ENV{DUDELICIOUS_HOME};
   
 get '/:groovy' => sub {  plugin 'json_config' => {
     my $self = shift;      file    => 'dudelicious.conf',
     $self->render_text($self->param('groovy'), layout => 'funky');      default => { todo_dir => $ENV{DUDELICIOUS_HOME} || '.', },
 };  };
   
   get '/' => sub {
       my $self = shift;
   
       my $dir = _todo($self)->file('todo_dir');
       opendir my $dh, $dir or croak "Unable to opendir $dir: $!";
       my @files = grep {/\.te?xt$/ixms} readdir $dh;
       closedir $dh;
   
       $self->render( files => \@files, layout => 'todotxt' );
   } => 'index';
   
   get '/l/:file' => sub {
       my $self   = shift;
       my $file   = $self->stash('file') . '.txt';
       my $format = $self->stash('format') || 'html';
       my $list   = _get_list( $self, $file );
   
       if ( $format eq 'json' ) {
           $self->render_json($list);
       }
       else {
           $self->render( list => $list, layout => 'todotxt' );
       }
   } => 'list';
   
   get '/l/:file/e/:line' => sub {
       my $self   = shift;
       my $file   = $self->stash('file') . '.txt';
       my $format = $self->stash('format') || 'html';
       my $entry  = _get_list( $self, $file )->[ $self->stash('line') - 1 ];
   
       if ( $format eq 'json' ) {
           $self->render_json($entry);
       }
       else {
           $self->render( entry => $entry, layout => 'todotxt' );
       }
   } => 'entry';
   
 app->start unless caller();  app->start unless 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
   % foreach my $entry (@{ $list }) {
   %==  include 'entry', entry => $entry;
   % }
   
   @@ entry.txt.ep
   <%= $entry->{text} %>
   
   @@ layouts/todotxt.txt.ep
   %= content
   
 @@ index.html.ep  @@ index.html.ep
 % layout 'funky';  % foreach my $file (@{ $files }) {
 Yea baby!  <%== $file %> <br />
   % }
   
 @@ layouts/funky.html.ep  @@ list.html.ep
   <h1><%= $file %></h1>
   <ol>
   % foreach my $entry (@{ $list }) {
       <li>
   %=  include 'entry', entry => $entry;
       </li>
   % }
   </ol>
   
   @@ entry.html.ep
   <%= $entry->{text} %>
   
   @@ layouts/todotxt.html.ep
 <!doctype html><html>  <!doctype html><html>
     <head><title>Funky!</title></head>      <head><title>Funky!</title></head>
     <body><%== content %></body>      <body><%== content %></body>

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

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