blob: f465802b40540f18f3b05182daaa8e287731ae47 [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 Diewalda944fab2015-04-08 21:02:04 +00006our $VERSION;
Nils Diewald7cad8402014-07-08 17:06:56 +00007
Nils Diewald002e8fb2014-06-22 14:27:01 +00008# Start the application and register all routes and plugins
Nils Diewald5d1ffb42014-05-21 17:45:34 +00009sub startup {
10 my $self = shift;
11
Nils Diewalda944fab2015-04-08 21:02:04 +000012 # Set version based on package file
13 my $pkg = b($self->home . '/package.json')->slurp;
14 $Kalamar::VERSION = decode_json($pkg)->{version};
15
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000016 # Add additional plugin path
17 push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin');
18
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000019 # Set secrets for signed cookies
20 $self->secrets([
21 b($self->home . '/kalamar.secret')->slurp->split("\n")
22 ]);
23
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000024 # Load plugins
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000025 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 Diewaldab4d3ca2015-04-17 01:48:43 +000036 $self->plugin($_);
37 };
38
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000039 # Configure mail exception
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000040 $self->plugin('MailException' => $self->config('MailException'));
41
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000042 # Configure documentation navigation
43 my $navi = b($self->home . '/templates/doc/_nav.json')->slurp;
44 $self->config(navi => decode_json($navi));
45
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000046 # Establish routes
47 my $r = $self->routes;
48
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000049 # Base query page
50 $r->get('/')->to('search#query')->name('index');
51
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000052 # 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
591;
60
61
62__END__
63
64
Nils Diewald2fe12e12015-03-06 16:47:06 +000065 # Set default totle
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000066# $self->defaults(
67# layout => 'main',
68# title => 'KorAP - Corpus Analysis Platform'
69# );
Nils Diewald7cad8402014-07-08 17:06:56 +000070
Nils Diewald33e15552014-06-13 19:38:37 +000071
Nils Diewalda944fab2015-04-08 21:02:04 +000072 $self->hook(
73 before_dispatch => sub {
Nils Diewald8462c182015-03-10 20:57:55 +000074 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 Diewalda944fab2015-04-08 21:02:04 +000079 }) if $self->mode eq 'production';
Nils Diewald8462c182015-03-10 20:57:55 +000080
Nils Diewald44e1edb2015-04-08 19:12:15 +000081
Nils Diewald002e8fb2014-06-22 14:27:01 +000082
83 # Load plugins
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000084 foreach (qw/
Nils Diewald002e8fb2014-06-22 14:27:01 +000085 Number::Commify
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000086 /) {
Nils Diewald002e8fb2014-06-22 14:27:01 +000087 $self->plugin($_);
88 };
Nils Diewald2329e1d2014-06-12 16:07:57 +000089
Nils Diewald2fe12e12015-03-06 16:47:06 +000090 # $self->plugin(AssetPack => { minify => 1 });
Nils Diewald996aa552014-12-02 03:26:44 +000091 $self->plugin('AssetPack');
Nils Diewald7cad8402014-07-08 17:06:56 +000092 $self->plugin('AssetPack::LibSass');
93
Nils Diewald94bae912014-09-22 13:40:31 +000094 # Add assets for AssetPack
Nils Diewald7cad8402014-07-08 17:06:56 +000095 $self->asset(
Nils Diewald2fe12e12015-03-06 16:47:06 +000096 'kalamar.css' => (
97
98 # Sass files
Nils Diewald7cad8402014-07-08 17:06:56 +000099 '/sass/style.scss',
100 '/sass/sidebar.scss',
101 '/sass/tutorial.scss',
102 '/sass/hint.scss',
103 '/sass/query.scss',
Nils Diewaldf2e02a92014-11-12 18:31:05 +0000104 '/sass/matchinfo.scss',
Nils Diewald7cad8402014-07-08 17:06:56 +0000105 '/sass/pagination.scss',
106 '/sass/kwic-4.0.scss',
Nils Diewald2fe12e12015-03-06 16:47:06 +0000107 '/sass/alertify.scss',
108
109 # CSS files
Nils Diewald7cad8402014-07-08 17:06:56 +0000110 '/css/font-awesome.min.css',
Nils Diewald3d871842015-03-10 23:14:34 +0000111 '/css/media.css',
Nils Diewaldca01b762014-09-08 02:35:20 +0000112 '/css/highlight.css',
Nils Diewaldca01b762014-09-08 02:35:20 +0000113 $self->notifications->styles
Nils Diewald7cad8402014-07-08 17:06:56 +0000114 )
115 );
116
117 $self->asset(
Nils Diewald2fe12e12015-03-06 16:47:06 +0000118 'kalamar.js' => (
Nils Diewald8f4b5da2014-12-03 22:13:39 +0000119# '/js/d3.v3.min.js',
Nils Diewaldf2e02a92014-11-12 18:31:05 +0000120# '/js/dagre-d3.min.js',
Nils Diewald8f4b5da2014-12-03 22:13:39 +0000121# '/js/dagre-d3.js',
122# '/js/translateTree.js',
Nils Diewald4e9fbcb2014-07-15 11:45:09 +0000123 '/js/tutorialCookie.js',
Nils Diewald7cad8402014-07-08 17:06:56 +0000124 '/js/translateTable.js',
125 '/js/hint.js',
Nils Diewaldca01b762014-09-08 02:35:20 +0000126 '/js/highlight.pack.js',
Nils Diewalde99d9042014-11-20 23:36:54 +0000127 '/js/ajax.js',
Nils Diewaldca01b762014-09-08 02:35:20 +0000128 $self->notifications->scripts
Nils Diewald7cad8402014-07-08 17:06:56 +0000129 )
130 );
Nils Diewald4af3f0b2014-06-25 01:43:17 +0000131
Nils Diewald89d88012015-03-10 21:03:36 +0000132 $self->helper(
133 date_format => sub {
134 my ($c, $date) = @_;
135 return $date;
136 }
137 );
Nils Diewald2329e1d2014-06-12 16:07:57 +0000138
Nils Diewald5d1ffb42014-05-21 17:45:34 +0000139
Nils Diewald002e8fb2014-06-22 14:27:01 +0000140 # Base search route
Nils Diewald8f4b5da2014-12-03 22:13:39 +0000141 $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 Diewald2fe12e12015-03-06 16:47:06 +0000146 my $match = $doc->route('/:match_id')
147 ->to('search#match_info')
148 ->name('match');
Nils Diewald33e15552014-06-13 19:38:37 +0000149
Nils Diewald002e8fb2014-06-22 14:27:01 +0000150 # Tutorial data
Nils Diewald4e9fbcb2014-07-15 11:45:09 +0000151 $r->get('/tutorial')->to('tutorial#page', tutorial => 'index');
152 $r->get('/tutorial/(*tutorial)')->to('tutorial#page')->name('tutorial');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000153
Nils Diewald7c8ced22015-04-15 19:21:00 +0000154
155 # Todo: The FAQ-Page has a contact form for new questions
Nils Diewald996aa552014-12-02 03:26:44 +0000156};
157
158
1591;
160
161
162__END__