| Akron | ccd9d7d | 2020-09-22 09:51:19 +0200 | [diff] [blame] | 1 | package Kalamar::Plugin::Plugins; |
| 2 | use Mojo::Base 'Mojolicious::Plugin'; |
| Akron | baae980 | 2021-02-27 18:32:15 +0100 | [diff] [blame] | 3 | use Mojo::JSON 'decode_json'; |
| 4 | use Mojo::File 'path'; |
| Akron | ccd9d7d | 2020-09-22 09:51:19 +0200 | [diff] [blame] | 5 | |
| 6 | # Register the plugin |
| 7 | sub register { |
| 8 | my ($plugin, $app, $param) = @_; |
| 9 | |
| 10 | # Load parameter from config file |
| 11 | if (my $config_param = $app->config('Kalamar-Plugins')) { |
| 12 | $param = { %$param, %$config_param }; |
| 13 | }; |
| 14 | |
| 15 | # There are default plugins to be registered |
| 16 | if ($param->{default_plugins}) { |
| 17 | |
| 18 | # Read default plugins file |
| Akron | baae980 | 2021-02-27 18:32:15 +0100 | [diff] [blame] | 19 | my $default = path($param->{default_plugins}); |
| 20 | |
| 21 | # Use correct working directory |
| 22 | $default = $app->home->child($default) unless $default->is_abs; |
| 23 | |
| Akron | 8dda1c6 | 2021-01-20 10:27:32 +0100 | [diff] [blame] | 24 | my $json_array = decode_json $default->slurp; |
| Akron | ccd9d7d | 2020-09-22 09:51:19 +0200 | [diff] [blame] | 25 | |
| 26 | # If any scripts are defined |
| 27 | if ($json_array) { |
| 28 | |
| 29 | # TODO: |
| Akron | 8dda1c6 | 2021-01-20 10:27:32 +0100 | [diff] [blame] | 30 | # Add user registered plugins as a path |
| 31 | |
| 32 | # TODO: |
| 33 | # Add sources to CORS. |
| Akron | ccd9d7d | 2020-09-22 09:51:19 +0200 | [diff] [blame] | 34 | |
| 35 | # Add default plugins, if exist |
| Akron | 8dda1c6 | 2021-01-20 10:27:32 +0100 | [diff] [blame] | 36 | $app->routes->get('/settings/plugin/list.json')->to( |
| 37 | cb => sub { |
| 38 | my $c = shift; |
| 39 | $c->res->headers->cache_control('no-cache'); |
| 40 | $c->render( |
| 41 | json => $json_array |
| 42 | ); |
| 43 | } |
| 44 | )->name('plugin_list'); |
| 45 | |
| Akron | ccd9d7d | 2020-09-22 09:51:19 +0200 | [diff] [blame] | 46 | $app->content_block( |
| 47 | scripts => { |
| Akron | 8dda1c6 | 2021-01-20 10:27:32 +0100 | [diff] [blame] | 48 | inline => q!<span id="kalamar-plugins" ! . |
| 49 | q!data-plugins="<%== url_for 'plugin_list' %>"></span>! |
| Akron | ccd9d7d | 2020-09-22 09:51:19 +0200 | [diff] [blame] | 50 | } |
| 51 | ); |
| 52 | }; |
| 53 | }; |
| Akron | ccd9d7d | 2020-09-22 09:51:19 +0200 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | |
| 57 | 1; |
| 58 | |
| 59 | |
| 60 | __END__ |
| 61 | |
| 62 | =pod |
| 63 | |
| 64 | =encoding utf8 |
| 65 | |
| 66 | =head1 NAME |
| 67 | |
| 68 | Kalamar::Plugin::Plugins - Register plugins in the user interface |
| 69 | |
| 70 | =head1 DESCRIPTION |
| 71 | |
| 72 | L<Kalamar::Plugin::Plugins> is an interface to register embedded plugins |
| 73 | in the Kalamar user interface. |
| 74 | |
| 75 | B<WARNING! This is early software and not ready to use!> |
| 76 | |
| 77 | =head1 CONFIGURATION |
| 78 | |
| 79 | L<Kalamar::Plugin::Plugins> supports the following parameter for the |
| 80 | C<Kalamar-Plugins> configuration section in the Kalamar configuration: |
| 81 | |
| 82 | =over 2 |
| 83 | |
| 84 | =item B<default_plugins> |
| 85 | |
| 86 | Path for default plugins (mandatory for all users) to register in the |
| 87 | frontend. |
| 88 | |
| 89 | =back |
| 90 | |
| 91 | =head2 COPYRIGHT AND LICENSE |
| 92 | |
| Akron | 8dda1c6 | 2021-01-20 10:27:32 +0100 | [diff] [blame] | 93 | Copyright (C) 2021, L<IDS Mannheim|http://www.ids-mannheim.de/> |
| Akron | ccd9d7d | 2020-09-22 09:51:19 +0200 | [diff] [blame] | 94 | Author: L<Nils Diewald|http://nils-diewald.de/> |
| 95 | |
| 96 | Kalamar is developed as part of the L<KorAP|http://korap.ids-mannheim.de/> |
| 97 | Corpus Analysis Platform at the |
| 98 | L<Leibniz Institute for the German Language (IDS)|http://ids-mannheim.de/>, |
| 99 | member of the |
| 100 | L<Leibniz-Gemeinschaft|http://www.leibniz-gemeinschaft.de> |
| 101 | and supported by the L<KobRA|http://www.kobra.tu-dortmund.de> project, |
| 102 | funded by the |
| 103 | L<Federal Ministry of Education and Research (BMBF)|http://www.bmbf.de/en/>. |
| 104 | |
| 105 | Kalamar is free software published under the |
| 106 | L<BSD-2 License|https://raw.githubusercontent.com/KorAP/Kalamar/master/LICENSE>. |
| 107 | |
| 108 | =cut |