[BACK]Return to dudelicious.pl CVS log [TXT][DIR] Up to [local] / todotxt / Text-Todo / bin

Annotation of todotxt/Text-Todo/bin/dudelicious.pl, Revision 1.14

1.8       andrew      1: #!/usr/bin/perl
1.1       andrew      2:
1.2       andrew      3: package Dudelicious;
                      4:
1.10      andrew      5: use 5.010;
1.6       andrew      6: use Data::Dumper;
1.4       andrew      7: use version; our $VERSION = qv('0.1.0');
                      8:
1.6       andrew      9: BEGIN {
                     10:     use FindBin;
                     11:     use lib "$FindBin::Bin/../lib";
1.8       andrew     12:     use lib "$FindBin::Bin/../mojo/lib";
1.6       andrew     13: }
1.2       andrew     14:
1.5       andrew     15: use Carp qw/ carp croak /;
1.6       andrew     16: use Digest::MD5 qw/ md5_hex /;
                     17: use Text::Todo;
1.5       andrew     18:
1.1       andrew     19: use Mojolicious::Lite;
1.6       andrew     20: use Mojo::JSON;
1.5       andrew     21:
                     22: app->home->parse( $ENV{DUDELICIOUS_HOME} ) if $ENV{DUDELICIOUS_HOME};
1.1       andrew     23:
1.6       andrew     24: plugin 'json_config' => {
                     25:     file    => 'dudelicious.conf',
                     26:     default => { todo_dir => $ENV{DUDELICIOUS_HOME} || '.', },
                     27: };
1.1       andrew     28:
1.10      andrew     29: app->renderer->add_helper(
                     30:     todo => sub {
1.12      andrew     31:         my ($self) = @_;
                     32:         state $todo = Text::Todo->new( $self->stash('config') );
                     33:
                     34:         my $file = $self->stash('file');
                     35:         if ($file) {
                     36:             $file =~ s/(?:\.txt)?$/\.txt/ixms;
                     37:             $todo->load($file);
                     38:         }
                     39:
1.10      andrew     40:         return $todo;
                     41:     }
                     42: );
                     43:
                     44: app->renderer->add_helper(
                     45:     get_list => sub {
1.12      andrew     46:         my ($self) = @_;
1.10      andrew     47:
                     48:         my $line = 1;
                     49:         return [
                     50:             map {
1.11      andrew     51:                 line     => $line++,
                     52:                     md5  => md5_hex( $_->text ),
                     53:                     text => $_->text,
                     54:                     done => $_->done,
1.10      andrew     55:             },
                     56:             $self->helper('todo')->list
                     57:         ];
                     58:     }
                     59: );
                     60:
1.5       andrew     61: get '/' => sub {
1.1       andrew     62:     my $self = shift;
1.5       andrew     63:
1.10      andrew     64:     my $dir = $self->helper('todo')->file('todo_dir');
1.5       andrew     65:     opendir my $dh, $dir or croak "Unable to opendir $dir: $!";
                     66:     my @files = grep {/\.te?xt$/ixms} readdir $dh;
                     67:     closedir $dh;
                     68:
                     69:     $self->render( files => \@files, layout => 'todotxt' );
                     70: } => 'index';
                     71:
1.9       andrew     72: get '/todotxt' => 'todotxt';
                     73:
1.5       andrew     74: get '/l/:file' => sub {
1.12      andrew     75:     my $self = shift;
                     76:
1.6       andrew     77:     my $format = $self->stash('format') || 'html';
1.5       andrew     78:
1.6       andrew     79:     if ( $format eq 'json' ) {
1.12      andrew     80:         $self->render_json( $self->helper('get_list') );
1.6       andrew     81:     }
                     82:     else {
1.12      andrew     83:         $self->render(
                     84:             list   => $self->helper('get_list'),
                     85:             layout => 'todotxt'
                     86:         );
1.6       andrew     87:     }
1.5       andrew     88: } => 'list';
                     89:
