Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 1 | package Kalamar; |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 2 | use Mojo::Base 'Mojolicious'; |
Nils Diewald | e2c8381 | 2014-11-11 21:13:18 +0000 | [diff] [blame] | 3 | use Mojo::ByteStream 'b'; |
Nils Diewald | a944fab | 2015-04-08 21:02:04 +0000 | [diff] [blame] | 4 | use Mojo::JSON 'decode_json'; |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 5 | |
Nils Diewald | a944fab | 2015-04-08 21:02:04 +0000 | [diff] [blame] | 6 | our $VERSION; |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 7 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame^] | 8 | # TODO: The FAQ-Page has a contact form for new questions |
| 9 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 10 | # Start the application and register all routes and plugins |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 11 | sub startup { |
| 12 | my $self = shift; |
| 13 | |
Nils Diewald | a944fab | 2015-04-08 21:02:04 +0000 | [diff] [blame] | 14 | # Set version based on package file |
| 15 | my $pkg = b($self->home . '/package.json')->slurp; |
| 16 | $Kalamar::VERSION = decode_json($pkg)->{version}; |
| 17 | |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 18 | # Add additional plugin path |
| 19 | push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin'); |
| 20 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 21 | # Set secrets for signed cookies |
Nils Diewald | 1940214 | 2015-04-30 15:44:52 +0000 | [diff] [blame] | 22 | if (-e (my $secret = $self->home . '/kalamar.secret')) { |
| 23 | $self->secrets([ |
| 24 | b($secret)->slurp->split("\n") |
| 25 | ]); |
| 26 | }; |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 27 | |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 28 | # Load plugins |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 29 | foreach ( |
| 30 | 'Config', # Configuration framework |
| 31 | 'Localize', # Localization framework |
| 32 | 'Notifications', # Client notifications |
| 33 | 'Search', # Abstract Search framework |
| 34 | 'CHI', # Global caching mechanism |
| 35 | 'TagHelpers::Pagination', # Pagination widget |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame^] | 36 | 'Number::Commify', # Localize numbers |
| 37 | 'KalamarHelpers' # Specific Helpers for Kalamar |
| 38 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 39 | ) { |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 40 | $self->plugin($_); |
| 41 | }; |
| 42 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 43 | # Configure mail exception |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 44 | $self->plugin('MailException' => $self->config('MailException')); |
| 45 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 46 | # Configure documentation navigation |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame^] | 47 | my $navi = b($self->home . '/templates/doc/navigation.json')->slurp; |
| 48 | $self->config(navi => decode_json($navi)) if $navi; |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 49 | |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 50 | # Establish routes |
| 51 | my $r = $self->routes; |
| 52 | |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 53 | # Base query page |
| 54 | $r->get('/')->to('search#query')->name('index'); |
| 55 | |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 56 | # Documentation |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame^] | 57 | $r->get('/doc')->to('documentation#page', page => 'korap')->name('doc_start'); |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 58 | $r->get('/doc/:page')->to('documentation#page', scope => undef); |
| 59 | $r->get('/doc/*scope/:page')->to('documentation#page')->name('doc'); |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 60 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame^] | 61 | # Match route |
Nils Diewald | 8f4b5da | 2014-12-03 22:13:39 +0000 | [diff] [blame] | 62 | my $corpus = $r->route('/corpus/:corpus_id'); |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame^] | 63 | my $doc = $corpus->get('/:doc_id'); |
| 64 | my $text = $doc->get('/:text_id'); |
| 65 | my $match = $text->get('/:match_id'); |
| 66 | $match->to('search#match_info')->name('match'); |
Nils Diewald | 996aa55 | 2014-12-02 03:26:44 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | |
| 70 | 1; |
| 71 | |
| 72 | |
| 73 | __END__ |