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/) { |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 25 | # AssetPack |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 26 | $self->plugin($_); |
| 27 | }; |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame] | 28 | |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 29 | # $self->asset( |
| 30 | # 'korap.css' => ( |
| 31 | # 'style.css', |
| 32 | # 'sass/hint.scss', |
| 33 | # 'table.css', |
| 34 | # 'sass/kwic-4.0.scss', |
| 35 | # 'fontawesome/font-awesome.min.css' |
| 36 | # ) |
| 37 | # ); |
| 38 | |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame] | 39 | $self->helper( |
| 40 | date_format => sub { |
| 41 | my ($c, $date) = @_; |
| 42 | return $date; |
| 43 | } |
| 44 | ); |
| 45 | |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame] | 46 | # Routes |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 47 | my $r = $self->routes; |
| 48 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 49 | # Base search route |
Nils Diewald | b22abdf | 2014-06-18 22:57:50 +0000 | [diff] [blame] | 50 | $r->get('/')->to('search#remote')->name('index'); |
Nils Diewald | 33e1555 | 2014-06-13 19:38:37 +0000 | [diff] [blame] | 51 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 52 | # Tutorial data |
| 53 | $r->get('/tutorial/(*tutorial)', { tutorial => 'start' }) |
| 54 | ->to('tutorial#page')->name('tutorial'); |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame] | 55 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 56 | # Collection data |
Nils Diewald | 1eba657 | 2014-06-17 19:49:53 +0000 | [diff] [blame] | 57 | my $collection = $r->route('/collection'); |
| 58 | $collection->to('search#info'); |
| 59 | $collection->search; |
| 60 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 61 | # Corpus data |
Nils Diewald | 1eba657 | 2014-06-17 19:49:53 +0000 | [diff] [blame] | 62 | my $corpus = $r->route('/corpus'); |
| 63 | $corpus->search; |
| 64 | $corpus->route('/:corpus_id')->search; |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 65 | $corpus->route('/:corpus_id/#doc_id')->search; |
| 66 | $corpus->route('/:corpus_id/#doc_id/:match_id') |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 67 | ->to('info#about_match')->name('match'); |
Nils Diewald | 1eba657 | 2014-06-17 19:49:53 +0000 | [diff] [blame] | 68 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 69 | # Utilities |
| 70 | $r->get('/util/query')->to('search#query'); |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame] | 71 | }; |
| 72 | |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 73 | |
| 74 | 1; |