blob: fddb9b49f316a4cc2ef24fac9f5a8424fd7e2d6a [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');
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 Diewald64bab252014-05-22 11:04:04 +000032 # Routes
Nils Diewald5d1ffb42014-05-21 17:45:34 +000033 my $r = $self->routes;
34
35 $r->add_shortcut(
36 search => sub {
37 shift->get('/search')->to('search#remote')
38 }
39 );
40
Nils Diewald64bab252014-05-22 11:04:04 +000041 $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 Diewald5d1ffb42014-05-21 17:45:34 +000049 $r->get('/:resource')->search;
50 $r->get('/:resource/:cid', resource => [qw/collection corpus/])->search;
51 $r->get('/:resource/')->search;
Nils Diewald5d1ffb42014-05-21 17:45:34 +000052 # /matchInfo?id=...&f=&l=&spans
Nils Diewald64bab252014-05-22 11:04:04 +000053};
54
Nils Diewald5d1ffb42014-05-21 17:45:34 +000055
561;