Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 1 | package Korap; |
| 2 | use Mojo::Base 'Mojolicious'; |
| 3 | |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame] | 4 | our $VERSION = '0.01'; |
| 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 | |
| 10 | $self->plugin('Config'); |
| 11 | $self->plugin('TagHelpers::Pagination'); |
Nils Diewald | dd2d4e8 | 2014-05-31 17:08:33 +0000 | [diff] [blame^] | 12 | $self->plugin('Notifications'); |
| 13 | $self->plugin('Number::Commify'); |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 14 | |
| 15 | push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin'); |
| 16 | $self->plugin('KorapSearch'); |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 17 | |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame] | 18 | # Routes |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 19 | my $r = $self->routes; |
| 20 | |
Nils Diewald | dd2d4e8 | 2014-05-31 17:08:33 +0000 | [diff] [blame^] | 21 | # Create search endpoint |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 22 | $r->add_shortcut( |
| 23 | search => sub { |
| 24 | shift->get('/search')->to('search#remote') |
| 25 | } |
| 26 | ); |
| 27 | |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame] | 28 | $r->get('/')->to( |
| 29 | cb => sub { |
| 30 | my $c = shift; |
Nils Diewald | dd2d4e8 | 2014-05-31 17:08:33 +0000 | [diff] [blame^] | 31 | $c->render( |
| 32 | text => |
| 33 | 'Go to '. |
| 34 | $c->link_to('search', '/collection/search')); |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame] | 35 | } |
| 36 | ); |
| 37 | |
| 38 | # resource => [qw/collection corpus/] |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 39 | $r->get('/:resource')->search; |
| 40 | $r->get('/:resource/:cid', resource => [qw/collection corpus/])->search; |
| 41 | $r->get('/:resource/')->search; |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 42 | # /matchInfo?id=...&f=&l=&spans |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 45 | |
| 46 | 1; |