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