===================================================================
RCS file: /cvs/todotxt/Text-Todo/bin/dudelicious.pl,v
retrieving revision 1.11
retrieving revision 1.16
diff -u -r1.11 -r1.16
--- todotxt/Text-Todo/bin/dudelicious.pl 2010/05/01 21:26:17 1.11
+++ todotxt/Text-Todo/bin/dudelicious.pl 2010/05/05 03:01:08 1.16
@@ -28,17 +28,23 @@
app->renderer->add_helper(
todo => sub {
- state $todo = Text::Todo->new( shift->stash('config') );
+ 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, $file ) = @_;
+ my ($self) = @_;
- $self->helper('todo')->load($file) if $file;
-
my $line = 1;
return [
map {
@@ -66,25 +72,27 @@
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 = $self->helper( 'get_list' => $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'),
+ tags => $self->helper('todo')->known_tags,
+ 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
- = $self->helper( 'get_list' => $file )->[ $self->stash('line') - 1 ];
+ my $entry = $self->helper('get_list')->[ $self->stash('line') - 1 ];
if ( $format eq 'json' ) {
$self->render_json($entry);
@@ -94,8 +102,39 @@
}
} => 'entry';
+get '/l/:file/t' => sub {
+ my $self = shift;
+
+ my $format = $self->stash('format') || 'html';
+
+ if ( $format eq 'json' ) {
+ $self->render_json( $self->helper('todo')->known_tags );
+ }
+ else {
+ $self->render(
+ tags => $self->helper('todo')->known_tags,
+ layout => 'todotxt'
+ );
+ }
+} => 'tags';
+
+get '/l/:file/t/:tag' => sub {
+ my $self = shift;
+
+ my $format = $self->stash('format') || 'html';
+ my $items = $self->helper('todo')->listtag( $self->stash('tag') );
+
+ 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
@@ -106,16 +145,34 @@
@@ 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
@@ index.html.ep
% foreach my $file (@{ $files }) {
-<%== $file %>
+% my ($basename) = $file =~ /^(.*?)(?:\.[^\.]+)?$/xms;
+<%= $file %>
% }
@@ list.html.ep