blob: 04f0014c582cf9ca66626af03fb306c8d71e8f11 [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/) {
Nils Diewald4af3f0b2014-06-25 01:43:17 +000025 # AssetPack
Nils Diewald002e8fb2014-06-22 14:27:01 +000026 $self->plugin($_);
27 };
Nils Diewald2329e1d2014-06-12 16:07:57 +000028
Nils Diewald4af3f0b2014-06-25 01:43:17 +000029# $self->asset(
30# 'korap.css' => (
31# 'style.css',
32# 'sass/hint.scss',
33# 'table.css',
34# 'sass/kwic-4.0.scss',
35# 'fontawesome/font-awesome.min.css'
36# )
37# );
38
Nils Diewald2329e1d2014-06-12 16:07:57 +000039 $self->helper(
40 date_format => sub {
41 my ($c, $date) = @_;
42 return $date;
43 }
44 );
45
Nils Diewald64bab252014-05-22 11:04:04 +000046 # Routes
Nils Diewald5d1ffb42014-05-21 17:45:34 +000047 my $r = $self->routes;
48
Nils Diewald002e8fb2014-06-22 14:27:01 +000049 # Base search route
Nils Diewaldb22abdf2014-06-18 22:57:50 +000050 $r->get('/')->to('search#remote')->name('index');
Nils Diewald33e15552014-06-13 19:38:37 +000051
Nils Diewald002e8fb2014-06-22 14:27:01 +000052 # Tutorial data
53 $r->get('/tutorial/(*tutorial)', { tutorial => 'start' })
54 ->to('tutorial#page')->name('tutorial');
Nils Diewald2329e1d2014-06-12 16:07:57 +000055
Nils Diewald002e8fb2014-06-22 14:27:01 +000056 # Collection data
Nils Diewald1eba6572014-06-17 19:49:53 +000057 my $collection = $r->route('/collection');
58 $collection->to('search#info');
59 $collection->search;
60
Nils Diewald002e8fb2014-06-22 14:27:01 +000061 # Corpus data
Nils Diewald1eba6572014-06-17 19:49:53 +000062 my $corpus = $r->route('/corpus');
63 $corpus->search;
64 $corpus->route('/:corpus_id')->search;
Nils Diewald002e8fb2014-06-22 14:27:01 +000065 $corpus->route('/:corpus_id/#doc_id')->search;
66 $corpus->route('/:corpus_id/#doc_id/:match_id')
Nils Diewald4af3f0b2014-06-25 01:43:17 +000067 ->to('info#about_match')->name('match');
Nils Diewald1eba6572014-06-17 19:49:53 +000068
Nils Diewald002e8fb2014-06-22 14:27:01 +000069 # Utilities
70 $r->get('/util/query')->to('search#query');
Nils Diewald64bab252014-05-22 11:04:04 +000071};
72
Nils Diewald5d1ffb42014-05-21 17:45:34 +000073
741;