blob: b8b60a3b6756673414980f5966741701a3ae696e [file] [log] [blame]
Nils Diewald5d1ffb42014-05-21 17:45:34 +00001package Korap;
2use Mojo::Base 'Mojolicious';
3
Nils Diewald4e9fbcb2014-07-15 11:45:09 +00004our $VERSION = '0.05';
Nils Diewald7cad8402014-07-08 17:06:56 +00005
6# Start dev with
7# morbo -w lib -w templates -w public/sass -w public/js script/korap
Nils Diewald64bab252014-05-22 11:04:04 +00008
Nils Diewald002e8fb2014-06-22 14:27:01 +00009# Start the application and register all routes and plugins
Nils Diewald5d1ffb42014-05-21 17:45:34 +000010sub startup {
11 my $self = shift;
12
Nils Diewald7cad8402014-07-08 17:06:56 +000013 $self->defaults(layout => 'default');
14
Nils Diewald002e8fb2014-06-22 14:27:01 +000015 # Set secret for signed cookies
Nils Diewald33e15552014-06-13 19:38:37 +000016 $self->secrets(['fmhsfjgfchgsdbfgshfxztsbt32477eb45veu4vubrghfgghbtv']);
17
Nils Diewald002e8fb2014-06-22 14:27:01 +000018 # Add additional plugin path
Nils Diewald5d1ffb42014-05-21 17:45:34 +000019 push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin');
Nils Diewald002e8fb2014-06-22 14:27:01 +000020
21 # Load plugins
22 foreach (qw/Config
23 CHI
24 TagHelpers::Pagination
25 Notifications
26 Number::Commify
27 KorapSearch
28 KorapInfo
Nils Diewald7cad8402014-07-08 17:06:56 +000029 KorapTagHelpers
30 /) {
Nils Diewald002e8fb2014-06-22 14:27:01 +000031 $self->plugin($_);
32 };
Nils Diewald2329e1d2014-06-12 16:07:57 +000033
Nils Diewald7cad8402014-07-08 17:06:56 +000034 $self->plugin(AssetPack => {
35 minify => 1
36 });
37
38 $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
41 $self->asset(
42 'korap.css' => (
43 '/sass/style.scss',
44 '/sass/sidebar.scss',
45 '/sass/tutorial.scss',
46 '/sass/hint.scss',
47 '/sass/query.scss',
48 '/sass/table.scss',
49 '/sass/pagination.scss',
50 '/sass/kwic-4.0.scss',
Nils Diewaldc6d1f472014-07-18 17:48:57 +000051 '/sass/alertify.scss',
Nils Diewald7cad8402014-07-08 17:06:56 +000052 '/css/media.css',
53 '/css/font-awesome.min.css',
54 '/css/highlight.css'
55 )
56 );
57
58 $self->asset(
59 'korap.js' => (
60 '/js/jquery-2.0.0.min.js',
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000061 '/js/tutorialCookie.js',
Nils Diewald7cad8402014-07-08 17:06:56 +000062 '/js/translateTable.js',
63 '/js/hint.js',
64 '/js/highlight.pack.js'
65 )
66 );
Nils Diewald4af3f0b2014-06-25 01:43:17 +000067
Nils Diewald2329e1d2014-06-12 16:07:57 +000068 $self->helper(
69 date_format => sub {
70 my ($c, $date) = @_;
71 return $date;
72 }
73 );
74
Nils Diewald64bab252014-05-22 11:04:04 +000075 # Routes
Nils Diewald5d1ffb42014-05-21 17:45:34 +000076 my $r = $self->routes;
77
Nils Diewald002e8fb2014-06-22 14:27:01 +000078 # Base search route
Nils Diewaldb22abdf2014-06-18 22:57:50 +000079 $r->get('/')->to('search#remote')->name('index');
Nils Diewald33e15552014-06-13 19:38:37 +000080
Nils Diewald002e8fb2014-06-22 14:27:01 +000081 # Tutorial data
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000082 $r->get('/tutorial')->to('tutorial#page', tutorial => 'index');
83 $r->get('/tutorial/(*tutorial)')->to('tutorial#page')->name('tutorial');
Nils Diewald2329e1d2014-06-12 16:07:57 +000084
Nils Diewald002e8fb2014-06-22 14:27:01 +000085 # Collection data
Nils Diewald7cad8402014-07-08 17:06:56 +000086 my $collection = $r->bridge('/collection');
87 $collection->to('info#about_collection');
88 my $collection_id = $collection->bridge('/:collection_id');
89 # stats
90 # $collection_id->;
91 $collection_id->search;
Nils Diewald1eba6572014-06-17 19:49:53 +000092
Nils Diewald002e8fb2014-06-22 14:27:01 +000093 # Corpus data
Nils Diewald7cad8402014-07-08 17:06:56 +000094 my $corpus_res = $r->route('/corpus');
95 my $corpus = $corpus_res->route('/:corpus_id');
96 # Todo: Stats
97 $corpus->search->name('search_corpus');
98 my $doc = $corpus->route('/#doc_id');
99 $doc->search->name('search_document');
100
101 # Match data
102 my $match = $doc->route('/:match_id');
103 $match->route->to('info#about_match')->name('match');
104 my $match_layer = $match->route('/:layer');
105 $match_layer->route->to('info#about_match');
106 $match_layer->route('/:foundry')->to('info#about_match');
Nils Diewald1eba6572014-06-17 19:49:53 +0000107
Nils Diewald002e8fb2014-06-22 14:27:01 +0000108 # Utilities
Nils Diewald7cad8402014-07-08 17:06:56 +0000109 # $r->get('/util/query')->to('search#query');
Nils Diewald64bab252014-05-22 11:04:04 +0000110};
111
Nils Diewald5d1ffb42014-05-21 17:45:34 +0000112
1131;