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 | ]); |
Nils Diewald | 4347ee9 | 2015-05-04 20:32:48 +0000 | [diff] [blame^] | 26 | } |
| 27 | else { |
| 28 | $self->log->warn('Please create a kalamar.secret file'); |
Nils Diewald | 1940214 | 2015-04-30 15:44:52 +0000 | [diff] [blame] | 29 | }; |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 30 | |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 31 | # Load plugins |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 32 | 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 Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 39 | 'Number::Commify', # Localize numbers |
| 40 | 'KalamarHelpers' # Specific Helpers for Kalamar |
| 41 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 42 | ) { |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 43 | $self->plugin($_); |
| 44 | }; |
| 45 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 46 | # Configure mail exception |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 47 | $self->plugin('MailException' => $self->config('MailException')); |
| 48 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 49 | # Configure documentation navigation |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 50 | my $navi = b($self->home . '/templates/doc/navigation.json')->slurp; |
| 51 | $self->config(navi => decode_json($navi)) if $navi; |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 52 | |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 53 | # Establish routes |
| 54 | my $r = $self->routes; |
| 55 | |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 56 | # Base query page |
| 57 | $r->get('/')->to('search#query')->name('index'); |
| 58 | |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 59 | # Documentation |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 60 | $r->get('/doc')->to('documentation#page', page => 'korap')->name('doc_start'); |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 61 | $r->get('/doc/:page')->to('documentation#page', scope => undef); |
| 62 | $r->get('/doc/*scope/:page')->to('documentation#page')->name('doc'); |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 63 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 64 | # Match route |
Nils Diewald | 8f4b5da | 2014-12-03 22:13:39 +0000 | [diff] [blame] | 65 | my $corpus = $r->route('/corpus/:corpus_id'); |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 66 | 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 Diewald | 996aa55 | 2014-12-02 03:26:44 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | |
| 73 | 1; |
| 74 | |
| 75 | |
| 76 | __END__ |