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 | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 8 | # Start the application and register all routes and plugins |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 9 | sub startup { |
| 10 | my $self = shift; |
| 11 | |
Nils Diewald | a944fab | 2015-04-08 21:02:04 +0000 | [diff] [blame] | 12 | # Set version based on package file |
| 13 | my $pkg = b($self->home . '/package.json')->slurp; |
| 14 | $Kalamar::VERSION = decode_json($pkg)->{version}; |
| 15 | |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 16 | # Add additional plugin path |
| 17 | push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin'); |
| 18 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame^] | 19 | # Set secrets for signed cookies |
| 20 | $self->secrets([ |
| 21 | b($self->home . '/kalamar.secret')->slurp->split("\n") |
| 22 | ]); |
| 23 | |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 24 | # Load plugins |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame^] | 25 | foreach ( |
| 26 | 'Config', # Configuration framework |
| 27 | 'Localize', # Localization framework |
| 28 | 'Notifications', # Client notifications |
| 29 | 'Search', # Abstract Search framework |
| 30 | 'CHI', # Global caching mechanism |
| 31 | 'TagHelpers::Pagination', # Pagination widget |
| 32 | 'DocNavi', # Navigation for documentation |
| 33 | 'KalamarHelpers', # Specific Helpers for Kalamar |
| 34 | 'KalamarTagHelpers' # Specific Taghelpers for Kalamar |
| 35 | ) { |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 36 | $self->plugin($_); |
| 37 | }; |
| 38 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame^] | 39 | # Configure mail exception |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 40 | $self->plugin('MailException' => $self->config('MailException')); |
| 41 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame^] | 42 | # Configure documentation navigation |
| 43 | my $navi = b($self->home . '/templates/doc/_nav.json')->slurp; |
| 44 | $self->config(navi => decode_json($navi)); |
| 45 | |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 46 | # Establish routes |
| 47 | my $r = $self->routes; |
| 48 | |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 49 | # Base query page |
| 50 | $r->get('/')->to('search#query')->name('index'); |
| 51 | |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 52 | # Documentation |
| 53 | $r->get('/doc')->to('documentation#page', page => 'korap'); |
| 54 | $r->get('/doc/:page')->to('documentation#page', scope => undef); |
| 55 | $r->get('/doc/*scope/:page')->to('documentation#page')->name('doc'); |
| 56 | }; |
| 57 | |
| 58 | |
| 59 | 1; |
| 60 | |
| 61 | |
| 62 | __END__ |
| 63 | |
| 64 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 65 | # Set default totle |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 66 | # $self->defaults( |
| 67 | # layout => 'main', |
| 68 | # title => 'KorAP - Corpus Analysis Platform' |
| 69 | # ); |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 70 | |
Nils Diewald | 33e1555 | 2014-06-13 19:38:37 +0000 | [diff] [blame] | 71 | |
Nils Diewald | a944fab | 2015-04-08 21:02:04 +0000 | [diff] [blame] | 72 | $self->hook( |
| 73 | before_dispatch => sub { |
Nils Diewald | 8462c18 | 2015-03-10 20:57:55 +0000 | [diff] [blame] | 74 | my $c = shift; |
| 75 | my $host = $c->req->headers->header('X-Forwarded-Host'); |
| 76 | if ($host && $host eq 'korap.ids-mannheim.de') { |
| 77 | $c->req->url->base->path('/kalamar/'); |
| 78 | }; |
Nils Diewald | a944fab | 2015-04-08 21:02:04 +0000 | [diff] [blame] | 79 | }) if $self->mode eq 'production'; |
Nils Diewald | 8462c18 | 2015-03-10 20:57:55 +0000 | [diff] [blame] | 80 | |
Nils Diewald | 44e1edb | 2015-04-08 19:12:15 +0000 | [diff] [blame] | 81 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 82 | |
| 83 | # Load plugins |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame^] | 84 | foreach (qw/ |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 85 | Number::Commify |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 86 | /) { |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 87 | $self->plugin($_); |
| 88 | }; |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame] | 89 | |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 90 | # $self->plugin(AssetPack => { minify => 1 }); |
Nils Diewald | 996aa55 | 2014-12-02 03:26:44 +0000 | [diff] [blame] | 91 | $self->plugin('AssetPack'); |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 92 | $self->plugin('AssetPack::LibSass'); |
| 93 | |
Nils Diewald | 94bae91 | 2014-09-22 13:40:31 +0000 | [diff] [blame] | 94 | # Add assets for AssetPack |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 95 | $self->asset( |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 96 | 'kalamar.css' => ( |
| 97 | |
| 98 | # Sass files |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 99 | '/sass/style.scss', |
| 100 | '/sass/sidebar.scss', |
| 101 | '/sass/tutorial.scss', |
| 102 | '/sass/hint.scss', |
| 103 | '/sass/query.scss', |
Nils Diewald | f2e02a9 | 2014-11-12 18:31:05 +0000 | [diff] [blame] | 104 | '/sass/matchinfo.scss', |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 105 | '/sass/pagination.scss', |
| 106 | '/sass/kwic-4.0.scss', |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 107 | '/sass/alertify.scss', |
| 108 | |
| 109 | # CSS files |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 110 | '/css/font-awesome.min.css', |
Nils Diewald | 3d87184 | 2015-03-10 23:14:34 +0000 | [diff] [blame] | 111 | '/css/media.css', |
Nils Diewald | ca01b76 | 2014-09-08 02:35:20 +0000 | [diff] [blame] | 112 | '/css/highlight.css', |
Nils Diewald | ca01b76 | 2014-09-08 02:35:20 +0000 | [diff] [blame] | 113 | $self->notifications->styles |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 114 | ) |
| 115 | ); |
| 116 | |
| 117 | $self->asset( |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 118 | 'kalamar.js' => ( |
Nils Diewald | 8f4b5da | 2014-12-03 22:13:39 +0000 | [diff] [blame] | 119 | # '/js/d3.v3.min.js', |
Nils Diewald | f2e02a9 | 2014-11-12 18:31:05 +0000 | [diff] [blame] | 120 | # '/js/dagre-d3.min.js', |
Nils Diewald | 8f4b5da | 2014-12-03 22:13:39 +0000 | [diff] [blame] | 121 | # '/js/dagre-d3.js', |
| 122 | # '/js/translateTree.js', |
Nils Diewald | 4e9fbcb | 2014-07-15 11:45:09 +0000 | [diff] [blame] | 123 | '/js/tutorialCookie.js', |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 124 | '/js/translateTable.js', |
| 125 | '/js/hint.js', |
Nils Diewald | ca01b76 | 2014-09-08 02:35:20 +0000 | [diff] [blame] | 126 | '/js/highlight.pack.js', |
Nils Diewald | e99d904 | 2014-11-20 23:36:54 +0000 | [diff] [blame] | 127 | '/js/ajax.js', |
Nils Diewald | ca01b76 | 2014-09-08 02:35:20 +0000 | [diff] [blame] | 128 | $self->notifications->scripts |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 129 | ) |
| 130 | ); |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 131 | |
Nils Diewald | 89d8801 | 2015-03-10 21:03:36 +0000 | [diff] [blame] | 132 | $self->helper( |
| 133 | date_format => sub { |
| 134 | my ($c, $date) = @_; |
| 135 | return $date; |
| 136 | } |
| 137 | ); |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame] | 138 | |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 139 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 140 | # Base search route |
Nils Diewald | 8f4b5da | 2014-12-03 22:13:39 +0000 | [diff] [blame] | 141 | $r->get('/')->to('search#query')->name('index'); |
| 142 | |
| 143 | # Get match information |
| 144 | my $corpus = $r->route('/corpus/:corpus_id'); |
| 145 | my $doc = $corpus->route('/#doc_id'); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 146 | my $match = $doc->route('/:match_id') |
| 147 | ->to('search#match_info') |
| 148 | ->name('match'); |
Nils Diewald | 33e1555 | 2014-06-13 19:38:37 +0000 | [diff] [blame] | 149 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 150 | # Tutorial data |
Nils Diewald | 4e9fbcb | 2014-07-15 11:45:09 +0000 | [diff] [blame] | 151 | $r->get('/tutorial')->to('tutorial#page', tutorial => 'index'); |
| 152 | $r->get('/tutorial/(*tutorial)')->to('tutorial#page')->name('tutorial'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 153 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 154 | |
| 155 | # Todo: The FAQ-Page has a contact form for new questions |
Nils Diewald | 996aa55 | 2014-12-02 03:26:44 +0000 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | |
| 159 | 1; |
| 160 | |
| 161 | |
| 162 | __END__ |