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 | a748b0e | 2015-05-19 22:54:06 +0000 | [diff] [blame] | 6 | # Sync with package.json |
| 7 | our $VERSION = '0.15.0'; |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 8 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 9 | # TODO: The FAQ-Page has a contact form for new questions |
| 10 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 11 | # Start the application and register all routes and plugins |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 12 | sub startup { |
| 13 | my $self = shift; |
| 14 | |
Nils Diewald | a944fab | 2015-04-08 21:02:04 +0000 | [diff] [blame] | 15 | # Set version based on package file |
Nils Diewald | a748b0e | 2015-05-19 22:54:06 +0000 | [diff] [blame] | 16 | # my $pkg = b($self->home . '/package.json')->slurp; |
| 17 | # $Kalamar::VERSION = decode_json($pkg)->{version}; |
Nils Diewald | a944fab | 2015-04-08 21:02:04 +0000 | [diff] [blame] | 18 | |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 19 | # Add additional plugin path |
| 20 | push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin'); |
| 21 | |
Nils Diewald | a79b268 | 2015-05-18 18:34:06 +0000 | [diff] [blame] | 22 | # korap.ids-mannheim.de specific path prefixing |
Nils Diewald | a0defc4 | 2015-05-07 23:54:17 +0000 | [diff] [blame] | 23 | $self->hook( |
| 24 | before_dispatch => sub { |
| 25 | my $c = shift; |
| 26 | my $host = $c->req->headers->header('X-Forwarded-Host'); |
| 27 | if ($host && $host eq 'korap.ids-mannheim.de') { |
| 28 | $c->req->url->base->path('/kalamar/'); |
Nils Diewald | 705b74a | 2015-05-07 23:57:34 +0000 | [diff] [blame] | 29 | $c->stash(prefix => '/kalamar'); |
Nils Diewald | a0defc4 | 2015-05-07 23:54:17 +0000 | [diff] [blame] | 30 | }; |
| 31 | }) if $self->mode eq 'production'; |
| 32 | |
Nils Diewald | a748b0e | 2015-05-19 22:54:06 +0000 | [diff] [blame] | 33 | |
Nils Diewald | 845282c | 2015-05-14 07:53:03 +0000 | [diff] [blame] | 34 | # Cache static assets |
Nils Diewald | a79b268 | 2015-05-18 18:34:06 +0000 | [diff] [blame] | 35 | # (not necessary, as long as shipped by nginx or Apache) |
Nils Diewald | 845282c | 2015-05-14 07:53:03 +0000 | [diff] [blame] | 36 | $self->hook( |
| 37 | after_static => sub { |
| 38 | my $res = shift->res; |
| 39 | if ($res->code) { |
| 40 | $res->headers->cache_control('public, max-age=172800'); |
| 41 | }; |
| 42 | }); |
| 43 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 44 | # Set secrets for signed cookies |
Nils Diewald | 1940214 | 2015-04-30 15:44:52 +0000 | [diff] [blame] | 45 | if (-e (my $secret = $self->home . '/kalamar.secret')) { |
Nils Diewald | a79b268 | 2015-05-18 18:34:06 +0000 | [diff] [blame] | 46 | |
| 47 | # Load file and split lines for multiple secrets |
| 48 | $self->secrets([b($secret)->slurp->split("\n")]); |
Nils Diewald | 4347ee9 | 2015-05-04 20:32:48 +0000 | [diff] [blame] | 49 | } |
| 50 | else { |
| 51 | $self->log->warn('Please create a kalamar.secret file'); |
Nils Diewald | 1940214 | 2015-04-30 15:44:52 +0000 | [diff] [blame] | 52 | }; |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 53 | |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 54 | # Load plugins |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 55 | foreach ( |
Nils Diewald | c46003b | 2015-05-07 15:55:35 +0000 | [diff] [blame] | 56 | 'Config', # Configuration framework |
| 57 | 'Localize', # Localization framework |
| 58 | 'Notifications', # Client notifications |
| 59 | 'Search', # Abstract Search framework |
| 60 | 'CHI', # Global caching mechanism |
Nils Diewald | a748b0e | 2015-05-19 22:54:06 +0000 | [diff] [blame] | 61 | 'MailException', # Alert via Email on exception |
Nils Diewald | c46003b | 2015-05-07 15:55:35 +0000 | [diff] [blame] | 62 | 'TagHelpers::Pagination', # Pagination widget |
| 63 | 'TagHelpers::MailToChiffre', # Obfuscate email addresses |
Nils Diewald | a79b268 | 2015-05-18 18:34:06 +0000 | [diff] [blame] | 64 | 'KalamarHelpers', # Specific Helpers for Kalamar |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 65 | ) { |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 66 | $self->plugin($_); |
| 67 | }; |
| 68 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 69 | # Configure mail exception |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 70 | $self->plugin('MailException' => $self->config('MailException')); |
| 71 | |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 72 | # Configure documentation navigation |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 73 | my $navi = b($self->home . '/templates/doc/navigation.json')->slurp; |
| 74 | $self->config(navi => decode_json($navi)) if $navi; |
Nils Diewald | fccfbcb | 2015-04-29 20:48:19 +0000 | [diff] [blame] | 75 | |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 76 | # Establish routes |
| 77 | my $r = $self->routes; |
| 78 | |
Nils Diewald | a79b268 | 2015-05-18 18:34:06 +0000 | [diff] [blame] | 79 | # Base query route |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 80 | $r->get('/')->to('search#query')->name('index'); |
| 81 | |
Nils Diewald | a79b268 | 2015-05-18 18:34:06 +0000 | [diff] [blame] | 82 | # Documentation routes |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 83 | $r->get('/doc')->to('documentation#page', page => 'korap')->name('doc_start'); |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 84 | $r->get('/doc/:page')->to('documentation#page', scope => undef); |
| 85 | $r->get('/doc/*scope/:page')->to('documentation#page')->name('doc'); |
Nils Diewald | ab4d3ca | 2015-04-17 01:48:43 +0000 | [diff] [blame] | 86 | |
Nils Diewald | c46003b | 2015-05-07 15:55:35 +0000 | [diff] [blame] | 87 | # Contact route |
| 88 | $r->get('/contact')->to('documentation#contact'); |
| 89 | $r->get('/contact')->mail_to_chiffre('documentation#contact'); |
| 90 | |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 91 | # Match route |
Nils Diewald | 8f4b5da | 2014-12-03 22:13:39 +0000 | [diff] [blame] | 92 | my $corpus = $r->route('/corpus/:corpus_id'); |
Nils Diewald | 7148c6f | 2015-05-04 15:07:53 +0000 | [diff] [blame] | 93 | my $doc = $corpus->get('/:doc_id'); |
| 94 | my $text = $doc->get('/:text_id'); |
| 95 | my $match = $text->get('/:match_id'); |
| 96 | $match->to('search#match_info')->name('match'); |
Nils Diewald | 996aa55 | 2014-12-02 03:26:44 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | |
| 100 | 1; |
| 101 | |
| 102 | |
| 103 | __END__ |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 104 | |
| 105 | =pod |
| 106 | |
Nils Diewald | eb5f307 | 2015-05-20 09:32:42 +0000 | [diff] [blame^] | 107 | =encoding utf8 |
Nils Diewald | a898dac | 2015-05-06 21:04:16 +0000 | [diff] [blame] | 108 | |
Nils Diewald | eb5f307 | 2015-05-20 09:32:42 +0000 | [diff] [blame^] | 109 | =head1 NAME |
| 110 | |
| 111 | Kalamar |
Nils Diewald | a0defc4 | 2015-05-07 23:54:17 +0000 | [diff] [blame] | 112 | |
| 113 | |
Nils Diewald | eb5f307 | 2015-05-20 09:32:42 +0000 | [diff] [blame^] | 114 | =head1 DESCRIPTION |
Nils Diewald | a0defc4 | 2015-05-07 23:54:17 +0000 | [diff] [blame] | 115 | |
Nils Diewald | eb5f307 | 2015-05-20 09:32:42 +0000 | [diff] [blame^] | 116 | L<Kalamar> is a L<Mojolicious|http://mojolicio.us/> based user interface |
| 117 | frontend for the L<KorAP Corpus Analysis Platform|http://korap.ids-mannheim.de/>. |
| 118 | |
| 119 | =head1 INSTALLATION |
| 120 | |
| 121 | =head2 Generate Static Asset Files |
| 122 | |
| 123 | To generate the static asset files (scripts, styles, images ...), |
| 124 | you need NodeJS E<gt> 0.8 and Grunt. To install Grunt, just run |
| 125 | |
| 126 | $ sudo npm install -g grunt-cli |
| 127 | $ npm install |
| 128 | $ grunt |
Nils Diewald | 652e5f4 | 2015-05-10 18:11:45 +0000 | [diff] [blame] | 129 | |
| 130 | |
Nils Diewald | eb5f307 | 2015-05-20 09:32:42 +0000 | [diff] [blame^] | 131 | =head2 Start Server |
Nils Diewald | 652e5f4 | 2015-05-10 18:11:45 +0000 | [diff] [blame] | 132 | |
Nils Diewald | eb5f307 | 2015-05-20 09:32:42 +0000 | [diff] [blame^] | 133 | Kalamar uses the L<Mojolicious|http://mojolicio.us/> framework, |
| 134 | that expects a Perl version of at least 5.10.1. |
| 135 | The recommended environment is based on L<Perlbrew|http://perlbrew.pl/> |
| 136 | with L<App::cpanminus>. |
| 137 | |
| 138 | Some perl modules are not on CPAN yet, |
| 139 | so you need to install them from GitHub. |
| 140 | The easiest way to do this is running |
| 141 | |
| 142 | $ cpanm git://github.com/Akron/Mojolicious-Plugin-Search.git |
| 143 | $ cpanm git://github.com/Akron/Mojolicious-Plugin-Localize.git |
| 144 | $ cpanm --installdeps . |
| 145 | $ perl Makefile.PL |
| 146 | $ make test |
| 147 | |
| 148 | Kalamar can be deployed like all |
| 149 | L<Mojolicious apps|http://mojolicio.us/perldoc/Mojolicious/Guides/Cookbook#DEPLOYMENT>. |
| 150 | The easiest way is to start the built-in server: |
| 151 | |
| 152 | $ perl script/kalamar deamon |
Nils Diewald | a748b0e | 2015-05-19 22:54:06 +0000 | [diff] [blame] | 153 | |
| 154 | |
| 155 | =head1 COPYRIGHT AND LICENSE |
| 156 | |
| 157 | =head2 Bundled Software |
| 158 | |
| 159 | C<ALERTIFY.js> is released under the terms of the MIT License. |
| 160 | C<Almond> is released under the terms of the BSD License. |
| 161 | C<dagre> is released under the terms of the MIT License. |
| 162 | C<Highlight.js> is released under the terms of the BSD License. |
| 163 | C<Jasmine> is released under the terms of the MIT License. |
| 164 | C<RequireJS> is released under the terms of the BSD License. |
| 165 | |
| 166 | |
| 167 | =head2 Original Software |
| 168 | |
| 169 | Copyright (C) 2015, L<IDS Mannheim|http://www.ids-mannheim.de/> |
| 170 | Author: L<Nils Diewald|http://nils-diewald.de/> |
| 171 | |
| 172 | Kalamar is developed as part of the L<KorAP|http://korap.ids-mannheim.de/> |
| 173 | Corpus Analysis Platform at the |
| 174 | L<Institute for the German Language (IDS)|http://ids-mannheim.de/>, |
| 175 | member of the |
| 176 | L<Leibniz-Gemeinschaft|http://www.leibniz-gemeinschaft.de/en/about-us/leibniz-competition/projekte-2011/2011-funding-line-2/> |
| 177 | and supported by the L<KobRA|http://www.kobra.tu-dortmund.de> project, |
| 178 | funded by the |
| 179 | L<Federal Ministry of Education and Research (BMBF)|http://www.bmbf.de/en/>. |
| 180 | |
| 181 | Kalamar is free software published under the |
| 182 | L<BSD-2 License|https://raw.githubusercontent.com/KorAP/Kalamar/master/LICENSE). |
| 183 | |
| 184 | =cut |