blob: d05257eb2af01fd5bdc519593d7fdfea04061787 [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
Nils Diewald19402142015-04-30 15:44:52 +000020 if (-e (my $secret = $self->home . '/kalamar.secret')) {
21 $self->secrets([
22 b($secret)->slurp->split("\n")
23 ]);
24 };
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000025
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000026 # Load plugins
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000027 foreach (
28 'Config', # Configuration framework
29 'Localize', # Localization framework
30 'Notifications', # Client notifications
31 'Search', # Abstract Search framework
32 'CHI', # Global caching mechanism
33 'TagHelpers::Pagination', # Pagination widget
34 'DocNavi', # Navigation for documentation
35 'KalamarHelpers', # Specific Helpers for Kalamar
36 'KalamarTagHelpers' # Specific Taghelpers for Kalamar
37 ) {
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000038 $self->plugin($_);
39 };
40
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000041 # Configure mail exception
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000042 $self->plugin('MailException' => $self->config('MailException'));
43
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000044 # Configure documentation navigation
45 my $navi = b($self->home . '/templates/doc/_nav.json')->slurp;
46 $self->config(navi => decode_json($navi));
47
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000048 # Establish routes
49 my $r = $self->routes;
50
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000051 # Base query page
52 $r->get('/')->to('search#query')->name('index');
53
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000054 # Documentation
55 $r->get('/doc')->to('documentation#page', page => 'korap');
56 $r->get('/doc/:page')->to('documentation#page', scope => undef);
57 $r->get('/doc/*scope/:page')->to('documentation#page')->name('doc');
58};
59
60
611;
62
63
64__END__
65
66
Nils Diewald2fe12e12015-03-06 16:47:06 +000067 # Set default totle
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000068# $self->defaults(
69# layout => 'main',
70# title => 'KorAP - Corpus Analysis Platform'
71# );
Nils Diewald7cad8402014-07-08 17:06:56 +000072
Nils Diewald33e15552014-06-13 19:38:37 +000073
Nils Diewalda944fab2015-04-08 21:02:04 +000074 $self->hook(
75 before_dispatch => sub {
Nils Diewald8462c182015-03-10 20:57:55 +000076 my $c = shift;
77 my $host = $c->req->headers->header('X-Forwarded-Host');
78 if ($host && $host eq 'korap.ids-mannheim.de') {
79 $c->req->url->base->path('/kalamar/');
80 };
Nils Diewalda944fab2015-04-08 21:02:04 +000081 }) if $self->mode eq 'production';
Nils Diewald8462c182015-03-10 20:57:55 +000082
Nils Diewald44e1edb2015-04-08 19:12:15 +000083
Nils Diewald002e8fb2014-06-22 14:27:01 +000084
85 # Load plugins
Nils Diewaldfccfbcb2015-04-29 20:48:19 +000086 foreach (qw/
Nils Diewald002e8fb2014-06-22 14:27:01 +000087 Number::Commify
Nils Diewaldab4d3ca2015-04-17 01:48:43 +000088 /) {
Nils Diewald002e8fb2014-06-22 14:27:01 +000089 $self->plugin($_);
90 };
Nils Diewald2329e1d2014-06-12 16:07:57 +000091
Nils Diewald2fe12e12015-03-06 16:47:06 +000092 # $self->plugin(AssetPack => { minify => 1 });
Nils Diewald996aa552014-12-02 03:26:44 +000093 $self->plugin('AssetPack');
Nils Diewald7cad8402014-07-08 17:06:56 +000094 $self->plugin('AssetPack::LibSass');
95
Nils Diewald94bae912014-09-22 13:40:31 +000096 # Add assets for AssetPack
Nils Diewald7cad8402014-07-08 17:06:56 +000097 $self->asset(
Nils Diewald2fe12e12015-03-06 16:47:06 +000098 'kalamar.css' => (
99
100 # Sass files
Nils Diewald7cad8402014-07-08 17:06:56 +0000101 '/sass/style.scss',
102 '/sass/sidebar.scss',
103 '/sass/tutorial.scss',
104 '/sass/hint.scss',
105 '/sass/query.scss',
Nils Diewaldf2e02a92014-11-12 18:31:05 +0000106 '/sass/matchinfo.scss',
Nils Diewald7cad8402014-07-08 17:06:56 +0000107 '/sass/pagination.scss',
108 '/sass/kwic-4.0.scss',
Nils Diewald2fe12e12015-03-06 16:47:06 +0000109 '/sass/alertify.scss',
110
111 # CSS files
Nils Diewald7cad8402014-07-08 17:06:56 +0000112 '/css/font-awesome.min.css',
Nils Diewald3d871842015-03-10 23:14:34 +0000113 '/css/media.css',
Nils Diewaldca01b762014-09-08 02:35:20 +0000114 '/css/highlight.css',
Nils Diewaldca01b762014-09-08 02:35:20 +0000115 $self->notifications->styles
Nils Diewald7cad8402014-07-08 17:06:56 +0000116 )
117 );
118
119 $self->asset(
Nils Diewald2fe12e12015-03-06 16:47:06 +0000120 'kalamar.js' => (
Nils Diewald8f4b5da2014-12-03 22:13:39 +0000121# '/js/d3.v3.min.js',
Nils Diewaldf2e02a92014-11-12 18:31:05 +0000122# '/js/dagre-d3.min.js',
Nils Diewald8f4b5da2014-12-03 22:13:39 +0000123# '/js/dagre-d3.js',
124# '/js/translateTree.js',
Nils Diewald4e9fbcb2014-07-15 11:45:09 +0000125 '/js/tutorialCookie.js',
Nils Diewald7cad8402014-07-08 17:06:56 +0000126 '/js/translateTable.js',
127 '/js/hint.js',
Nils Diewaldca01b762014-09-08 02:35:20 +0000128 '/js/highlight.pack.js',
Nils Diewalde99d9042014-11-20 23:36:54 +0000129 '/js/ajax.js',
Nils Diewaldca01b762014-09-08 02:35:20 +0000130 $self->notifications->scripts
Nils Diewald7cad8402014-07-08 17:06:56 +0000131 )
132 );
Nils Diewald4af3f0b2014-06-25 01:43:17 +0000133
Nils Diewald89d88012015-03-10 21:03:36 +0000134 $self->helper(
135 date_format => sub {
136 my ($c, $date) = @_;
137 return $date;
138 }
139 );
Nils Diewald2329e1d2014-06-12 16:07:57 +0000140
Nils Diewald5d1ffb42014-05-21 17:45:34 +0000141
Nils Diewald002e8fb2014-06-22 14:27:01 +0000142 # Base search route
Nils Diewald8f4b5da2014-12-03 22:13:39 +0000143 $r->get('/')->to('search#query')->name('index');
144
145 # Get match information
146 my $corpus = $r->route('/corpus/:corpus_id');
147 my $doc = $corpus->route('/#doc_id');
Nils Diewald2fe12e12015-03-06 16:47:06 +0000148 my $match = $doc->route('/:match_id')
149 ->to('search#match_info')
150 ->name('match');
Nils Diewald33e15552014-06-13 19:38:37 +0000151
Nils Diewald002e8fb2014-06-22 14:27:01 +0000152 # Tutorial data
Nils Diewald4e9fbcb2014-07-15 11:45:09 +0000153 $r->get('/tutorial')->to('tutorial#page', tutorial => 'index');
154 $r->get('/tutorial/(*tutorial)')->to('tutorial#page')->name('tutorial');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000155
Nils Diewald7c8ced22015-04-15 19:21:00 +0000156
157 # Todo: The FAQ-Page has a contact form for new questions
Nils Diewald996aa552014-12-02 03:26:44 +0000158};
159
160
1611;
162
163
164__END__