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 | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame^] | 6 | # Start the application and register all routes and plugins |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 7 | sub startup { |
| 8 | my $self = shift; |
| 9 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame^] | 10 | # Set secret for signed cookies |
Nils Diewald | 33e1555 | 2014-06-13 19:38:37 +0000 | [diff] [blame] | 11 | $self->secrets(['fmhsfjgfchgsdbfgshfxztsbt32477eb45veu4vubrghfgghbtv']); |
| 12 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame^] | 13 | # Add additional plugin path |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 14 | push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin'); |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame^] | 15 | |
| 16 | # Load plugins |
| 17 | foreach (qw/Config |
| 18 | CHI |
| 19 | TagHelpers::Pagination |
| 20 | Notifications |
| 21 | Number::Commify |
| 22 | KorapSearch |
| 23 | KorapInfo |
| 24 | KorapTagHelpers/) { |
| 25 | $self->plugin($_); |
| 26 | }; |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame] | 27 | |
| 28 | $self->helper( |
| 29 | date_format => sub { |
| 30 | my ($c, $date) = @_; |
| 31 | return $date; |
| 32 | } |
| 33 | ); |
| 34 | |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame] | 35 | # Routes |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 36 | my $r = $self->routes; |
| 37 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame^] | 38 | # Base search route |
Nils Diewald | b22abdf | 2014-06-18 22:57:50 +0000 | [diff] [blame] | 39 | $r->get('/')->to('search#remote')->name('index'); |
Nils Diewald | 33e1555 | 2014-06-13 19:38:37 +0000 | [diff] [blame] | 40 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame^] | 41 | # Tutorial data |
| 42 | $r->get('/tutorial/(*tutorial)', { tutorial => 'start' }) |
| 43 | ->to('tutorial#page')->name('tutorial'); |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame] | 44 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame^] | 45 | # Collection data |
Nils Diewald | 1eba657 | 2014-06-17 19:49:53 +0000 | [diff] [blame] | 46 | my $collection = $r->route('/collection'); |
| 47 | $collection->to('search#info'); |
| 48 | $collection->search; |
| 49 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame^] | 50 | # Corpus data |
Nils Diewald | 1eba657 | 2014-06-17 19:49:53 +0000 | [diff] [blame] | 51 | my $corpus = $r->route('/corpus'); |
| 52 | $corpus->search; |
| 53 | $corpus->route('/:corpus_id')->search; |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame^] | 54 | $corpus->route('/:corpus_id/#doc_id')->search; |
| 55 | $corpus->route('/:corpus_id/#doc_id/:match_id') |
| 56 | ->to('info#about_match'); |
Nils Diewald | 1eba657 | 2014-06-17 19:49:53 +0000 | [diff] [blame] | 57 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame^] | 58 | # Utilities |
| 59 | $r->get('/util/query')->to('search#query'); |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 62 | |
| 63 | 1; |