===================================================================
RCS file: /cvs/todotxt/Text-Todo/bin/dudelicious.pl,v
retrieving revision 1.7
retrieving revision 1.12
diff -u -r1.7 -r1.12
--- todotxt/Text-Todo/bin/dudelicious.pl 2010/04/30 07:23:32 1.7
+++ todotxt/Text-Todo/bin/dudelicious.pl 2010/05/01 21:54:56 1.12
@@ -1,14 +1,15 @@
-#!/usr/bin/env perl
+#!/usr/bin/perl
package Dudelicious;
+use 5.010;
use Data::Dumper;
use version; our $VERSION = qv('0.1.0');
BEGIN {
use FindBin;
use lib "$FindBin::Bin/../lib";
- use lib "$FindBin::Bin/mojo/lib";
+ use lib "$FindBin::Bin/../mojo/lib";
}
use Carp qw/ carp croak /;
@@ -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;
@@ -36,25 +69,29 @@
$self->render( files => \@files, layout => 'todotxt' );
} => 'index';
+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);
@@ -64,34 +101,23 @@
}
} => 'entry';
-app->start unless caller();
+get '/l/:file/t' => sub {
+ my $self = shift;
-sub _todo {
- my ($c) = @_;
+ my $format = $self->stash('format') || 'html';
+ my $tags = $self->helper('todo')->known_tags;
- if ( !$c->stash('todo') ) {
- my $todo = Text::Todo->new( $c->stash('config') );
- $c->stash( 'todo' => $todo );
+ if ( $format eq 'json' ) {
+ $self->render_json($tags);
}
+ else {
+ $self->render( tags => $tags, layout => 'todotxt' );
+ }
+} => 'tags';
- return $c->stash('todo');
-}
+app->start if !caller();
-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),
- )
- ];
-}
-
+1;
__DATA__
@@ list.txt.ep
@@ -102,6 +128,11 @@
@@ entry.txt.ep
<%= $entry->{text} %>
+@@ tags.txt.ep
+% foreach my $tag (keys%{ $tags }) {
+<%= $tag %>, <%= $tags->{$tag} %>
+% }
+
@@ layouts/todotxt.txt.ep
%= content
@@ -123,12 +154,32 @@
@@ entry.html.ep
<%= $entry->{text} %>
+@@ tags.html.ep
+% foreach my $tag (keys%{ $tags }) {
+<%= $tag %> == <%= $tags->{$tag} %>
+% }
+
+
@@ layouts/todotxt.html.ep
-