blob: d89d40dc4e1ee3db6a6f7b6176163fff77b09555 [file] [log] [blame]
Nils Diewald2fe12e12015-03-06 16:47:06 +00001package Kalamar;
Nils Diewald5d1ffb42014-05-21 17:45:34 +00002use Mojo::Base 'Mojolicious';
Nils Diewalde2c83812014-11-11 21:13:18 +00003use Mojo::ByteStream 'b';
Nils Diewalda944fab2015-04-08 21:02:04 +00004use Mojo::JSON 'decode_json';
Nils Diewald5d1ffb42014-05-21 17:45:34 +00005
Nils Diewald709f52f2015-05-21 18:32:58 +00006# Minor version - may be patched from package.json
7our $VERSION = '0.15';
Nils Diewald7cad8402014-07-08 17:06:56 +00008
Nils Diewald7148c6f2015-05-04 15:07:53 +00009# TODO: The FAQ-Page has a contact form for new questions
Nils Diewald709f52f2015-05-21 18:32:58 +000010# TODO: Embed query serialization
11# TODO: Embed collection statistics
12# TODO: Implement tab opener for matches and the tutorial
13# TODO: Make the tutorial ql sensitive
14# TODO: Implement a "projects" system
Nils Diewald7148c6f2015-05-04 15:07:53 +000015
Nils Diewald002e8fb2014-06-22 14:27:01 +000016# Start the application and register all routes and plugins
Nils Diewald5d1ffb42014-05-21 17:45:34 +000017sub startup {
18 my $self = shift;
19
Nils Diewalda944fab2015-04-08 21:02:04 +000020 # Set version based on package file
Nils Diewald709f52f2015-05-21 18:32:58 +000021 # This may introduce a SemVer patch number
22 my $pkg = b($self->home . '/package.json')->slurp;
23 $Kalamar::VERSION = decode_json($pkg)->{version};
Nils Diewalda944fab2015-04-08 21:02:04 +000024
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000025 # Add additional plugin path
26 push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin');
27
Nils Diewalda79b2682015-05-18 18:34:06 +000028 # korap.ids-mannheim.de specific path prefixing
Nils Diewalda0defc42015-05-07 23:54:17 +000029 $self->hook(
30 before_dispatch => sub {
31 my $c = shift;
32 my $host = $c->req->headers->header('X-Forwarded-Host');
33 if ($host && $host eq 'korap.ids-mannheim.de') {
34 $c->req->url->base->path('/kalamar/');
Nils Diewald705b74a2015-05-07 23:57:34 +000035 $c->stash(prefix => '/kalamar');
Nils Diewalda0defc42015-05-07 23:54:17 +000036 };
37 }) if $self->mode eq 'production';
38
Nils Diewalda748b0e2015-05-19 22:54:06 +000039
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000040 # Set secrets for signed cookies
Nils Diewald19402142015-04-30 15:44:52 +000041 if (-e (my $secret = $self->home . '/kalamar.secret')) {
Nils Diewalda79b2682015-05-18 18:34:06 +000042
43 # Load file and split lines for multiple secrets
44 $self->secrets([b($secret)->slurp->split("\n")]);
Nils Diewald4347ee92015-05-04 20:32:48 +000045 }
Nils Diewald709f52f2015-05-21 18:32:58 +000046
47 # File not found ...
48 # Kalamar needs secrets in a file to be easily deployable
49 # and publishable at the same time.
Nils Diewald4347ee92015-05-04 20:32:48 +000050 else {
51 $self->log->warn('Please create a kalamar.secret file');
Nils Diewald19402142015-04-30 15:44:52 +000052 };
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000053
Nils Diewald709f52f2015-05-21 18:32:58 +000054
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000055 # Load plugins
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000056 foreach (
Nils Diewaldc46003b2015-05-07 15:55:35 +000057 'Config', # Configuration framework
58 'Localize', # Localization framework
59 'Notifications', # Client notifications
60 'Search', # Abstract Search framework
61 'CHI', # Global caching mechanism
62 'TagHelpers::Pagination', # Pagination widget
63 'TagHelpers::MailToChiffre', # Obfuscate email addresses
Nils Diewalda79b2682015-05-18 18:34:06 +000064 'KalamarHelpers', # Specific Helpers for Kalamar
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000065 ) {
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000066 $self->plugin($_);
67 };
68
Nils Diewald709f52f2015-05-21 18:32:58 +000069
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000070 # Configure mail exception
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000071 $self->plugin('MailException' => $self->config('MailException'));
72
Nils Diewald709f52f2015-05-21 18:32:58 +000073
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000074 # Configure documentation navigation
Nils Diewald7148c6f2015-05-04 15:07:53 +000075 my $navi = b($self->home . '/templates/doc/navigation.json')->slurp;
76 $self->config(navi => decode_json($navi)) if $navi;
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000077
Nils Diewald709f52f2015-05-21 18:32:58 +000078
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000079 # Establish routes
80 my $r = $self->routes;
81
Nils Diewalda79b2682015-05-18 18:34:06 +000082 # Base query route
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000083 $r->get('/')->to('search#query')->name('index');
84
Nils Diewalda79b2682015-05-18 18:34:06 +000085 # Documentation routes
Nils Diewald7148c6f2015-05-04 15:07:53 +000086 $r->get('/doc')->to('documentation#page', page => 'korap')->name('doc_start');
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000087 $r->get('/doc/:page')->to('documentation#page', scope => undef);
88 $r->get('/doc/*scope/:page')->to('documentation#page')->name('doc');
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000089
Nils Diewaldc46003b2015-05-07 15:55:35 +000090 # Contact route
91 $r->get('/contact')->to('documentation#contact');
92 $r->get('/contact')->mail_to_chiffre('documentation#contact');
93
Nils Diewald7148c6f2015-05-04 15:07:53 +000094 # Match route
Nils Diewald8f4b5da2014-12-03 22:13:39 +000095 my $corpus = $r->route('/corpus/:corpus_id');
Nils Diewald7148c6f2015-05-04 15:07:53 +000096 my $doc = $corpus->get('/:doc_id');
97 my $text = $doc->get('/:text_id');
98 my $match = $text->get('/:match_id');
99 $match->to('search#match_info')->name('match');
Nils Diewald996aa552014-12-02 03:26:44 +0000100};
101
102
1031;
104
105
106__END__
Nils Diewalda898dac2015-05-06 21:04:16 +0000107
108=pod
109
Nils Diewaldeb5f3072015-05-20 09:32:42 +0000110=encoding utf8
Nils Diewalda898dac2015-05-06 21:04:16 +0000111
Nils Diewaldeb5f3072015-05-20 09:32:42 +0000112=head1 NAME
113
114Kalamar
Nils Diewalda0defc42015-05-07 23:54:17 +0000115
116
Nils Diewaldeb5f3072015-05-20 09:32:42 +0000117=head1 DESCRIPTION
Nils Diewalda0defc42015-05-07 23:54:17 +0000118
Nils Diewaldeb5f3072015-05-20 09:32:42 +0000119L<Kalamar> is a L<Mojolicious|http://mojolicio.us/> based user interface
120frontend for the L<KorAP Corpus Analysis Platform|http://korap.ids-mannheim.de/>.
121
122=head1 INSTALLATION
123
124=head2 Generate Static Asset Files
125
126To generate the static asset files (scripts, styles, images ...),
Nils Diewald709f52f2015-05-21 18:32:58 +0000127you need NodeJS E<gt> 0.8. This will probably need administration
128rights.
Nils Diewaldeb5f3072015-05-20 09:32:42 +0000129
Nils Diewaldeb5f3072015-05-20 09:32:42 +0000130 $ npm install
131 $ grunt
Nils Diewald652e5f42015-05-10 18:11:45 +0000132
Nils Diewaldeb5f3072015-05-20 09:32:42 +0000133=head2 Start Server
Nils Diewald652e5f42015-05-10 18:11:45 +0000134
Nils Diewaldeb5f3072015-05-20 09:32:42 +0000135Kalamar uses the L<Mojolicious|http://mojolicio.us/> framework,
136that expects a Perl version of at least 5.10.1.
137The recommended environment is based on L<Perlbrew|http://perlbrew.pl/>
138with L<App::cpanminus>.
139
Nils Diewald709f52f2015-05-21 18:32:58 +0000140Some perl modules are not on CPAN yet, so you need to install them from GitHub.
141The easiest way to do this is using L<App:cpanminus>.
142This will probably need administration rights.
Nils Diewaldeb5f3072015-05-20 09:32:42 +0000143
144 $ cpanm git://github.com/Akron/Mojolicious-Plugin-Search.git
Nils Diewald709f52f2015-05-21 18:32:58 +0000145 $ cpanm --force git://github.com/Akron/Mojolicious-Plugin-Localize.git
146
147Then install the dependencies as always and run the test suite.
148There is no need to install Kalamar on your system.
149
Nils Diewaldeb5f3072015-05-20 09:32:42 +0000150 $ perl Makefile.PL
151 $ make test
152
153Kalamar can be deployed like all
154L<Mojolicious apps|http://mojolicio.us/perldoc/Mojolicious/Guides/Cookbook#DEPLOYMENT>.
155The easiest way is to start the built-in server:
156
Nils Diewald709f52f2015-05-21 18:32:58 +0000157 $ perl script/kalamar daemon
158
159Kalamar will then be available at C<localhost:3000> in your browser.
Nils Diewalda748b0e2015-05-19 22:54:06 +0000160
161
162=head1 COPYRIGHT AND LICENSE
163
164=head2 Bundled Software
165
Nils Diewald023c6712015-05-21 20:12:30 +0000166L<ALERTIFY.js|https://fabien-d.github.io/alertify.js/> is released under the terms of the MIT License.
167L<Almond|https://github.com/jrburke/almond> is released under the terms of the BSD License.
168L<dagre|https://highlightjs.org/> is released under the terms
169of the MIT License.
170L<Highlight.js|https://highlightjs.org/> is released under the terms
171of the BSD License.
172L<Jasmine|https://jasmine.github.io/> is released under the terms
173of the MIT License.
174L<RequireJS|http://requirejs.org/> is released under the terms
175of the BSD License.
176L<Font Awesome|http://fontawesome.io> by Dave Gandy
177is released under the terms of the L<SIL OFL 1.1|http://scripts.sil.org/OFL>.
Nils Diewalda748b0e2015-05-19 22:54:06 +0000178
179
180=head2 Original Software
181
182Copyright (C) 2015, L<IDS Mannheim|http://www.ids-mannheim.de/>
183Author: L<Nils Diewald|http://nils-diewald.de/>
184
185Kalamar is developed as part of the L<KorAP|http://korap.ids-mannheim.de/>
186Corpus Analysis Platform at the
187L<Institute for the German Language (IDS)|http://ids-mannheim.de/>,
188member of the
189L<Leibniz-Gemeinschaft|http://www.leibniz-gemeinschaft.de/en/about-us/leibniz-competition/projekte-2011/2011-funding-line-2/>
190and supported by the L<KobRA|http://www.kobra.tu-dortmund.de> project,
191funded by the
192L<Federal Ministry of Education and Research (BMBF)|http://www.bmbf.de/en/>.
193
194Kalamar is free software published under the
195L<BSD-2 License|https://raw.githubusercontent.com/KorAP/Kalamar/master/LICENSE).
196
197=cut