=================================================================== RCS file: /cvs/todotxt/Text-Todo/bin/dudelicious.pl,v retrieving revision 1.8 retrieving revision 1.10 diff -u -r1.8 -r1.10 --- todotxt/Text-Todo/bin/dudelicious.pl 2010/04/30 18:17:40 1.8 +++ todotxt/Text-Todo/bin/dudelicious.pl 2010/05/01 21:23:19 1.10 @@ -2,6 +2,7 @@ package Dudelicious; +use 5.010; use Data::Dumper; use version; our $VERSION = qv('0.1.0'); @@ -25,10 +26,36 @@ 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 { 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: $!"; my @files = grep {/\.te?xt$/ixms} readdir $dh; closedir $dh; @@ -36,11 +63,13 @@ $self->render( files => \@files, layout => 'todotxt' ); } => 'index'; +get '/todotxt' => 'todotxt'; + 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 ); + my $list = $self->helper( 'get_list' => $file ); if ( $format eq 'json' ) { $self->render_json($list); @@ -54,7 +83,8 @@ 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 ]; + my $entry + = $self->helper( 'get_list' => $file )->[ $self->stash('line') - 1 ]; if ( $format eq 'json' ) { $self->render_json($entry); @@ -66,32 +96,6 @@ 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__ @@ list.txt.ep @@ -125,10 +129,24 @@ @@ layouts/todotxt.html.ep - Funky! + + Funky! + + <%== content %> +@@ todotxt.css.ep +body { + background: LightGoldenRodYellow; + color: DarkSlateBlue; +} + +.inplaceeditor-saving { + background: url(images/saving.gif) bottom right no-repeat; +} + + __END__ =head1 NAME @@ -140,7 +158,7 @@ Since the $VERSION can't be automatically included, here is the RCS Id instead, you'll have to look up $VERSION. - $Id: dudelicious.pl,v 1.8 2010/04/30 17:17:40 andrew Exp $ + $Id: dudelicious.pl,v 1.10 2010/05/01 20:23:19 andrew Exp $ =head1 SYNOPSIS