Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 1 | package Korap; |
| 2 | use Mojo::Base 'Mojolicious'; |
| 3 | |
Nils Diewald | 44a7278 | 2014-06-20 16:03:21 +0000 | [diff] [blame] | 4 | our $VERSION = '0.03'; |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame] | 5 | |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 6 | # This method will run once at server start |
| 7 | sub startup { |
| 8 | my $self = shift; |
| 9 | |
Nils Diewald | 33e1555 | 2014-06-13 19:38:37 +0000 | [diff] [blame] | 10 | $self->secrets(['fmhsfjgfchgsdbfgshfxztsbt32477eb45veu4vubrghfgghbtv']); |
| 11 | |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 12 | $self->plugin('Config'); |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame] | 13 | $self->plugin('CHI'); |
Nils Diewald | 02df991 | 2014-06-03 16:08:07 +0000 | [diff] [blame] | 14 | $self->plugin('TagHelpers::Pagination' => { |
| 15 | prev => '<span><i class="fa fa-caret-left"></i></span>', |
| 16 | next => '<span><i class="fa fa-caret-right"></i></span>', |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame] | 17 | ellipsis => '<span><i class="fa fa-ellipsis-h"></i></span>', |
Nils Diewald | 02df991 | 2014-06-03 16:08:07 +0000 | [diff] [blame] | 18 | separator => '', |
| 19 | current => '<span>{current}</span>', |
| 20 | page => '<span>{page}</span>' |
| 21 | }); |
Nils Diewald | dd2d4e8 | 2014-05-31 17:08:33 +0000 | [diff] [blame] | 22 | $self->plugin('Notifications'); |
| 23 | $self->plugin('Number::Commify'); |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 24 | push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin'); |
| 25 | $self->plugin('KorapSearch'); |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame] | 26 | $self->plugin('KorapInfo'); |
| 27 | $self->plugin('KorapTagHelpers'); |
| 28 | |
| 29 | $self->helper( |
| 30 | date_format => sub { |
| 31 | my ($c, $date) = @_; |
| 32 | return $date; |
| 33 | } |
| 34 | ); |
| 35 | |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame] | 36 | # Routes |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 37 | my $r = $self->routes; |
| 38 | |
Nils Diewald | dd2d4e8 | 2014-05-31 17:08:33 +0000 | [diff] [blame] | 39 | # Create search endpoint |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 40 | $r->add_shortcut( |
| 41 | search => sub { |
Nils Diewald | 33e1555 | 2014-06-13 19:38:37 +0000 | [diff] [blame] | 42 | shift->route('/search')->to('search#remote') |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 43 | } |
| 44 | ); |
| 45 | |
Nils Diewald | b22abdf | 2014-06-18 22:57:50 +0000 | [diff] [blame] | 46 | $r->get('/')->to('search#remote')->name('index'); |
Nils Diewald | 33e1555 | 2014-06-13 19:38:37 +0000 | [diff] [blame] | 47 | $r->get('/util/query')->to('search#query'); |
| 48 | |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame] | 49 | # Tutorial |
Nils Diewald | b22abdf | 2014-06-18 22:57:50 +0000 | [diff] [blame] | 50 | $r->get('/tutorial/(*tutorial)', { tutorial => 'start' })->to('tutorial#page')->name('tutorial'); |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame] | 51 | |
Nils Diewald | 1eba657 | 2014-06-17 19:49:53 +0000 | [diff] [blame] | 52 | my $collection = $r->route('/collection'); |
| 53 | $collection->to('search#info'); |
| 54 | $collection->search; |
| 55 | |
| 56 | my $corpus = $r->route('/corpus'); |
| 57 | $corpus->search; |
| 58 | $corpus->route('/:corpus_id')->search; |
| 59 | $corpus->route('/:corpus_id/:doc_id')->search; |
| 60 | $corpus->route('/:corpus_id/#doc_id/:match_id')->to('info#about_match'); |
| 61 | |
| 62 | |
| 63 | |
Nils Diewald | 33e1555 | 2014-06-13 19:38:37 +0000 | [diff] [blame] | 64 | # $r->get( |
| 65 | # '/:resource/:corpus_id/#doc_id/#match_id', |
| 66 | # resource => [qw/collection corpus/])->to('search#match')->name('match'); |
| 67 | # /matchInfo?id=...&f=&l=&spans |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 70 | |
| 71 | 1; |
Nils Diewald | 33e1555 | 2014-06-13 19:38:37 +0000 | [diff] [blame] | 72 | |
| 73 | __END__ |
| 74 | |
| 75 | # TODO: Write search snippet |