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 | 46e6f18 | 2015-02-04 15:22:49 +0000 | [diff] [blame^] | 5 | our $VERSION = '0.12'; |
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 | 996aa55 | 2014-12-02 03:26:44 +0000 | [diff] [blame] | 30 | KorapHelpers |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 31 | KorapTagHelpers |
Nils Diewald | 94bae91 | 2014-09-22 13:40:31 +0000 | [diff] [blame] | 32 | /) { |
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 | 996aa55 | 2014-12-02 03:26:44 +0000 | [diff] [blame] | 36 | # $self->plugin(AssetPack => { minify => 1 }); |
| 37 | $self->plugin('AssetPack'); |
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', |
Nils Diewald | f2e02a9 | 2014-11-12 18:31:05 +0000 | [diff] [blame] | 49 | '/sass/matchinfo.scss', |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 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', |
Nils Diewald | 063a7c4 | 2014-11-12 20:11:55 +0000 | [diff] [blame] | 55 | '/sass/alertify.scss', |
Nils Diewald | ca01b76 | 2014-09-08 02:35:20 +0000 | [diff] [blame] | 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' => ( |
Nils Diewald | 8f4b5da | 2014-12-03 22:13:39 +0000 | [diff] [blame] | 62 | # '/js/d3.v3.min.js', |
Nils Diewald | f2e02a9 | 2014-11-12 18:31:05 +0000 | [diff] [blame] | 63 | # '/js/dagre-d3.min.js', |
Nils Diewald | 8f4b5da | 2014-12-03 22:13:39 +0000 | [diff] [blame] | 64 | # '/js/dagre-d3.js', |
| 65 | # '/js/translateTree.js', |
Nils Diewald | 4e9fbcb | 2014-07-15 11:45:09 +0000 | [diff] [blame] | 66 | '/js/tutorialCookie.js', |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 67 | '/js/translateTable.js', |
| 68 | '/js/hint.js', |
Nils Diewald | ca01b76 | 2014-09-08 02:35:20 +0000 | [diff] [blame] | 69 | '/js/highlight.pack.js', |
Nils Diewald | e99d904 | 2014-11-20 23:36:54 +0000 | [diff] [blame] | 70 | '/js/ajax.js', |
Nils Diewald | ca01b76 | 2014-09-08 02:35:20 +0000 | [diff] [blame] | 71 | $self->notifications->scripts |
Nils Diewald | 7cad840 | 2014-07-08 17:06:56 +0000 | [diff] [blame] | 72 | ) |
| 73 | ); |
Nils Diewald | 4af3f0b | 2014-06-25 01:43:17 +0000 | [diff] [blame] | 74 | |
Nils Diewald | 2329e1d | 2014-06-12 16:07:57 +0000 | [diff] [blame] | 75 | $self->helper( |
| 76 | date_format => sub { |
| 77 | my ($c, $date) = @_; |
| 78 | return $date; |
| 79 | } |
| 80 | ); |
| 81 | |
Nils Diewald | 64bab25 | 2014-05-22 11:04:04 +0000 | [diff] [blame] | 82 | # Routes |
Nils Diewald | 5d1ffb4 | 2014-05-21 17:45:34 +0000 | [diff] [blame] | 83 | my $r = $self->routes; |
| 84 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 85 | # Base search route |
Nils Diewald | 8f4b5da | 2014-12-03 22:13:39 +0000 | [diff] [blame] | 86 | $r->get('/')->to('search#query')->name('index'); |
| 87 | |
| 88 | # Get match information |
| 89 | my $corpus = $r->route('/corpus/:corpus_id'); |
| 90 | my $doc = $corpus->route('/#doc_id'); |
| 91 | my $match = $doc->route('/:match_id')->to('search#match_info')->name('match'); |
Nils Diewald | 33e1555 | 2014-06-13 19:38:37 +0000 | [diff] [blame] | 92 | |
Nils Diewald | 002e8fb | 2014-06-22 14:27:01 +0000 | [diff] [blame] | 93 | # Tutorial data |
Nils Diewald | 4e9fbcb | 2014-07-15 11:45:09 +0000 | [diff] [blame] | 94 | $r->get('/tutorial')->to('tutorial#page', tutorial => 'index'); |
| 95 | $r->get('/tutorial/(*tutorial)')->to('tutorial#page')->name('tutorial'); |
Nils Diewald | 996aa55 | 2014-12-02 03:26:44 +0000 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | |
| 99 | 1; |
| 100 | |
| 101 | |
| 102 | __END__ |