1.6       andrew     90: get '/l/:file/e/:line' => sub {
1.12      andrew     91:     my $self = shift;
                     92:
1.6       andrew     93:     my $format = $self->stash('format') || 'html';
1.12      andrew     94:     my $entry = $self->helper('get_list')->[ $self->stash('line') - 1 ];
1.6       andrew     95:
                     96:     if ( $format eq 'json' ) {
1.7       andrew     97:         $self->render_json($entry);
1.6       andrew     98:     }
                     99:     else {
1.7       andrew    100:         $self->render( entry => $entry, layout => 'todotxt' );
1.6       andrew    101:     }
1.5       andrew    102: } => 'entry';
1.1       andrew    103:
1.12      andrew    104: get '/l/:file/t' => sub {
                    105:     my $self = shift;
                    106:
                    107:     my $format = $self->stash('format') || 'html';
                    108:
                    109:     if ( $format eq 'json' ) {
1.13      andrew    110:         $self->render_json( $self->helper('todo')->known_tags );
1.12      andrew    111:     }
                    112:     else {
1.13      andrew    113:         $self->render(
                    114:             tags   => $self->helper('todo')->known_tags,
                    115:             layout => 'todotxt'
                    116:         );
1.12      andrew    117:     }
                    118: } => 'tags';
                    119:
1.13      andrew    120: get '/l/:file/t/:tag' => sub {
                    121:     my $self = shift;
                    122:
                    123:     my $format = $self->stash('format') || 'html';
                    124:     my $items  = $self->helper('todo')->listtag( $self->stash('tag') );
                    125:
                    126:     if ( $format eq 'json' ) {
                    127:         $self->render_json($items);
                    128:     }
                    129:     else {
                    130:         $self->render( items => $items, layout => 'todotxt' );
                    131:     }
                    132: } => 'tag';
                    133:
1.11      andrew    134: app->start if !caller();
1.5       andrew    135:
1.12      andrew    136: 1;
1.1       andrew    137: __DATA__
                    138:
1.5       andrew    139: @@ list.txt.ep
1.6       andrew    140: % foreach my $entry (@{ $list }) {
                    141: %==  include 'entry', entry => $entry;
1.5       andrew    142: % }
                    143:
                    144: @@ entry.txt.ep
1.6       andrew    145: <%= $entry->{text} %>
1.5       andrew    146:
1.12      andrew    147: @@ tags.txt.ep
1.13      andrew    148: % foreach my $tag (keys %{ $tags }) {
1.12      andrew    149: <%= $tag %>, <%= $tags->{$tag} %>
                    150: % }
                    151:
1.13      andrew    152: @@ tag.txt.ep
                    153: # <%= $tag %>
                    154: % foreach my $item (@{ $items}) {
                    155: <%= $item %>
                    156: % }
                    157:
1.5       andrew    158: @@ layouts/todotxt.txt.ep
                    159: %= content
                    160:
1.1       andrew    161: @@ index.html.ep
1.5       andrew    162: % foreach my $file (@{ $files }) {
1.14    ! andrew    163: % my ($basename) = $file =~ /^(.*?)(?:\.[^\.]+)?$/xms;
        !           164: <a href="<%= url_for 'list' %>/<%= $basename %>"><%= $file %></a><br />
1.5       andrew    165: % }
                    166:
                    167: @@ list.html.ep
                    168: <h1><%= $file %></h1>
                    169: <ol>
1.6       andrew    170: % foreach my $entry (@{ $list }) {
1.5       andrew    171:     <li>
1.6       andrew    172: %=  include 'entry', entry => $entry;
1.5       andrew    173:     </li>
                    174: % }
                    175: </ol>
1.1       andrew    176:
1.5       andrew    177: @@ entry.html.ep
1.6       andrew    178: <%= $entry->{text} %>
1.5       andrew    179:
1.12      andrew    180: @@ tags.html.ep
                    181: % foreach my $tag (keys%{ $tags }) {
1.14    ! andrew    182: <a href="<%= url_for 'tag', format => '' %>/<%= $tag %>"><%= $tag %> == <%= $tags->{$tag} %></a><br />
1.12      andrew    183: % }
                    184:
