blob: 30318bcd552e1a12eb379ff8d4a4a5ab4db4d6c8 [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 Diewald80d4c6e2014-11-19 02:53:16 +00005our $VERSION = '0.08';
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
Nils Diewaldeca30442014-11-18 20:33:54 +00009# morbo -m test -w lib -w templates -w public/sass -w public/js -w public/css script/korap
Nils Diewaldf7366232014-07-25 15:57:08 +000010
Nils Diewald002e8fb2014-06-22 14:27:01 +000011# Start the application and register all routes and plugins
Nils Diewald5d1ffb42014-05-21 17:45:34 +000012sub startup {
13 my $self = shift;
14
Nils Diewald7cad8402014-07-08 17:06:56 +000015 $self->defaults(layout => 'default');
16
Nils Diewald002e8fb2014-06-22 14:27:01 +000017 # Set secret for signed cookies
Nils Diewald33e15552014-06-13 19:38:37 +000018 $self->secrets(['fmhsfjgfchgsdbfgshfxztsbt32477eb45veu4vubrghfgghbtv']);
19
Nils Diewald002e8fb2014-06-22 14:27:01 +000020 # Add additional plugin path
Nils Diewald5d1ffb42014-05-21 17:45:34 +000021 push(@{$self->plugins->namespaces}, __PACKAGE__ . '::Plugin');
Nils Diewald002e8fb2014-06-22 14:27:01 +000022
23 # Load plugins
24 foreach (qw/Config
25 CHI
26 TagHelpers::Pagination
27 Notifications
28 Number::Commify
Nils Diewald996aa552014-12-02 03:26:44 +000029 Search
Nils Diewald996aa552014-12-02 03:26:44 +000030 KorapHelpers
Nils Diewald7cad8402014-07-08 17:06:56 +000031 KorapTagHelpers
Nils Diewald94bae912014-09-22 13:40:31 +000032 /) {
Nils Diewald002e8fb2014-06-22 14:27:01 +000033 $self->plugin($_);
34 };
Nils Diewald2329e1d2014-06-12 16:07:57 +000035
Nils Diewald996aa552014-12-02 03:26:44 +000036# $self->plugin(AssetPack => { minify => 1 });
37 $self->plugin('AssetPack');
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',
Nils Diewaldf2e02a92014-11-12 18:31:05 +000049 '/sass/matchinfo.scss',
Nils Diewald7cad8402014-07-08 17:06:56 +000050 '/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',
Nils Diewald063a7c42014-11-12 20:11:55 +000055 '/sass/alertify.scss',
Nils Diewaldca01b762014-09-08 02:35:20 +000056 $self->notifications->styles
Nils Diewald7cad8402014-07-08 17:06:56 +000057 )
58 );
59
60 $self->asset(
61 'korap.js' => (
Nils Diewald8f4b5da2014-12-03 22:13:39 +000062# '/js/d3.v3.min.js',
Nils Diewaldf2e02a92014-11-12 18:31:05 +000063# '/js/dagre-d3.min.js',
Nils Diewald8f4b5da2014-12-03 22:13:39 +000064# '/js/dagre-d3.js',
65# '/js/translateTree.js',
Nils Diewald996aa552014-12-02 03:26:44 +000066 '/js/jquery-2.0.0.min.js', # Temp
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000067 '/js/tutorialCookie.js',
Nils Diewald7cad8402014-07-08 17:06:56 +000068 '/js/translateTable.js',
69 '/js/hint.js',
Nils Diewaldca01b762014-09-08 02:35:20 +000070 '/js/highlight.pack.js',
Nils Diewalde99d9042014-11-20 23:36:54 +000071 '/js/ajax.js',
Nils Diewaldca01b762014-09-08 02:35:20 +000072 $self->notifications->scripts
Nils Diewald7cad8402014-07-08 17:06:56 +000073 )
74 );
Nils Diewald4af3f0b2014-06-25 01:43:17 +000075
Nils Diewald2329e1d2014-06-12 16:07:57 +000076 $self->helper(
77 date_format => sub {
78 my ($c, $date) = @_;
79 return $date;
80 }
81 );
82
Nils Diewald64bab252014-05-22 11:04:04 +000083 # Routes
Nils Diewald5d1ffb42014-05-21 17:45:34 +000084 my $r = $self->routes;
85
Nils Diewald002e8fb2014-06-22 14:27:01 +000086 # Base search route
Nils Diewald8f4b5da2014-12-03 22:13:39 +000087 $r->get('/')->to('search#query')->name('index');
88
89 # Get match information
90 my $corpus = $r->route('/corpus/:corpus_id');
91 my $doc = $corpus->route('/#doc_id');
92 my $match = $doc->route('/:match_id')->to('search#match_info')->name('match');
Nils Diewald33e15552014-06-13 19:38:37 +000093
Nils Diewald002e8fb2014-06-22 14:27:01 +000094 # Tutorial data
Nils Diewald4e9fbcb2014-07-15 11:45:09 +000095 $r->get('/tutorial')->to('tutorial#page', tutorial => 'index');
96 $r->get('/tutorial/(*tutorial)')->to('tutorial#page')->name('tutorial');
Nils Diewald996aa552014-12-02 03:26:44 +000097};
98
99
1001;
101
102
103__END__