blob: e3f0d31dd2e6ae01de6979264a7579cd19e75260 [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 Diewald25a86442015-03-04 19:56:39 +00005our $VERSION = '0.13';
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 Diewald002e8fb2014-06-22 14:27:01 +000022 # Add additional plugin path
Nils Diewald5d1ffb42014-05-21 17:45:34 +000023 push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin');
Nils Diewald002e8fb2014-06-22 14:27:01 +000024
25 # Load plugins
26 foreach (qw/Config
27 CHI
28 TagHelpers::Pagination
29 Notifications
30 Number::Commify
Nils Diewald996aa552014-12-02 03:26:44 +000031 Search
Nils Diewald2fe12e12015-03-06 16:47:06 +000032 KalamarHelpers
33 KalamarTagHelpers/) {
Nils Diewald002e8fb2014-06-22 14:27:01 +000034 $self->plugin($_);
35 };
Nils Diewald2329e1d2014-06-12 16:07:57 +000036
Nils Diewald2fe12e12015-03-06 16:47:06 +000037 # $self->plugin(AssetPack => { minify => 1 });
Nils Diewald996aa552014-12-02 03:26:44 +000038 $self->plugin('AssetPack');
Nils Diewald7cad8402014-07-08 17:06:56 +000039 $self->plugin('AssetPack::LibSass');
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000040 $self->plugin('MailException' => $self->config('MailException'));
Nils Diewald7cad8402014-07-08 17:06:56 +000041
Nils Diewald94bae912014-09-22 13:40:31 +000042 # Add assets for AssetPack
Nils Diewald7cad8402014-07-08 17:06:56 +000043 $self->asset(
Nils Diewald2fe12e12015-03-06 16:47:06 +000044 'kalamar.css' => (
45
46 # Sass files
Nils Diewald7cad8402014-07-08 17:06:56 +000047 '/sass/style.scss',
48 '/sass/sidebar.scss',
49 '/sass/tutorial.scss',
50 '/sass/hint.scss',
51 '/sass/query.scss',
Nils Diewaldf2e02a92014-11-12 18:31:05 +000052 '/sass/matchinfo.scss',
Nils Diewald7cad8402014-07-08 17:06:56 +000053 '/sass/pagination.scss',
54 '/sass/kwic-4.0.scss',
Nils Diewald2fe12e12015-03-06 16:47:06 +000055 '/sass/alertify.scss',
56
57 # CSS files
Nils Diewald7cad8402014-07-08 17:06:56 +000058 '/css/media.css',
59 '/css/font-awesome.min.css',
Nils Diewaldca01b762014-09-08 02:35:20 +000060 '/css/highlight.css',
Nils Diewaldca01b762014-09-08 02:35:20 +000061 $self->notifications->styles
Nils Diewald7cad8402014-07-08 17:06:56 +000062 )
63 );
64
65 $self->asset(
Nils Diewald2fe12e12015-03-06 16:47:06 +000066 'kalamar.js' => (
Nils Diewald8f4b5da2014-12-03 22:13:39 +000067# '/js/d3.v3.min.js',
Nils Diewaldf2e02a92014-11-12 18:31:05 +000068# '/js/dagre-d3.min.js',
Nils Diewald8f4b5da2014-12-03 22:13:39 +000069# '/js/dagre-d3.js',
70# '/js/translateTree.js',
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000071 '/js/tutorialCookie.js',
Nils Diewald7cad8402014-07-08 17:06:56 +000072 '/js/translateTable.js',
73 '/js/hint.js',
Nils Diewaldca01b762014-09-08 02:35:20 +000074 '/js/highlight.pack.js',
Nils Diewalde99d9042014-11-20 23:36:54 +000075 '/js/ajax.js',
Nils Diewaldca01b762014-09-08 02:35:20 +000076 $self->notifications->scripts
Nils Diewald7cad8402014-07-08 17:06:56 +000077 )
78 );
Nils Diewald4af3f0b2014-06-25 01:43:17 +000079
Nils Diewald2fe12e12015-03-06 16:47:06 +000080 # $self->helper(
81 # date_format => sub {
82 # my ($c, $date) = @_;
83 # return $date;
84 # }
85 # );
Nils Diewald2329e1d2014-06-12 16:07:57 +000086
Nils Diewald64bab252014-05-22 11:04:04 +000087 # Routes
Nils Diewald5d1ffb42014-05-21 17:45:34 +000088 my $r = $self->routes;
89
Nils Diewald002e8fb2014-06-22 14:27:01 +000090 # Base search route
Nils Diewald8f4b5da2014-12-03 22:13:39 +000091 $r->get('/')->to('search#query')->name('index');
92
93 # Get match information
94 my $corpus = $r->route('/corpus/:corpus_id');
95 my $doc = $corpus->route('/#doc_id');
Nils Diewald2fe12e12015-03-06 16:47:06 +000096 my $match = $doc->route('/:match_id')
97 ->to('search#match_info')
98 ->name('match');
Nils Diewald33e15552014-06-13 19:38:37 +000099
Nils Diewald002e8fb2014-06-22 14:27:01 +0000100 # Tutorial data
Nils Diewald4e9fbcb2014-07-15 11:45:09 +0000101 $r->get('/tutorial')->to('tutorial#page', tutorial => 'index');
102 $r->get('/tutorial/(*tutorial)')->to('tutorial#page')->name('tutorial');
Nils Diewald996aa552014-12-02 03:26:44 +0000103};
104
105
1061;
107
108
109__END__