blob: e2eadbfaf184af49230408879afad4f44da7e493 [file] [log] [blame]
Akronccd9d7d2020-09-22 09:51:19 +02001package Kalamar::Plugin::Plugins;
2use Mojo::Base 'Mojolicious::Plugin';
Akronbaae9802021-02-27 18:32:15 +01003use Mojo::JSON 'decode_json';
4use Mojo::File 'path';
Akronccd9d7d2020-09-22 09:51:19 +02005
6# Register the plugin
7sub 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
Akronbaae9802021-02-27 18:32:15 +010019 my $default = path($param->{default_plugins});
20
21 # Use correct working directory
22 $default = $app->home->child($default) unless $default->is_abs;
23
Akron8dda1c62021-01-20 10:27:32 +010024 my $json_array = decode_json $default->slurp;
Akronccd9d7d2020-09-22 09:51:19 +020025
26 # If any scripts are defined
27 if ($json_array) {
28
29 # TODO:
Akron8dda1c62021-01-20 10:27:32 +010030 # Add user registered plugins as a path
31
32 # TODO:
33 # Add sources to CORS.
Akronccd9d7d2020-09-22 09:51:19 +020034
35 # Add default plugins, if exist
Akron8dda1c62021-01-20 10:27:32 +010036 $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
Akronccd9d7d2020-09-22 09:51:19 +020046 $app->content_block(
47 scripts => {
Akron8dda1c62021-01-20 10:27:32 +010048 inline => q!<span id="kalamar-plugins" ! .
49 q!data-plugins="<%== url_for 'plugin_list' %>"></span>!
Akronccd9d7d2020-09-22 09:51:19 +020050 }
51 );
52 };
53 };
Akronccd9d7d2020-09-22 09:51:19 +020054};
55
56
571;
58
59
60__END__
61
62=pod
63
64=encoding utf8
65
66=head1 NAME
67
68Kalamar::Plugin::Plugins - Register plugins in the user interface
69
70=head1 DESCRIPTION
71
72L<Kalamar::Plugin::Plugins> is an interface to register embedded plugins
73in the Kalamar user interface.
74
75B<WARNING! This is early software and not ready to use!>
76
77=head1 CONFIGURATION
78
79L<Kalamar::Plugin::Plugins> supports the following parameter for the
80C<Kalamar-Plugins> configuration section in the Kalamar configuration:
81
82=over 2
83
84=item B<default_plugins>
85
86Path for default plugins (mandatory for all users) to register in the
87frontend.
88
89=back
90
91=head2 COPYRIGHT AND LICENSE
92
Akron8dda1c62021-01-20 10:27:32 +010093Copyright (C) 2021, L<IDS Mannheim|http://www.ids-mannheim.de/>
Akronccd9d7d2020-09-22 09:51:19 +020094Author: L<Nils Diewald|http://nils-diewald.de/>
95
96Kalamar is developed as part of the L<KorAP|http://korap.ids-mannheim.de/>
97Corpus Analysis Platform at the
98L<Leibniz Institute for the German Language (IDS)|http://ids-mannheim.de/>,
99member of the
100L<Leibniz-Gemeinschaft|http://www.leibniz-gemeinschaft.de>
101and supported by the L<KobRA|http://www.kobra.tu-dortmund.de> project,
102funded by the
103L<Federal Ministry of Education and Research (BMBF)|http://www.bmbf.de/en/>.
104
105Kalamar is free software published under the
106L<BSD-2 License|https://raw.githubusercontent.com/KorAP/Kalamar/master/LICENSE>.
107
108=cut