blob: 93463753dbab97d1b4cc14a7d7ed6b11c4246386 [file] [log] [blame]
Nils Diewald5d1ffb42014-05-21 17:45:34 +00001package Korap;
2use Mojo::Base 'Mojolicious';
Nils Diewalde2c83812014-11-11 21:13:18 +00003use Mojo::ByteStream 'b';
Nils Diewald5d1ffb42014-05-21 17:45:34 +00004
Nils Diewald46e6f182015-02-04 15:22:49 +00005our $VERSION = '0.12';
Nils Diewald7cad8402014-07-08 17:06:56 +00006
7# Start dev with
Nils Diewaldf7366232014-07-25 15:57:08 +00008# morbo -w lib -w templates -w public/sass -w public/js -w public/css script/korap
Nils Diewaldeca30442014-11-18 20:33:54 +00009# morbo -m test -w lib -w templates -w public/sass -w public/js -w public/css script/korap
Nils Diewaldf7366232014-07-25 15:57:08 +000010
Nils Diewald002e8fb2014-06-22 14:27:01 +000011# Start the application and register all routes and plugins
Nils Diewald5d1ffb42014-05-21 17:45:34 +000012sub startup {
13 my $self = shift;
14
Nils Diewald7cad8402014-07-08 17:06:56 +000015 $self->defaults(layout => 'default');
16
Nils Diewald002e8fb2014-06-22 14:27:01 +000017 # Set secret for signed cookies
Nils Diewald33e15552014-06-13 19:38:37 +000018 $self->secrets(['fmhsfjgfchgsdbfgshfxztsbt32477eb45veu4vubrghfgghbtv']);
19
Nils Diewald002e8fb2014-06-22 14:27:01 +000020 # Add additional plugin path
Nils Diewald5d1ffb42014-05-21 17:45:34 +000021 push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin');
Nils Diewald002e8fb2014-06-22 14:27:01 +000022
23 # Load plugins
24 foreach (qw/Config
25 CHI
26 TagHelpers::Pagination
27 Notifications
28 Number::Commify
Nils Diewald996aa552014-12-02 03:26:44 +000029 Search
Nils Diewald996aa552014-12-02 03:26:44 +000030 KorapHelpers
Nils Diewald7cad8402014-07-08 17:06:56 +000031 KorapTagHelpers
Nils Diewald94bae912014-09-22 13:40:31 +000032 /) {
Nils Diewald002e8fb2014-06-22 14:27:01 +000033 $self->plugin($_);
34 };
Nils Diewald2329e1d2014-06-12 16:07:57 +000035
Nils Diewald996aa552014-12-02 03:26:44 +000036# $self->plugin(AssetPack => { minify => 1 });
37 $self->plugin('AssetPack');
Nils Diewald7cad8402014-07-08 17:06:56 +000038 $self->plugin('AssetPack::LibSass');
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000039 $self->plugin('MailException' => $self->config('MailException'));
Nils Diewald7cad8402014-07-08 17:06:56 +000040
Nils Diewald94bae912014-09-22 13:40:31 +000041 # Add assets for AssetPack
Nils Diewald7cad8402014-07-08 17:06:56 +000042 $self->asset(
43 'korap.css' => (
44 '/sass/style.scss',
45 '/sass/sidebar.scss',
46 '/sass/tutorial.scss',
47 '/sass/hint.scss',
48 '/sass/query.scss',
Nils Diewaldf2e02a92014-11-12 18:31:05 +000049 '/sass/matchinfo.scss',
Nils Diewald7cad8402014-07-08 17:06:56 +000050 '/sass/pagination.scss',
51 '/sass/kwic-4.0.scss',
52 '/css/media.css',
53 '/css/font-awesome.min.css',
Nils Diewaldca01b762014-09-08 02:35:20 +000054 '/css/highlight.css',
Nils Diewald063a7c42014-11-12 20:11:55 +000055 '/sass/alertify.scss',
Nils Diewaldca01b762014-09-08 02:35:20 +000056 $self->notifications->styles
Nils Diewald7cad8402014-07-08 17:06:56 +000057 )
58 );
59
60 $self->asset(
61 'korap.js' => (
Nils Diewald8f4b5da2014-12-03 22:13:39 +000062# '/js/d3.v3.min.js',
Nils Diewaldf2e02a92014-11-12 18:31:05 +000063# '/js/dagre-d3.min.js',
Nils Diewald8f4b5da2014-12-03 22:13:39 +000064# '/js/dagre-d3.js',
65# '/js/translateTree.js',
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000066 '/js/tutorialCookie.js',
Nils Diewald7cad8402014-07-08 17:06:56 +000067 '/js/translateTable.js',
68 '/js/hint.js',
Nils Diewaldca01b762014-09-08 02:35:20 +000069 '/js/highlight.pack.js',
Nils Diewalde99d9042014-11-20 23:36:54 +000070 '/js/ajax.js',
Nils Diewaldca01b762014-09-08 02:35:20 +000071 $self->notifications->scripts
Nils Diewald7cad8402014-07-08 17:06:56 +000072 )
73 );
Nils Diewald4af3f0b2014-06-25 01:43:17 +000074
Nils Diewald2329e1d2014-06-12 16:07:57 +000075 $self->helper(
76 date_format => sub {
77 my ($c, $date) = @_;
78 return $date;
79 }
80 );
81
Nils Diewald64bab252014-05-22 11:04:04 +000082 # Routes
Nils Diewald5d1ffb42014-05-21 17:45:34 +000083 my $r = $self->routes;
84
Nils Diewald002e8fb2014-06-22 14:27:01 +000085 # Base search route
Nils Diewald8f4b5da2014-12-03 22:13:39 +000086 $r->get('/')->to('search#query')->name('index');
87
88 # Get match information
89 my $corpus = $r->route('/corpus/:corpus_id');
90 my $doc = $corpus->route('/#doc_id');
91 my $match = $doc->route('/:match_id')->to('search#match_info')->name('match');
Nils Diewald33e15552014-06-13 19:38:37 +000092
Nils Diewald002e8fb2014-06-22 14:27:01 +000093 # Tutorial data
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000094 $r->get('/tutorial')->to('tutorial#page', tutorial => 'index');
95 $r->get('/tutorial/(*tutorial)')->to('tutorial#page')->name('tutorial');
Nils Diewald996aa552014-12-02 03:26:44 +000096};
97
98
991;
100
101
102__END__