blob: f310cbf4782d7a3d64eb318880ebd92f177cf64f [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 Diewald5d1ffb42014-05-21 17:45:34 +00004
Nils Diewalda297f062015-04-02 00:23:46 +00005our $VERSION = '0.14';
Nils Diewald7cad8402014-07-08 17:06:56 +00006
Nils Diewald002e8fb2014-06-22 14:27:01 +00007# Start the application and register all routes and plugins
Nils Diewald5d1ffb42014-05-21 17:45:34 +00008sub startup {
9 my $self = shift;
10
Nils Diewald2fe12e12015-03-06 16:47:06 +000011 # Set default totle
12 $self->defaults(
13 layout => 'default',
Nils Diewaldd2b57372015-03-10 20:09:48 +000014 title => 'KorAP - Corpus Analysis Platform'
Nils Diewald2fe12e12015-03-06 16:47:06 +000015 );
Nils Diewald7cad8402014-07-08 17:06:56 +000016
Nils Diewald002e8fb2014-06-22 14:27:01 +000017 # Set secret for signed cookies
Nils Diewald2fe12e12015-03-06 16:47:06 +000018 $self->secrets([
19 b($self->home . '/kalamar.secret')->slurp->split("\n")
20 ]);
Nils Diewald33e15552014-06-13 19:38:37 +000021
Nils Diewald8462c182015-03-10 20:57:55 +000022 $self->hook(before_dispatch => sub {
23 my $c = shift;
24 my $host = $c->req->headers->header('X-Forwarded-Host');
25 if ($host && $host eq 'korap.ids-mannheim.de') {
26 $c->req->url->base->path('/kalamar/');
27 };
28 }) if $self->mode eq 'production';
29
Nils Diewald002e8fb2014-06-22 14:27:01 +000030 # Add additional plugin path
Nils Diewald5d1ffb42014-05-21 17:45:34 +000031 push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin');
Nils Diewald002e8fb2014-06-22 14:27:01 +000032
33 # Load plugins
34 foreach (qw/Config
35 CHI
36 TagHelpers::Pagination
37 Notifications
38 Number::Commify
Nils Diewald996aa552014-12-02 03:26:44 +000039 Search
Nils Diewald2fe12e12015-03-06 16:47:06 +000040 KalamarHelpers
41 KalamarTagHelpers/) {
Nils Diewald002e8fb2014-06-22 14:27:01 +000042 $self->plugin($_);
43 };
Nils Diewald2329e1d2014-06-12 16:07:57 +000044
Nils Diewald2fe12e12015-03-06 16:47:06 +000045 # $self->plugin(AssetPack => { minify => 1 });
Nils Diewald996aa552014-12-02 03:26:44 +000046 $self->plugin('AssetPack');
Nils Diewald7cad8402014-07-08 17:06:56 +000047 $self->plugin('AssetPack::LibSass');
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000048 $self->plugin('MailException' => $self->config('MailException'));
Nils Diewald7cad8402014-07-08 17:06:56 +000049
Nils Diewald94bae912014-09-22 13:40:31 +000050 # Add assets for AssetPack
Nils Diewald7cad8402014-07-08 17:06:56 +000051 $self->asset(
Nils Diewald2fe12e12015-03-06 16:47:06 +000052 'kalamar.css' => (
53
54 # Sass files
Nils Diewald7cad8402014-07-08 17:06:56 +000055 '/sass/style.scss',
56 '/sass/sidebar.scss',
57 '/sass/tutorial.scss',
58 '/sass/hint.scss',
59 '/sass/query.scss',
Nils Diewaldf2e02a92014-11-12 18:31:05 +000060 '/sass/matchinfo.scss',
Nils Diewald7cad8402014-07-08 17:06:56 +000061 '/sass/pagination.scss',
62 '/sass/kwic-4.0.scss',
Nils Diewald2fe12e12015-03-06 16:47:06 +000063 '/sass/alertify.scss',
64
65 # CSS files
Nils Diewald7cad8402014-07-08 17:06:56 +000066 '/css/font-awesome.min.css',
Nils Diewald3d871842015-03-10 23:14:34 +000067 '/css/media.css',
Nils Diewaldca01b762014-09-08 02:35:20 +000068 '/css/highlight.css',
Nils Diewaldca01b762014-09-08 02:35:20 +000069 $self->notifications->styles
Nils Diewald7cad8402014-07-08 17:06:56 +000070 )
71 );
72
73 $self->asset(
Nils Diewald2fe12e12015-03-06 16:47:06 +000074 'kalamar.js' => (
Nils Diewald8f4b5da2014-12-03 22:13:39 +000075# '/js/d3.v3.min.js',
Nils Diewaldf2e02a92014-11-12 18:31:05 +000076# '/js/dagre-d3.min.js',
Nils Diewald8f4b5da2014-12-03 22:13:39 +000077# '/js/dagre-d3.js',
78# '/js/translateTree.js',
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000079 '/js/tutorialCookie.js',
Nils Diewald7cad8402014-07-08 17:06:56 +000080 '/js/translateTable.js',
81 '/js/hint.js',
Nils Diewaldca01b762014-09-08 02:35:20 +000082 '/js/highlight.pack.js',
Nils Diewalde99d9042014-11-20 23:36:54 +000083 '/js/ajax.js',
Nils Diewaldca01b762014-09-08 02:35:20 +000084 $self->notifications->scripts
Nils Diewald7cad8402014-07-08 17:06:56 +000085 )
86 );
Nils Diewald4af3f0b2014-06-25 01:43:17 +000087
Nils Diewald89d88012015-03-10 21:03:36 +000088 $self->helper(
89 date_format => sub {
90 my ($c, $date) = @_;
91 return $date;
92 }
93 );
Nils Diewald2329e1d2014-06-12 16:07:57 +000094
Nils Diewald64bab252014-05-22 11:04:04 +000095 # Routes
Nils Diewald5d1ffb42014-05-21 17:45:34 +000096 my $r = $self->routes;
97
Nils Diewald002e8fb2014-06-22 14:27:01 +000098 # Base search route
Nils Diewald8f4b5da2014-12-03 22:13:39 +000099 $r->get('/')->to('search#query')->name('index');
100
101 # Get match information
102 my $corpus = $r->route('/corpus/:corpus_id');
103 my $doc = $corpus->route('/#doc_id');
Nils Diewald2fe12e12015-03-06 16:47:06 +0000104 my $match = $doc->route('/:match_id')
105 ->to('search#match_info')
106 ->name('match');
Nils Diewald33e15552014-06-13 19:38:37 +0000107
Nils Diewald002e8fb2014-06-22 14:27:01 +0000108 # Tutorial data
Nils Diewald4e9fbcb2014-07-15 11:45:09 +0000109 $r->get('/tutorial')->to('tutorial#page', tutorial => 'index');
110 $r->get('/tutorial/(*tutorial)')->to('tutorial#page')->name('tutorial');
Nils Diewald996aa552014-12-02 03:26:44 +0000111};
112
113
1141;
115
116
117__END__