Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 1 | package Korap; |
| 2 | use Mojo::Base 'Mojolicious'; |
Nils Diewald | e2c8381 | 2014-11-11 21:13:18 +0000 | [diff] [blame] | 3 | use Mojo::ByteStream 'b'; |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 4 | |
Nils Diewald | 1d2903f | 2014-11-03 22:31:20 +0000 | [diff] [blame] | 5 | our $VERSION = '0.07'; |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 6 | |
| 7 | # Start dev with |
Nils Diewald | f736623 | 2014-07-25 15:57:08 +0000 | [diff] [blame] | 8 | # morbo -w lib -w templates -w public/sass -w public/js -w public/css script/korap |
| 9 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 10 | # Start the application and register all routes and plugins |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 11 | sub startup { |
| 12 | my $self = shift; |
| 13 | |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 14 | $self->defaults(layout => 'default'); |
| 15 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 16 | # Set secret for signed cookies |
Nils Diewald | 33e1555 | 2014-06-13 19:38:37 +0000 | [diff] [blame] | 17 | $self->secrets(['fmhsfjgfchgsdbfgshfxztsbt32477eb45veu4vubrghfgghbtv']); |
| 18 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 19 | # Add additional plugin path |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 20 | push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin'); |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 21 | |
| 22 | # Load plugins |
| 23 | foreach (qw/Config |
| 24 | CHI |
| 25 | TagHelpers::Pagination |
| 26 | Notifications |
| 27 | Number::Commify |
| 28 | KorapSearch |
| 29 | KorapInfo |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 30 | KorapTagHelpers |
Nils Diewald | 94bae91 | 2014-09-22 13:40:31 +0000 | [diff] [blame] | 31 | /) { |
| 32 | # Oro::Account |
| 33 | # Oro::Account::ConfirmMail |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 34 | $self->plugin($_); |
| 35 | }; |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame] | 36 | |
Nils Diewald | 94bae91 | 2014-09-22 13:40:31 +0000 | [diff] [blame] | 37 | $self->plugin(AssetPack => { minify => 1 }); |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 38 | $self->plugin('AssetPack::LibSass'); |
Nils Diewald | 4e9fbcb | 2014-07-15 11:45:09 +0000 | [diff] [blame] | 39 | $self->plugin('MailException' => $self->config('MailException')); |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 40 | |
Nils Diewald | 94bae91 | 2014-09-22 13:40:31 +0000 | [diff] [blame] | 41 | # Add assets for AssetPack |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 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', |
| 52 | '/css/media.css', |
| 53 | '/css/font-awesome.min.css', |
Nils Diewald | ca01b76 | 2014-09-08 02:35:20 +0000 | [diff] [blame] | 54 | '/css/highlight.css', |
| 55 | # '/sass/alertify.scss', |
| 56 | $self->notifications->styles |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 57 | ) |
| 58 | ); |
| 59 | |
| 60 | $self->asset( |
| 61 | 'korap.js' => ( |
| 62 | '/js/jquery-2.0.0.min.js', |
Nils Diewald | 4e9fbcb | 2014-07-15 11:45:09 +0000 | [diff] [blame] | 63 | '/js/tutorialCookie.js', |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 64 | '/js/translateTable.js', |
| 65 | '/js/hint.js', |
Nils Diewald | ca01b76 | 2014-09-08 02:35:20 +0000 | [diff] [blame] | 66 | '/js/highlight.pack.js', |
| 67 | $self->notifications->scripts |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 68 | ) |
| 69 | ); |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 70 | |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame] | 71 | $self->helper( |
| 72 | date_format => sub { |
| 73 | my ($c, $date) = @_; |
| 74 | return $date; |
| 75 | } |
| 76 | ); |
| 77 | |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame] | 78 | # Routes |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 79 | my $r = $self->routes; |
| 80 | |
Nils Diewald | 94bae91 | 2014-09-22 13:40:31 +0000 | [diff] [blame] | 81 | # 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 Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 89 | # Base search route |
Nils Diewald | b22abdf | 2014-06-18 22:57:50 +0000 | [diff] [blame] | 90 | $r->get('/')->to('search#remote')->name('index'); |
Nils Diewald | 33e1555 | 2014-06-13 19:38:37 +0000 | [diff] [blame] | 91 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 92 | # Tutorial data |
Nils Diewald | 4e9fbcb | 2014-07-15 11:45:09 +0000 | [diff] [blame] | 93 | $r->get('/tutorial')->to('tutorial#page', tutorial => 'index'); |
| 94 | $r->get('/tutorial/(*tutorial)')->to('tutorial#page')->name('tutorial'); |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame] | 95 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 96 | # Collection data |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 97 | 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 Diewald | 1eba657 | 2014-06-17 19:49:53 +0000 | [diff] [blame] | 103 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 104 | # Corpus data |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 105 | 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 Diewald | 1eba657 | 2014-06-17 19:49:53 +0000 | [diff] [blame] | 118 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 119 | # Utilities |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 120 | # $r->get('/util/query')->to('search#query'); |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 123 | |
| 124 | 1; |