blob: 584d31dbc69533124321e19bc80b2b4864af0394 [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 Diewald1d2903f2014-11-03 22:31:20 +00005our $VERSION = '0.07';
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
9
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
Nils Diewald94bae912014-09-22 13:40:31 +000031 /) {
32 # Oro::Account
33 # Oro::Account::ConfirmMail
Nils Diewald002e8fb2014-06-22 14:27:01 +000034 $self->plugin($_);
35 };
Nils Diewald2329e1d2014-06-12 16:07:57 +000036
Nils Diewald94bae912014-09-22 13:40:31 +000037 $self->plugin(AssetPack => { minify => 1 });
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',
49 '/sass/table.scss',
50 '/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',
55 # '/sass/alertify.scss',
56 $self->notifications->styles
Nils Diewald7cad8402014-07-08 17:06:56 +000057 )
58 );
59
60 $self->asset(
61 'korap.js' => (
62 '/js/jquery-2.0.0.min.js',
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000063 '/js/tutorialCookie.js',
Nils Diewald7cad8402014-07-08 17:06:56 +000064 '/js/translateTable.js',
65 '/js/hint.js',
Nils Diewaldca01b762014-09-08 02:35:20 +000066 '/js/highlight.pack.js',
67 $self->notifications->scripts
Nils Diewald7cad8402014-07-08 17:06:56 +000068 )
69 );
Nils Diewald4af3f0b2014-06-25 01:43:17 +000070
Nils Diewald2329e1d2014-06-12 16:07:57 +000071 $self->helper(
72 date_format => sub {
73 my ($c, $date) = @_;
74 return $date;
75 }
76 );
77
Nils Diewald64bab252014-05-22 11:04:04 +000078 # Routes
Nils Diewald5d1ffb42014-05-21 17:45:34 +000079 my $r = $self->routes;
80
Nils Diewald94bae912014-09-22 13:40:31 +000081 # User account management
82 # $r->route('/login')->acct('login');
83 # $r->route('/login/forgotten')->acct('forgotten');
84 # $r->route('/login/remove')->acct('remove');
85 # $r->route('/register')->acct('register');
86 # $r->route('/logout')->acct('logout');
87 # $r->route('/preferences')->acct('preferences');
88
Nils Diewald002e8fb2014-06-22 14:27:01 +000089 # Base search route
Nils Diewaldb22abdf2014-06-18 22:57:50 +000090 $r->get('/')->to('search#remote')->name('index');
Nils Diewald33e15552014-06-13 19:38:37 +000091
Nils Diewald002e8fb2014-06-22 14:27:01 +000092 # Tutorial data
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000093 $r->get('/tutorial')->to('tutorial#page', tutorial => 'index');
94 $r->get('/tutorial/(*tutorial)')->to('tutorial#page')->name('tutorial');
Nils Diewald2329e1d2014-06-12 16:07:57 +000095
Nils Diewald002e8fb2014-06-22 14:27:01 +000096 # Collection data
Nils Diewald7cad8402014-07-08 17:06:56 +000097 my $collection = $r->bridge('/collection');
98 $collection->to('info#about_collection');
99 my $collection_id = $collection->bridge('/:collection_id');
100 # stats
101 # $collection_id->;
102 $collection_id->search;
Nils Diewald1eba6572014-06-17 19:49:53 +0000103
Nils Diewald002e8fb2014-06-22 14:27:01 +0000104 # Corpus data
Nils Diewald7cad8402014-07-08 17:06:56 +0000105 my $corpus_res = $r->route('/corpus');
106 my $corpus = $corpus_res->route('/:corpus_id');
107 # Todo: Stats
108 $corpus->search->name('search_corpus');
109 my $doc = $corpus->route('/#doc_id');
110 $doc->search->name('search_document');
111
112 # Match data
113 my $match = $doc->route('/:match_id');
114 $match->route->to('info#about_match')->name('match');
115 my $match_layer = $match->route('/:layer');
116 $match_layer->route->to('info#about_match');
117 $match_layer->route('/:foundry')->to('info#about_match');
Nils Diewald1eba6572014-06-17 19:49:53 +0000118
Nils Diewald002e8fb2014-06-22 14:27:01 +0000119 # Utilities
Nils Diewald7cad8402014-07-08 17:06:56 +0000120 # $r->get('/util/query')->to('search#query');
Nils Diewald64bab252014-05-22 11:04:04 +0000121};
122
Nils Diewald5d1ffb42014-05-21 17:45:34 +0000123
1241;