blob: 311ed4820419dc8ac67a4ff54ca1661384c0ba18 [file] [log] [blame]
Nils Diewald5d1ffb42014-05-21 17:45:34 +00001package Korap;
2use Mojo::Base 'Mojolicious';
3
Nils Diewald1d2903f2014-11-03 22:31:20 +00004our $VERSION = '0.07';
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 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
Nils Diewald94bae912014-09-22 13:40:31 +000030 /) {
31 # Oro::Account
32 # Oro::Account::ConfirmMail
Nils Diewald002e8fb2014-06-22 14:27:01 +000033 $self->plugin($_);
34 };
Nils Diewald2329e1d2014-06-12 16:07:57 +000035
Nils Diewald94bae912014-09-22 13:40:31 +000036 $self->plugin(AssetPack => { minify => 1 });
Nils Diewald7cad8402014-07-08 17:06:56 +000037 $self->plugin('AssetPack::LibSass');
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000038 $self->plugin('MailException' => $self->config('MailException'));
Nils Diewald7cad8402014-07-08 17:06:56 +000039
Nils Diewald94bae912014-09-22 13:40:31 +000040 # Add assets for AssetPack
Nils Diewald7cad8402014-07-08 17:06:56 +000041 $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',
51 '/css/media.css',
52 '/css/font-awesome.min.css',
Nils Diewaldca01b762014-09-08 02:35:20 +000053 '/css/highlight.css',
54 # '/sass/alertify.scss',
55 $self->notifications->styles
Nils Diewald7cad8402014-07-08 17:06:56 +000056 )
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',
Nils Diewaldca01b762014-09-08 02:35:20 +000065 '/js/highlight.pack.js',
66 $self->notifications->scripts
Nils Diewald7cad8402014-07-08 17:06:56 +000067 )
68 );
Nils Diewald4af3f0b2014-06-25 01:43:17 +000069
Nils Diewald2329e1d2014-06-12 16:07:57 +000070 $self->helper(
71 date_format => sub {
72 my ($c, $date) = @_;
73 return $date;
74 }
75 );
76
Nils Diewald64bab252014-05-22 11:04:04 +000077 # Routes
Nils Diewald5d1ffb42014-05-21 17:45:34 +000078 my $r = $self->routes;
79
Nils Diewald94bae912014-09-22 13:40:31 +000080 # User account management
81 # $r->route('/login')->acct('login');
82 # $r->route('/login/forgotten')->acct('forgotten');
83 # $r->route('/login/remove')->acct('remove');
84 # $r->route('/register')->acct('register');
85 # $r->route('/logout')->acct('logout');
86 # $r->route('/preferences')->acct('preferences');
87
Nils Diewald002e8fb2014-06-22 14:27:01 +000088 # Base search route
Nils Diewaldb22abdf2014-06-18 22:57:50 +000089 $r->get('/')->to('search#remote')->name('index');
Nils Diewald33e15552014-06-13 19:38:37 +000090
Nils Diewald002e8fb2014-06-22 14:27:01 +000091 # Tutorial data
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000092 $r->get('/tutorial')->to('tutorial#page', tutorial => 'index');
93 $r->get('/tutorial/(*tutorial)')->to('tutorial#page')->name('tutorial');
Nils Diewald2329e1d2014-06-12 16:07:57 +000094
Nils Diewald002e8fb2014-06-22 14:27:01 +000095 # Collection data
Nils Diewald7cad8402014-07-08 17:06:56 +000096 my $collection = $r->bridge('/collection');
97 $collection->to('info#about_collection');
98 my $collection_id = $collection->bridge('/:collection_id');
99 # stats
100 # $collection_id->;
101 $collection_id->search;
Nils Diewald1eba6572014-06-17 19:49:53 +0000102
Nils Diewald002e8fb2014-06-22 14:27:01 +0000103 # Corpus data
Nils Diewald7cad8402014-07-08 17:06:56 +0000104 my $corpus_res = $r->route('/corpus');
105 my $corpus = $corpus_res->route('/:corpus_id');
106 # Todo: Stats
107 $corpus->search->name('search_corpus');
108 my $doc = $corpus->route('/#doc_id');
109 $doc->search->name('search_document');
110
111 # Match data
112 my $match = $doc->route('/:match_id');
113 $match->route->to('info#about_match')->name('match');
114 my $match_layer = $match->route('/:layer');
115 $match_layer->route->to('info#about_match');
116 $match_layer->route('/:foundry')->to('info#about_match');
Nils Diewald1eba6572014-06-17 19:49:53 +0000117
Nils Diewald002e8fb2014-06-22 14:27:01 +0000118 # Utilities
Nils Diewald7cad8402014-07-08 17:06:56 +0000119 # $r->get('/util/query')->to('search#query');
Nils Diewald64bab252014-05-22 11:04:04 +0000120};
121
Nils Diewald5d1ffb42014-05-21 17:45:34 +0000122
1231;