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 | 80d4c6e | 2014-11-19 02:53:16 +0000 | [diff] [blame] | 5 | our $VERSION = '0.08'; |
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 |
Nils Diewald | eca3044 | 2014-11-18 20:33:54 +0000 | [diff] [blame] | 9 | # morbo -m test -w lib -w templates -w public/sass -w public/js -w public/css script/korap |
Nils Diewald | f736623 | 2014-07-25 15:57:08 +0000 | [diff] [blame] | 10 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 11 | # Start the application and register all routes and plugins |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 12 | sub startup { |
| 13 | my $self = shift; |
| 14 | |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 15 | $self->defaults(layout => 'default'); |
| 16 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 17 | # Set secret for signed cookies |
Nils Diewald | 33e1555 | 2014-06-13 19:38:37 +0000 | [diff] [blame] | 18 | $self->secrets(['fmhsfjgfchgsdbfgshfxztsbt32477eb45veu4vubrghfgghbtv']); |
| 19 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 20 | # Add additional plugin path |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 21 | push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin'); |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 22 | |
| 23 | # Load plugins |
| 24 | foreach (qw/Config |
| 25 | CHI |
| 26 | TagHelpers::Pagination |
| 27 | Notifications |
| 28 | Number::Commify |
Nils Diewald | 996aa55 | 2014-12-02 03:26:44 +0000 | [diff] [blame^] | 29 | Search |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 30 | KorapInfo |
Nils Diewald | 996aa55 | 2014-12-02 03:26:44 +0000 | [diff] [blame^] | 31 | KorapHelpers |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 32 | KorapTagHelpers |
Nils Diewald | 94bae91 | 2014-09-22 13:40:31 +0000 | [diff] [blame] | 33 | /) { |
| 34 | # Oro::Account |
| 35 | # Oro::Account::ConfirmMail |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 36 | $self->plugin($_); |
| 37 | }; |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame] | 38 | |
Nils Diewald | 996aa55 | 2014-12-02 03:26:44 +0000 | [diff] [blame^] | 39 | # $self->plugin(AssetPack => { minify => 1 }); |
| 40 | $self->plugin('AssetPack'); |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 41 | $self->plugin('AssetPack::LibSass'); |
Nils Diewald | 4e9fbcb | 2014-07-15 11:45:09 +0000 | [diff] [blame] | 42 | $self->plugin('MailException' => $self->config('MailException')); |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 43 | |
Nils Diewald | 94bae91 | 2014-09-22 13:40:31 +0000 | [diff] [blame] | 44 | # Add assets for AssetPack |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 45 | $self->asset( |
| 46 | 'korap.css' => ( |
| 47 | '/sass/style.scss', |
| 48 | '/sass/sidebar.scss', |
| 49 | '/sass/tutorial.scss', |
| 50 | '/sass/hint.scss', |
| 51 | '/sass/query.scss', |
Nils Diewald | f2e02a9 | 2014-11-12 18:31:05 +0000 | [diff] [blame] | 52 | '/sass/matchinfo.scss', |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 53 | '/sass/pagination.scss', |
| 54 | '/sass/kwic-4.0.scss', |
| 55 | '/css/media.css', |
| 56 | '/css/font-awesome.min.css', |
Nils Diewald | ca01b76 | 2014-09-08 02:35:20 +0000 | [diff] [blame] | 57 | '/css/highlight.css', |
Nils Diewald | 063a7c4 | 2014-11-12 20:11:55 +0000 | [diff] [blame] | 58 | '/sass/alertify.scss', |
Nils Diewald | ca01b76 | 2014-09-08 02:35:20 +0000 | [diff] [blame] | 59 | $self->notifications->styles |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 60 | ) |
| 61 | ); |
| 62 | |
| 63 | $self->asset( |
| 64 | 'korap.js' => ( |
Nils Diewald | 996aa55 | 2014-12-02 03:26:44 +0000 | [diff] [blame^] | 65 | '/js/d3.v3.min.js', |
Nils Diewald | f2e02a9 | 2014-11-12 18:31:05 +0000 | [diff] [blame] | 66 | # '/js/dagre-d3.min.js', |
Nils Diewald | 996aa55 | 2014-12-02 03:26:44 +0000 | [diff] [blame^] | 67 | '/js/dagre-d3.js', |
| 68 | '/js/translateTree.js', |
| 69 | '/js/jquery-2.0.0.min.js', # Temp |
Nils Diewald | 4e9fbcb | 2014-07-15 11:45:09 +0000 | [diff] [blame] | 70 | '/js/tutorialCookie.js', |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 71 | '/js/translateTable.js', |
| 72 | '/js/hint.js', |
Nils Diewald | ca01b76 | 2014-09-08 02:35:20 +0000 | [diff] [blame] | 73 | '/js/highlight.pack.js', |
Nils Diewald | e99d904 | 2014-11-20 23:36:54 +0000 | [diff] [blame] | 74 | '/js/ajax.js', |
Nils Diewald | ca01b76 | 2014-09-08 02:35:20 +0000 | [diff] [blame] | 75 | $self->notifications->scripts |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 76 | ) |
| 77 | ); |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 78 | |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame] | 79 | $self->helper( |
| 80 | date_format => sub { |
| 81 | my ($c, $date) = @_; |
| 82 | return $date; |
| 83 | } |
| 84 | ); |
| 85 | |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame] | 86 | # Routes |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 87 | my $r = $self->routes; |
| 88 | |
Nils Diewald | 94bae91 | 2014-09-22 13:40:31 +0000 | [diff] [blame] | 89 | # User account management |
| 90 | # $r->route('/login')->acct('login'); |
| 91 | # $r->route('/login/forgotten')->acct('forgotten'); |
| 92 | # $r->route('/login/remove')->acct('remove'); |
| 93 | # $r->route('/register')->acct('register'); |
| 94 | # $r->route('/logout')->acct('logout'); |
| 95 | # $r->route('/preferences')->acct('preferences'); |
| 96 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 97 | # Base search route |
Nils Diewald | b22abdf | 2014-06-18 22:57:50 +0000 | [diff] [blame] | 98 | $r->get('/')->to('search#remote')->name('index'); |
Nils Diewald | 33e1555 | 2014-06-13 19:38:37 +0000 | [diff] [blame] | 99 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 100 | # Tutorial data |
Nils Diewald | 4e9fbcb | 2014-07-15 11:45:09 +0000 | [diff] [blame] | 101 | $r->get('/tutorial')->to('tutorial#page', tutorial => 'index'); |
| 102 | $r->get('/tutorial/(*tutorial)')->to('tutorial#page')->name('tutorial'); |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame] | 103 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 104 | # Collection data |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 105 | my $collection = $r->bridge('/collection'); |
| 106 | $collection->to('info#about_collection'); |
| 107 | my $collection_id = $collection->bridge('/:collection_id'); |
| 108 | # stats |
Nils Diewald | 996aa55 | 2014-12-02 03:26:44 +0000 | [diff] [blame^] | 109 | }; |
| 110 | |
| 111 | |
| 112 | 1; |
| 113 | |
| 114 | |
| 115 | __END__ |
| 116 | |
| 117 | |
| 118 | |
| 119 | # No shortcut! |
| 120 | |
| 121 | # $collection_id->search; |
Nils Diewald | 1eba657 | 2014-06-17 19:49:53 +0000 | [diff] [blame] | 122 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 123 | # Corpus data |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 124 | my $corpus_res = $r->route('/corpus'); |
| 125 | my $corpus = $corpus_res->route('/:corpus_id'); |
Nils Diewald | 996aa55 | 2014-12-02 03:26:44 +0000 | [diff] [blame^] | 126 | |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 127 | # Todo: Stats |
Nils Diewald | 996aa55 | 2014-12-02 03:26:44 +0000 | [diff] [blame^] | 128 | # $corpus->search->name('search_corpus'); |
| 129 | # my $doc = $corpus->route('/#doc_id'); |
| 130 | # $doc->search->name('search_document'); |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 131 | |
| 132 | # Match data |
| 133 | my $match = $doc->route('/:match_id'); |
| 134 | $match->route->to('info#about_match')->name('match'); |
Nils Diewald | e99d904 | 2014-11-20 23:36:54 +0000 | [diff] [blame] | 135 | # my $match_foundry = $match->route('/:foundry'); |
| 136 | # $match_foundry->route->to('info#about_match'); |
| 137 | # $match_foundry->route('/:layer')->to('info#about_match'); |
Nils Diewald | 1eba657 | 2014-06-17 19:49:53 +0000 | [diff] [blame] | 138 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 139 | # Utilities |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 140 | # $r->get('/util/query')->to('search#query'); |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame] | 141 | }; |
| 142 | |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 143 | |
| 144 | 1; |