blob: a1025d90e1fa097341e8f81d875e525cf8d3b7cd [file] [log] [blame]
Nils Diewald5d1ffb42014-05-21 17:45:34 +00001package Korap;
2use Mojo::Base 'Mojolicious';
3
Nils Diewald64bab252014-05-22 11:04:04 +00004our $VERSION = '0.01';
5
Nils Diewald5d1ffb42014-05-21 17:45:34 +00006# This method will run once at server start
7sub startup {
8 my $self = shift;
9
10 $self->plugin('Config');
Nils Diewald02df9912014-06-03 16:08:07 +000011 $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>&hellip;</span>',
15 separator => '',
16 current => '<span>{current}</span>',
17 page => '<span>{page}</span>'
18 });
Nils Diewalddd2d4e82014-05-31 17:08:33 +000019 $self->plugin('Notifications');
20 $self->plugin('Number::Commify');
Nils Diewald5d1ffb42014-05-21 17:45:34 +000021
22 push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin');
23 $self->plugin('KorapSearch');
Nils Diewald5d1ffb42014-05-21 17:45:34 +000024
Nils Diewald64bab252014-05-22 11:04:04 +000025 # Routes
Nils Diewald5d1ffb42014-05-21 17:45:34 +000026 my $r = $self->routes;
27
Nils Diewalddd2d4e82014-05-31 17:08:33 +000028 # Create search endpoint
Nils Diewald5d1ffb42014-05-21 17:45:34 +000029 $r->add_shortcut(
30 search => sub {
31 shift->get('/search')->to('search#remote')
32 }
33 );
34
Nils Diewald64bab252014-05-22 11:04:04 +000035 $r->get('/')->to(
36 cb => sub {
37 my $c = shift;
Nils Diewalddd2d4e82014-05-31 17:08:33 +000038 $c->render(
39 text =>
40 'Go to '.
41 $c->link_to('search', '/collection/search'));
Nils Diewald64bab252014-05-22 11:04:04 +000042 }
43 );
44
Nils Diewald02df9912014-06-03 16:08:07 +000045 $r->get('/util/query')->to('search#query');
46
47 $r->get('/:resource' => [qw/collection corpus/])->to('search#info');
48
Nils Diewald64bab252014-05-22 11:04:04 +000049 # resource => [qw/collection corpus/]
Nils Diewald5d1ffb42014-05-21 17:45:34 +000050 $r->get('/:resource')->search;
51 $r->get('/:resource/:cid', resource => [qw/collection corpus/])->search;
52 $r->get('/:resource/')->search;
Nils Diewald5d1ffb42014-05-21 17:45:34 +000053 # /matchInfo?id=...&f=&l=&spans
Nils Diewald64bab252014-05-22 11:04:04 +000054};
55
Nils Diewald5d1ffb42014-05-21 17:45:34 +000056
571;