===================================================================
RCS file: /cvs/todotxt/Text-Todo/bin/dudelicious.pl,v
retrieving revision 1.9
retrieving revision 1.13
diff -u -r1.9 -r1.13
--- todotxt/Text-Todo/bin/dudelicious.pl 2010/04/30 18:30:57 1.9
+++ todotxt/Text-Todo/bin/dudelicious.pl 2010/05/01 22:11:58 1.13
@@ -2,6 +2,7 @@
package Dudelicious;
+use 5.010;
use Data::Dumper;
use version; our $VERSION = qv('0.1.0');
@@ -25,10 +26,42 @@
default => { todo_dir => $ENV{DUDELICIOUS_HOME} || '.', },
};
+app->renderer->add_helper(
+ todo => sub {
+ my ($self) = @_;
+ state $todo = Text::Todo->new( $self->stash('config') );
+
+ my $file = $self->stash('file');
+ if ($file) {
+ $file =~ s/(?:\.txt)?$/\.txt/ixms;
+ $todo->load($file);
+ }
+
+ return $todo;
+ }
+);
+
+app->renderer->add_helper(
+ get_list => sub {
+ my ($self) = @_;
+
+ 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;
@@ -39,24 +72,26 @@
get '/todotxt' => 'todotxt';
get '/l/:file' => sub {
- my $self = shift;
- my $file = $self->stash('file') . '.txt';
+ my $self = shift;
+
my $format = $self->stash('format') || 'html';
- my $list = _get_list( $self, $file );
if ( $format eq 'json' ) {
- $self->render_json($list);
+ $self->render_json( $self->helper('get_list') );
}
else {
- $self->render( list => $list, layout => 'todotxt' );
+ $self->render(
+ list => $self->helper('get_list'),
+ layout => 'todotxt'
+ );
}
} => 'list';
get '/l/:file/e/:line' => sub {
- my $self = shift;
- my $file = $self->stash('file') . '.txt';
+ my $self = shift;
+
my $format = $self->stash('format') || 'html';
- my $entry = _get_list( $self, $file )->[ $self->stash('line') - 1 ];
+ my $entry = $self->helper('get_list')->[ $self->stash('line') - 1 ];
if ( $format eq 'json' ) {
$self->render_json($entry);
@@ -66,34 +101,39 @@
}
} => 'entry';
-app->start unless caller();
+get '/l/:file/t' => sub {
+ my $self = shift;
-sub _todo {
- my ($c) = @_;
+ my $format = $self->stash('format') || 'html';
- if ( !$c->stash('todo') ) {
- my $todo = Text::Todo->new( $c->stash('config') );
- $c->stash( 'todo' => $todo );
+ if ( $format eq 'json' ) {
+ $self->render_json( $self->helper('todo')->known_tags );
}
+ else {
+ $self->render(
+ tags => $self->helper('todo')->known_tags,
+ layout => 'todotxt'
+ );
+ }
+} => 'tags';
- return $c->stash('todo');
-}
+get '/l/:file/t/:tag' => sub {
+ my $self = shift;
-sub _get_list {
- my ( $c, $file ) = @_;
+ my $format = $self->stash('format') || 'html';
+ my $items = $self->helper('todo')->listtag( $self->stash('tag') );
- my $line = 1;
- return [
- map ( { line => $line++,
- md5 => md5_hex( $_->text ),
- text => $_->text,
- done => $_->done,
- },
- _todo($c)->listfile($file),
- )
- ];
-}
+ if ( $format eq 'json' ) {
+ $self->render_json($items);
+ }
+ else {
+ $self->render( items => $items, layout => 'todotxt' );
+ }
+} => 'tag';
+app->start if !caller();
+
+1;
__DATA__
@@ list.txt.ep
@@ -104,6 +144,17 @@
@@ entry.txt.ep
<%= $entry->{text} %>
+@@ tags.txt.ep
+% foreach my $tag (keys %{ $tags }) {
+<%= $tag %>, <%= $tags->{$tag} %>
+% }
+
+@@ tag.txt.ep
+# <%= $tag %>
+% foreach my $item (@{ $items}) {
+<%= $item %>
+% }
+
@@ layouts/todotxt.txt.ep
%= content
@@ -125,6 +176,17 @@
@@ entry.html.ep
<%= $entry->{text} %>
+@@ tags.html.ep
+% foreach my $tag (keys%{ $tags }) {
+<%= $tag %> == <%= $tags->{$tag} %>
+% }
+
+@@ tag.html.ep
+