blob: f79ef61d8094c79c356082046a7cb16f90888525 [file] [log] [blame]
Nils Diewald5d1ffb42014-05-21 17:45:34 +00001package Korap;
2use Mojo::Base 'Mojolicious';
3
Nils Diewald44a72782014-06-20 16:03:21 +00004our $VERSION = '0.03';
Nils Diewald64bab252014-05-22 11:04:04 +00005
Nils Diewald5d1ffb42014-05-21 17:45:34 +00006# This method will run once at server start
7sub startup {
8 my $self = shift;
9
Nils Diewald33e15552014-06-13 19:38:37 +000010 $self->secrets(['fmhsfjgfchgsdbfgshfxztsbt32477eb45veu4vubrghfgghbtv']);
11
Nils Diewald5d1ffb42014-05-21 17:45:34 +000012 $self->plugin('Config');
Nils Diewald2329e1d2014-06-12 16:07:57 +000013 $self->plugin('CHI');
Nils Diewald02df9912014-06-03 16:08:07 +000014 $self->plugin('TagHelpers::Pagination' => {
15 prev => '<span><i class="fa fa-caret-left"></i></span>',
16 next => '<span><i class="fa fa-caret-right"></i></span>',
Nils Diewald2329e1d2014-06-12 16:07:57 +000017 ellipsis => '<span><i class="fa fa-ellipsis-h"></i></span>',
Nils Diewald02df9912014-06-03 16:08:07 +000018 separator => '',
19 current => '<span>{current}</span>',
20 page => '<span>{page}</span>'
21 });
Nils Diewalddd2d4e82014-05-31 17:08:33 +000022 $self->plugin('Notifications');
23 $self->plugin('Number::Commify');
Nils Diewald5d1ffb42014-05-21 17:45:34 +000024 push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin');
25 $self->plugin('KorapSearch');
Nils Diewald2329e1d2014-06-12 16:07:57 +000026 $self->plugin('KorapInfo');
27 $self->plugin('KorapTagHelpers');
28
29 $self->helper(
30 date_format => sub {
31 my ($c, $date) = @_;
32 return $date;
33 }
34 );
35
Nils Diewald64bab252014-05-22 11:04:04 +000036 # Routes
Nils Diewald5d1ffb42014-05-21 17:45:34 +000037 my $r = $self->routes;
38
Nils Diewalddd2d4e82014-05-31 17:08:33 +000039 # Create search endpoint
Nils Diewald5d1ffb42014-05-21 17:45:34 +000040 $r->add_shortcut(
41 search => sub {
Nils Diewald33e15552014-06-13 19:38:37 +000042 shift->route('/search')->to('search#remote')
Nils Diewald5d1ffb42014-05-21 17:45:34 +000043 }
44 );
45
Nils Diewaldb22abdf2014-06-18 22:57:50 +000046 $r->get('/')->to('search#remote')->name('index');
Nils Diewald33e15552014-06-13 19:38:37 +000047 $r->get('/util/query')->to('search#query');
48
Nils Diewald2329e1d2014-06-12 16:07:57 +000049 # Tutorial
Nils Diewaldb22abdf2014-06-18 22:57:50 +000050 $r->get('/tutorial/(*tutorial)', { tutorial => 'start' })->to('tutorial#page')->name('tutorial');
Nils Diewald2329e1d2014-06-12 16:07:57 +000051
Nils Diewald1eba6572014-06-17 19:49:53 +000052 my $collection = $r->route('/collection');
53 $collection->to('search#info');
54 $collection->search;
55
56 my $corpus = $r->route('/corpus');
57 $corpus->search;
58 $corpus->route('/:corpus_id')->search;
59 $corpus->route('/:corpus_id/:doc_id')->search;
60 $corpus->route('/:corpus_id/#doc_id/:match_id')->to('info#about_match');
61
62
63
Nils Diewald33e15552014-06-13 19:38:37 +000064# $r->get(
65# '/:resource/:corpus_id/#doc_id/#match_id',
66# resource => [qw/collection corpus/])->to('search#match')->name('match');
67 # /matchInfo?id=...&f=&l=&spans
Nils Diewald64bab252014-05-22 11:04:04 +000068};
69
Nils Diewald5d1ffb42014-05-21 17:45:34 +000070
711;
Nils Diewald33e15552014-06-13 19:38:37 +000072
73__END__
74
75 # TODO: Write search snippet