blob: aea95f59a9dd1b2522beedf086b9965d4c3206aa [file] [log] [blame]
Nils Diewald2fe12e12015-03-06 16:47:06 +00001package Kalamar;
Nils Diewald5d1ffb42014-05-21 17:45:34 +00002use Mojo::Base 'Mojolicious';
Nils Diewalde2c83812014-11-11 21:13:18 +00003use Mojo::ByteStream 'b';
Nils Diewalda944fab2015-04-08 21:02:04 +00004use Mojo::JSON 'decode_json';
Nils Diewald5d1ffb42014-05-21 17:45:34 +00005
Nils Diewalda944fab2015-04-08 21:02:04 +00006our $VERSION;
Nils Diewald7cad8402014-07-08 17:06:56 +00007
Nils Diewald7148c6f2015-05-04 15:07:53 +00008# TODO: The FAQ-Page has a contact form for new questions
9
Nils Diewald002e8fb2014-06-22 14:27:01 +000010# Start the application and register all routes and plugins
Nils Diewald5d1ffb42014-05-21 17:45:34 +000011sub startup {
12 my $self = shift;
13
Nils Diewalda944fab2015-04-08 21:02:04 +000014 # Set version based on package file
15 my $pkg = b($self->home . '/package.json')->slurp;
16 $Kalamar::VERSION = decode_json($pkg)->{version};
17
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000018 # Add additional plugin path
19 push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin');
20
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000021 # Set secrets for signed cookies
Nils Diewald19402142015-04-30 15:44:52 +000022 if (-e (my $secret = $self->home . '/kalamar.secret')) {
23 $self->secrets([
24 b($secret)->slurp->split("\n")
25 ]);
Nils Diewald4347ee92015-05-04 20:32:48 +000026 }
27 else {
28 $self->log->warn('Please create a kalamar.secret file');
Nils Diewald19402142015-04-30 15:44:52 +000029 };
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000030
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000031 # Load plugins
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000032 foreach (
33 'Config', # Configuration framework
34 'Localize', # Localization framework
35 'Notifications', # Client notifications
36 'Search', # Abstract Search framework
37 'CHI', # Global caching mechanism
38 'TagHelpers::Pagination', # Pagination widget
Nils Diewald7148c6f2015-05-04 15:07:53 +000039 'Number::Commify', # Localize numbers
40 'KalamarHelpers' # Specific Helpers for Kalamar
41
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000042 ) {
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000043 $self->plugin($_);
44 };
45
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000046 # Configure mail exception
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000047 $self->plugin('MailException' => $self->config('MailException'));
48
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000049 # Configure documentation navigation
Nils Diewald7148c6f2015-05-04 15:07:53 +000050 my $navi = b($self->home . '/templates/doc/navigation.json')->slurp;
51 $self->config(navi => decode_json($navi)) if $navi;
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000052
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000053 # Establish routes
54 my $r = $self->routes;
55
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000056 # Base query page
57 $r->get('/')->to('search#query')->name('index');
58
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000059 # Documentation
Nils Diewald7148c6f2015-05-04 15:07:53 +000060 $r->get('/doc')->to('documentation#page', page => 'korap')->name('doc_start');
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000061 $r->get('/doc/:page')->to('documentation#page', scope => undef);
62 $r->get('/doc/*scope/:page')->to('documentation#page')->name('doc');
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000063
Nils Diewald7148c6f2015-05-04 15:07:53 +000064 # Match route
Nils Diewald8f4b5da2014-12-03 22:13:39 +000065 my $corpus = $r->route('/corpus/:corpus_id');
Nils Diewald7148c6f2015-05-04 15:07:53 +000066 my $doc = $corpus->get('/:doc_id');
67 my $text = $doc->get('/:text_id');
68 my $match = $text->get('/:match_id');
69 $match->to('search#match_info')->name('match');
Nils Diewald996aa552014-12-02 03:26:44 +000070};
71
72
731;
74
75
76__END__