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'); |
| 12 | |
| 13 | push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin'); |
| 14 | $self->plugin('KorapSearch'); |
| 15 | $self->plugin('Notifications' => { |
| 16 | use => 'Humane' |
| 17 | }); |
| 18 | |
| 19 | $self->helper( |
| 20 | format_thousands => sub { |
| 21 | shift; |
| 22 | my ($n, @array) = @_; |
| 23 | while ($n =~ /\d\d\d\d/) { |
| 24 | $n =~ s/(\d\d\d)$//; |
| 25 | unshift @array, $1; |
| 26 | }; |
| 27 | unshift @array, $n; |
| 28 | return join ',', @array; |
| 29 | } |
| 30 | ); |
| 31 | |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame^] | 32 | # Routes |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 33 | my $r = $self->routes; |
| 34 | |
| 35 | $r->add_shortcut( |
| 36 | search => sub { |
| 37 | shift->get('/search')->to('search#remote') |
| 38 | } |
| 39 | ); |
| 40 | |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame^] | 41 | $r->get('/')->to( |
| 42 | cb => sub { |
| 43 | my $c = shift; |
| 44 | $c->render('text' => 'Go to '. $c->link_to('search', '/collection/search')); |
| 45 | } |
| 46 | ); |
| 47 | |
| 48 | # resource => [qw/collection corpus/] |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 49 | $r->get('/:resource')->search; |
| 50 | $r->get('/:resource/:cid', resource => [qw/collection corpus/])->search; |
| 51 | $r->get('/:resource/')->search; |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 52 | # /matchInfo?id=...&f=&l=&spans |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame^] | 53 | }; |
| 54 | |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 55 | |
| 56 | 1; |