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 | 'KalamarHelpers' # Specific Helpers for Kalamar |
| 40 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 41 | ) { |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 42 | $self->plugin($_); |
| 43 | }; |
| 44 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 45 | # Configure mail exception |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 46 | $self->plugin('MailException' => $self->config('MailException')); |
| 47 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 48 | # Configure documentation navigation |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 49 | my $navi = b($self->home . '/templates/doc/navigation.json')->slurp; |
| 50 | $self->config(navi => decode_json($navi)) if $navi; |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 51 | |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 52 | # Establish routes |
| 53 | my $r = $self->routes; |
| 54 | |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 55 | # Base query page |
| 56 | $r->get('/')->to('search#query')->name('index'); |
| 57 | |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 58 | # Documentation |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 59 | $r->get('/doc')->to('documentation#page', page => 'korap')->name('doc_start'); |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 60 | $r->get('/doc/:page')->to('documentation#page', scope => undef); |
| 61 | $r->get('/doc/*scope/:page')->to('documentation#page')->name('doc'); |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 62 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 63 | # Match route |
Nils Diewald | 8f4b5da | 2014-12-03 22:13:39 +0000 | [diff] [blame] | 64 | my $corpus = $r->route('/corpus/:corpus_id'); |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 65 | my $doc = $corpus->get('/:doc_id'); |
| 66 | my $text = $doc->get('/:text_id'); |
| 67 | my $match = $text->get('/:match_id'); |
| 68 | $match->to('search#match_info')->name('match'); |
Nils Diewald | 996aa55 | 2014-12-02 03:26:44 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | |
| 72 | 1; |
| 73 | |
| 74 | |
| 75 | __END__ |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 76 | |
| 77 | =pod |
| 78 | |
| 79 | To get started, you'll need npm. Then you can install and run grunt: |
| 80 | |
| 81 | sudo npm install -g grunt-cli |
| 82 | npm install |
| 83 | grunt |