1.13      andrew    185: @@ tag.html.ep
                    186: <h2><%= $tag %></h2>
                    187: % foreach my $item (@{ $items }) {
                    188: <%= $item %><br />
                    189: % }
1.12      andrew    190:
1.5       andrew    191: @@ layouts/todotxt.html.ep
1.1       andrew    192: <!doctype html><html>
1.9       andrew    193:     <head>
                    194:         <title>Funky!</title>
                    195:         <link rel="stylesheet" href="<%= url_for 'todotxt', format => 'css' %>">
                    196:     </head>
1.1       andrew    197:     <body><%== content %></body>
                    198: </html>
1.4       andrew    199:
1.9       andrew    200: @@ todotxt.css.ep
                    201: body {
                    202:         background: LightGoldenRodYellow;
                    203:         color: DarkSlateBlue;
                    204: }
                    205:
                    206: .inplaceeditor-saving {
                    207:         background: url(images/saving.gif) bottom right no-repeat;
                    208: }
                    209:
                    210:
1.4       andrew    211: __END__
                    212:
                    213: =head1 NAME
                    214:
                    215: dudelicious - A Mojolicous interface to your todotxt files
                    216:
                    217: =head1 VERSION
                    218:
                    219: Since the $VERSION can't be automatically included,
                    220: here is the RCS Id instead, you'll have to look up $VERSION.
                    221:
1.14    ! andrew    222:     $Id: dudelicious.pl,v 1.13 2010/05/01 21:11:58 andrew Exp $
1.4       andrew    223:
                    224: =head1 SYNOPSIS
                    225:
                    226:     dudelicious daemon
                    227:
                    228: Then browse to http://localhost:3000/
                    229:
                    230: =head1 DESCRIPTION
                    231:
                    232: A Mojolicous web app for access to your todotxt files
                    233:
                    234: The modules are there to give more access to my todo.txt file from more
                    235: places.  My goal is a web API for a web interface and then a WebOS version for
                    236: my Palm Pre.
                    237:
                    238: For more information see L<http://todotxt.com>
                    239:
                    240: =head1 USAGE
                    241:
                    242: See todo.pl -h
                    243:
                    244: =head1 OPTIONS
                    245:
                    246: See todo.pl -h
                    247:
                    248: =head1 REQUIRED ARGUMENTS
                    249:
                    250: See todo.pl -h
                    251:
                    252: =head1 CONFIGURATION AND ENVIRONMENT
                    253:
                    254: =head1 DIAGNOSTICS
                    255:
                    256: =head1 DEPENDENCIES
                    257:
                    258: Perl Modules:
                    259:
                    260: =over
                    261:
                    262: =item Text::Todo
                    263:
                    264: =item Mojolicous::Lite
                    265:
                    266: =item version
                    267:
                    268: =back
                    269:
                    270:
                    271: =head1 BUGS AND LIMITATIONS
                    272:
                    273: No bugs have been reported.
                    274:
                    275: =head1 AUTHOR
                    276:
                    277: Andrew Fresh  C<< <andrew@cpan.org> >>
                    278:
                    279:
                    280: =head1 LICENSE AND COPYRIGHT
                    281:
                    282: Copyright (c) 2010, Andrew Fresh C<< <andrew@cpan.org> >>. All rights reserved.
                    283:
                    284: This module is free software; you can redistribute it and/or
                    285: modify it under the same terms as Perl itself. See L<perlartistic>.
                    286:
                    287:
                    288: =head1 DISCLAIMER OF WARRANTY
                    289:
                    290: BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
                    291: FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
                    292: OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
                    293: PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
                    294: EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
                    295: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
                    296: ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
                    297: YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
                    298: NECESSARY SERVICING, REPAIR, OR CORRECTION.
                    299:
                    300: IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
                    301: WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
                    302: REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
                    303: LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
                    304: OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
                    305: THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
                    306: RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
                    307: FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
                    308: SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
                    309: SUCH DAMAGES.

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