blob: 259383b80fe0b8af6e16c3b4831ec1f77f97486b [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 Diewald002e8fb2014-06-22 14:27:01 +00006# Start the application and register all routes and plugins
Nils Diewald5d1ffb42014-05-21 17:45:34 +00007sub startup {
8 my $self = shift;
9
Nils Diewald002e8fb2014-06-22 14:27:01 +000010 # Set secret for signed cookies
Nils Diewald33e15552014-06-13 19:38:37 +000011 $self->secrets(['fmhsfjgfchgsdbfgshfxztsbt32477eb45veu4vubrghfgghbtv']);
12
Nils Diewald002e8fb2014-06-22 14:27:01 +000013 # Add additional plugin path
Nils Diewald5d1ffb42014-05-21 17:45:34 +000014 push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin');
Nils Diewald002e8fb2014-06-22 14:27:01 +000015
16 # Load plugins
17 foreach (qw/Config
18 CHI
19 TagHelpers::Pagination
20 Notifications
21 Number::Commify
22 KorapSearch
23 KorapInfo
24 KorapTagHelpers/) {
25 $self->plugin($_);
26 };
Nils Diewald2329e1d2014-06-12 16:07:57 +000027
28 $self->helper(
29 date_format => sub {
30 my ($c, $date) = @_;
31 return $date;
32 }
33 );
34
Nils Diewald64bab252014-05-22 11:04:04 +000035 # Routes
Nils Diewald5d1ffb42014-05-21 17:45:34 +000036 my $r = $self->routes;
37
Nils Diewald002e8fb2014-06-22 14:27:01 +000038 # Base search route
Nils Diewaldb22abdf2014-06-18 22:57:50 +000039 $r->get('/')->to('search#remote')->name('index');
Nils Diewald33e15552014-06-13 19:38:37 +000040
Nils Diewald002e8fb2014-06-22 14:27:01 +000041 # Tutorial data
42 $r->get('/tutorial/(*tutorial)', { tutorial => 'start' })
43 ->to('tutorial#page')->name('tutorial');
Nils Diewald2329e1d2014-06-12 16:07:57 +000044
Nils Diewald002e8fb2014-06-22 14:27:01 +000045 # Collection data
Nils Diewald1eba6572014-06-17 19:49:53 +000046 my $collection = $r->route('/collection');
47 $collection->to('search#info');
48 $collection->search;
49
Nils Diewald002e8fb2014-06-22 14:27:01 +000050 # Corpus data
Nils Diewald1eba6572014-06-17 19:49:53 +000051 my $corpus = $r->route('/corpus');
52 $corpus->search;
53 $corpus->route('/:corpus_id')->search;
Nils Diewald002e8fb2014-06-22 14:27:01 +000054 $corpus->route('/:corpus_id/#doc_id')->search;
55 $corpus->route('/:corpus_id/#doc_id/:match_id')
56 ->to('info#about_match');
Nils Diewald1eba6572014-06-17 19:49:53 +000057
Nils Diewald002e8fb2014-06-22 14:27:01 +000058 # Utilities
59 $r->get('/util/query')->to('search#query');
Nils Diewald64bab252014-05-22 11:04:04 +000060};
61
Nils Diewald5d1ffb42014-05-21 17:45:34 +000062
631;