[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.13

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 }) {
                    163: <%== $file %> <br />
                    164: % }
                    165:
                    166: @@ list.html.ep
                    167: <h1><%= $file %></h1>
                    168: <ol>
1.6       andrew    169: % foreach my $entry (@{ $list }) {
1.5       andrew    170:     <li>
1.6       andrew    171: %=  include 'entry', entry => $entry;
1.5       andrew    172:     </li>
                    173: % }
                    174: </ol>
1.1       andrew    175:
1.5       andrew    176: @@ entry.html.ep
1.6       andrew    177: <%= $entry->{text} %>
1.5       andrew    178:
1.12      andrew    179: @@ tags.html.ep
                    180: % foreach my $tag (keys%{ $tags }) {
                    181: <%= $tag %> == <%= $tags->{$tag} %><br />
                    182: % }
                    183:
1.13    ! andrew    184: @@ tag.html.ep
        !           185: <h2><%= $tag %></h2>
        !           186: % foreach my $item (@{ $items }) {
        !           187: <%= $item %><br />
        !           188: % }
1.12      andrew    189:
1.5       andrew    190: @@ layouts/todotxt.html.ep
1.1       andrew    191: <!doctype html><html>
1.9       andrew    192:     <head>
                    193:         <title>Funky!</title>
                    194:         <link rel="stylesheet" href="<%= url_for 'todotxt', format => 'css' %>">
                    195:     </head>
1.1       andrew    196:     <body><%== content %></body>
                    197: </html>
1.4       andrew    198:
1.9       andrew    199: @@ todotxt.css.ep
                    200: body {
                    201:         background: LightGoldenRodYellow;
                    202:         color: DarkSlateBlue;
                    203: }
                    204:
                    205: .inplaceeditor-saving {
                    206:         background: url(images/saving.gif) bottom right no-repeat;
                    207: }
                    208:
                    209:
1.4       andrew    210: __END__
                    211:
                    212: =head1 NAME
                    213:
                    214: dudelicious - A Mojolicous interface to your todotxt files
                    215:
                    216: =head1 VERSION
                    217:
                    218: Since the $VERSION can't be automatically included,
                    219: here is the RCS Id instead, you'll have to look up $VERSION.
                    220:
1.13    ! andrew    221:     $Id: dudelicious.pl,v 1.12 2010/05/01 20:54:56 andrew Exp $
1.4       andrew    222:
                    223: =head1 SYNOPSIS
                    224:
                    225:     dudelicious daemon
                    226:
                    227: Then browse to http://localhost:3000/
                    228:
                    229: =head1 DESCRIPTION
                    230:
                    231: A Mojolicous web app for access to your todotxt files
                    232:
                    233: The modules are there to give more access to my todo.txt file from more
                    234: places.  My goal is a web API for a web interface and then a WebOS version for
                    235: my Palm Pre.
                    236:
                    237: For more information see L<http://todotxt.com>
                    238:
                    239: =head1 USAGE
                    240:
                    241: See todo.pl -h
                    242:
                    243: =head1 OPTIONS
                    244:
                    245: See todo.pl -h
                    246:
                    247: =head1 REQUIRED ARGUMENTS
                    248:
                    249: See todo.pl -h
                    250:
                    251: =head1 CONFIGURATION AND ENVIRONMENT
                    252:
                    253: =head1 DIAGNOSTICS
                    254:
                    255: =head1 DEPENDENCIES
                    256:
                    257: Perl Modules:
                    258:
                    259: =over
                    260:
                    261: =item Text::Todo
                    262:
                    263: =item Mojolicous::Lite
                    264:
                    265: =item version
                    266:
                    267: =back
                    268:
                    269:
                    270: =head1 BUGS AND LIMITATIONS
                    271:
                    272: No bugs have been reported.
                    273:
                    274: =head1 AUTHOR
                    275:
                    276: Andrew Fresh  C<< <andrew@cpan.org> >>
                    277:
                    278:
                    279: =head1 LICENSE AND COPYRIGHT
                    280:
                    281: Copyright (c) 2010, Andrew Fresh C<< <andrew@cpan.org> >>. All rights reserved.
                    282:
                    283: This module is free software; you can redistribute it and/or
                    284: modify it under the same terms as Perl itself. See L<perlartistic>.
                    285:
                    286:
                    287: =head1 DISCLAIMER OF WARRANTY
                    288:
                    289: BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
                    290: FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
                    291: OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
                    292: PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
                    293: EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
                    294: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
                    295: ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
                    296: YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
                    297: NECESSARY SERVICING, REPAIR, OR CORRECTION.
                    298:
                    299: IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
                    300: WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
                    301: REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
                    302: LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
                    303: OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
                    304: THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
                    305: RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
                    306: FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
                    307: SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
                    308: SUCH DAMAGES.

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