blob: b7cb6cfc089fe1f03bb8a5af18dda034bcf426d9 [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
Nils Diewaldf7366232014-07-25 15:57:08 +00007# morbo -w lib -w templates -w public/sass -w public/js -w public/css script/korap
8
Nils Diewald64bab252014-05-22 11:04:04 +00009
Nils Diewald002e8fb2014-06-22 14:27:01 +000010# Start the application and register all routes and plugins
Nils Diewald5d1ffb42014-05-21 17:45:34 +000011sub startup {
12 my $self = shift;
13
Nils Diewald7cad8402014-07-08 17:06:56 +000014 $self->defaults(layout => 'default');
15
Nils Diewald002e8fb2014-06-22 14:27:01 +000016 # Set secret for signed cookies
Nils Diewald33e15552014-06-13 19:38:37 +000017 $self->secrets(['fmhsfjgfchgsdbfgshfxztsbt32477eb45veu4vubrghfgghbtv']);
18
Nils Diewald002e8fb2014-06-22 14:27:01 +000019 # Add additional plugin path
Nils Diewald5d1ffb42014-05-21 17:45:34 +000020 push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin');
Nils Diewald002e8fb2014-06-22 14:27:01 +000021
22 # Load plugins
23 foreach (qw/Config
24 CHI
25 TagHelpers::Pagination
26 Notifications
27 Number::Commify
28 KorapSearch
29 KorapInfo
Nils Diewald7cad8402014-07-08 17:06:56 +000030 KorapTagHelpers
31 /) {
Nils Diewald002e8fb2014-06-22 14:27:01 +000032 $self->plugin($_);
33 };
Nils Diewald2329e1d2014-06-12 16:07:57 +000034
Nils Diewald7cad8402014-07-08 17:06:56 +000035 $self->plugin(AssetPack => {
36 minify => 1
37 });
38
39 $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
42 $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',
49 '/sass/table.scss',
50 '/sass/pagination.scss',
51 '/sass/kwic-4.0.scss',
Nils Diewaldc6d1f472014-07-18 17:48:57 +000052 '/sass/alertify.scss',
Nils Diewald7cad8402014-07-08 17:06:56 +000053 '/css/media.css',
54 '/css/font-awesome.min.css',
55 '/css/highlight.css'
56 )
57 );
58
59 $self->asset(
60 'korap.js' => (
61 '/js/jquery-2.0.0.min.js',
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000062 '/js/tutorialCookie.js',
Nils Diewald7cad8402014-07-08 17:06:56 +000063 '/js/translateTable.js',
64 '/js/hint.js',
65 '/js/highlight.pack.js'
66 )
67 );
Nils Diewald4af3f0b2014-06-25 01:43:17 +000068
Nils Diewald2329e1d2014-06-12 16:07:57 +000069 $self->helper(
70 date_format => sub {
71 my ($c, $date) = @_;
72 return $date;
73 }
74 );
75
Nils Diewald64bab252014-05-22 11:04:04 +000076 # Routes
Nils Diewald5d1ffb42014-05-21 17:45:34 +000077 my $r = $self->routes;
78
Nils Diewald002e8fb2014-06-22 14:27:01 +000079 # Base search route
Nils Diewaldb22abdf2014-06-18 22:57:50 +000080 $r->get('/')->to('search#remote')->name('index');
Nils Diewald33e15552014-06-13 19:38:37 +000081
Nils Diewald002e8fb2014-06-22 14:27:01 +000082 # Tutorial data
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000083 $r->get('/tutorial')->to('tutorial#page', tutorial => 'index');
84 $r->get('/tutorial/(*tutorial)')->to('tutorial#page')->name('tutorial');
Nils Diewald2329e1d2014-06-12 16:07:57 +000085
Nils Diewald002e8fb2014-06-22 14:27:01 +000086 # Collection data
Nils Diewald7cad8402014-07-08 17:06:56 +000087 my $collection = $r->bridge('/collection');
88 $collection->to('info#about_collection');
89 my $collection_id = $collection->bridge('/:collection_id');
90 # stats
91 # $collection_id->;
92 $collection_id->search;
Nils Diewald1eba6572014-06-17 19:49:53 +000093
Nils Diewald002e8fb2014-06-22 14:27:01 +000094 # Corpus data
Nils Diewald7cad8402014-07-08 17:06:56 +000095 my $corpus_res = $r->route('/corpus');
96 my $corpus = $corpus_res->route('/:corpus_id');
97 # Todo: Stats
98 $corpus->search->name('search_corpus');
99 my $doc = $corpus->route('/#doc_id');
100 $doc->search->name('search_document');
101
102 # Match data
103 my $match = $doc->route('/:match_id');
104 $match->route->to('info#about_match')->name('match');
105 my $match_layer = $match->route('/:layer');
106 $match_layer->route->to('info#about_match');
107 $match_layer->route('/:foundry')->to('info#about_match');
Nils Diewald1eba6572014-06-17 19:49:53 +0000108
Nils Diewald002e8fb2014-06-22 14:27:01 +0000109 # Utilities
Nils Diewald7cad8402014-07-08 17:06:56 +0000110 # $r->get('/util/query')->to('search#query');
Nils Diewald64bab252014-05-22 11:04:04 +0000111};
112
Nils Diewald5d1ffb42014-05-21 17:45:34 +0000113
1141;