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'); |
Nils Diewald | 02df991 | 2014-06-03 16:08:07 +0000 | [diff] [blame^] | 11 | $self->plugin('TagHelpers::Pagination' => { |
| 12 | prev => '<span><i class="fa fa-caret-left"></i></span>', |
| 13 | next => '<span><i class="fa fa-caret-right"></i></span>', |
| 14 | ellipsis => '<span>…</span>', |
| 15 | separator => '', |
| 16 | current => '<span>{current}</span>', |
| 17 | page => '<span>{page}</span>' |
| 18 | }); |
Nils Diewald | dd2d4e8 | 2014-05-31 17:08:33 +0000 | [diff] [blame] | 19 | $self->plugin('Notifications'); |
| 20 | $self->plugin('Number::Commify'); |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 21 | |
| 22 | push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin'); |
| 23 | $self->plugin('KorapSearch'); |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 24 | |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame] | 25 | # Routes |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 26 | my $r = $self->routes; |
| 27 | |
Nils Diewald | dd2d4e8 | 2014-05-31 17:08:33 +0000 | [diff] [blame] | 28 | # Create search endpoint |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 29 | $r->add_shortcut( |
| 30 | search => sub { |
| 31 | shift->get('/search')->to('search#remote') |
| 32 | } |
| 33 | ); |
| 34 | |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame] | 35 | $r->get('/')->to( |
| 36 | cb => sub { |
| 37 | my $c = shift; |
Nils Diewald | dd2d4e8 | 2014-05-31 17:08:33 +0000 | [diff] [blame] | 38 | $c->render( |
| 39 | text => |
| 40 | 'Go to '. |
| 41 | $c->link_to('search', '/collection/search')); |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame] | 42 | } |
| 43 | ); |
| 44 | |
Nils Diewald | 02df991 | 2014-06-03 16:08:07 +0000 | [diff] [blame^] | 45 | $r->get('/util/query')->to('search#query'); |
| 46 | |
| 47 | $r->get('/:resource' => [qw/collection corpus/])->to('search#info'); |
| 48 | |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame] | 49 | # resource => [qw/collection corpus/] |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 50 | $r->get('/:resource')->search; |
| 51 | $r->get('/:resource/:cid', resource => [qw/collection corpus/])->search; |
| 52 | $r->get('/:resource/')->search; |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 53 | # /matchInfo?id=...&f=&l=&spans |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 56 | |
| 57 | 1; |