Improve Plugin integrations

Change-Id: Ia301dfb06324e3579ced95bb13bf8065d949d686
diff --git a/Changes b/Changes
index 8f6725a..25b158e 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,6 @@
 0.64 2026-01-15
         - Support API version 1.1 (diewald)
+        - Improve 'Plugins' mounting (diewald)
 
 0.63 2026-01-15
         - Add data-testid to test relevant elements (fixes #244; diewald)
diff --git a/Dockerfile b/Dockerfile
index b4e5f01..cec81c5 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -86,7 +86,7 @@
 ENV MOJO_LISTEN http://*:${MOJO_PORT}
 ENV MOJO_MODE   production
 
-RUN echo "{Kalamar=>{plugins=>['KorAPXML2Krill','Tei2KorAPXML','KorAPXML2CoNLLU']}}" > kalamar.production.conf
+RUN echo "{Kalamar=>{plugins=>['KorAPXML2Krill','Tei2KorAPXML','KorAPXML2CoNLLU','Plugins'],proxies=>['PROXY_STUB']},'Kalamar-Plugins'=>{default=>['PLUGIN_STUB']}}" > kalamar.production.conf
 
 EXPOSE ${MOJO_PORT}
 
diff --git a/lib/Kalamar/Plugin/Plugins.pm b/lib/Kalamar/Plugin/Plugins.pm
index e2eadbf..a2a81d3 100644
--- a/lib/Kalamar/Plugin/Plugins.pm
+++ b/lib/Kalamar/Plugin/Plugins.pm
@@ -12,45 +12,63 @@
     $param = { %$param, %$config_param };
   };
 
+  my @json_array = ();
+
+  # Legacy support
+  $param->{default_file} //= $param->{default_plugins};
+
   # There are default plugins to be registered
-  if ($param->{default_plugins}) {
+  if ($param->{default_file}) {
 
     # Read default plugins file
-    my $default = path($param->{default_plugins});
+    my $default = path($param->{default_file});
 
     # Use correct working directory
     $default = $app->home->child($default) unless $default->is_abs;
 
-    my $json_array = decode_json $default->slurp;
+    @json_array = @{ decode_json $default->slurp };
+  };
 
-    # If any scripts are defined
-    if ($json_array) {
+  # There are default plugins to be registered
+  if ($param->{default}) {
+    if (ref $param->{default} ne 'ARRAY') {
+      push @json_array, $param->{default};
+    }
 
-      # TODO:
-      #   Add user registered plugins as a path
-
-      # TODO:
-      #   Add sources to CORS.
-
-      # Add default plugins, if exist
-      $app->routes->get('/settings/plugin/list.json')->to(
-        cb => sub {
-          my $c = shift;
-          $c->res->headers->cache_control('no-cache');
-          $c->render(
-            json => $json_array
-          );
-        }
-      )->name('plugin_list');
-
-      $app->content_block(
-        scripts => {
-          inline => q!<span id="kalamar-plugins" ! .
-            q!data-plugins="<%== url_for 'plugin_list' %>"></span>!
-        }
-      );
+    else {
+      push @json_array, @{$param->{default}};
     };
   };
+
+  @json_array = grep { $_ ne 'PLUGIN_STUB' } @json_array;
+
+  # If any scripts are defined
+  if (@json_array > 0) {
+
+    # TODO:
+    #   Add user registered plugins as a path
+
+    # TODO:
+    #   Add sources to CORS.
+
+    # Add default plugins, if exist
+    $app->routes->get('/settings/plugin/list.json')->to(
+      cb => sub {
+        my $c = shift;
+        $c->res->headers->cache_control('no-cache');
+        $c->render(
+          json => \@json_array
+        );
+      }
+    )->name('plugin_list');
+
+    $app->content_block(
+      scripts => {
+        inline => q!<span id="kalamar-plugins" ! .
+        q!data-plugins="<%== url_for 'plugin_list' %>"></span>!
+      }
+    );
+  };
 };
 
 
@@ -81,16 +99,21 @@
 
 =over 2
 
-=item B<default_plugins>
+=item B<default_file>
 
-Path for default plugins (mandatory for all users) to register in the
+Path for default plugins (mandatory to all users) to register in the
+frontend.
+
+=item B<default>
+
+Array of default plugins (mandatory to all users) to register in the
 frontend.
 
 =back
 
 =head2 COPYRIGHT AND LICENSE
 
-Copyright (C) 2021, L<IDS Mannheim|http://www.ids-mannheim.de/>
+Copyright (C) 2021-2025, L<IDS Mannheim|http://www.ids-mannheim.de/>
 Author: L<Nils Diewald|http://nils-diewald.de/>
 
 Kalamar is developed as part of the L<KorAP|http://korap.ids-mannheim.de/>
diff --git a/slim_script.sh b/slim_script.sh
index bc3dd0c..b726145 100755
--- a/slim_script.sh
+++ b/slim_script.sh
@@ -9,7 +9,7 @@
 
 # Build the docker-slim command
 slim build --http-probe=true \
-           --exec="perl Makefile.PL && make test && unzip -v" \
+           --exec="perl Makefile.PL && MOJO_MODE=test make test && unzip -v" \
            --include-workdir=true \
            --include-path="/usr/local/share/perl5/site_perl/KorAP/" \
            --include-path="/usr/local/share/perl5/site_perl/Mojolicious/" \
diff --git a/t/plugin/plugins.t b/t/plugin/plugins.t
index 2c3f258..93ebc29 100644
--- a/t/plugin/plugins.t
+++ b/t/plugin/plugins.t
@@ -26,7 +26,28 @@
 SCRIPT
 
 $t->app->plugin('Plugins' => {
-  default_plugins => $temp->to_string
+  default_file => $temp->to_string,
+  default => [
+    'PLUGIN_STUB',
+    {
+      "name" => "External Resources",
+      "desc" => "Get extended access from an external provider",
+      "embed" => [{
+        "panel" => "match",
+        "title" => "Full Text",
+        "classes" => ["plugin","cart"],
+        "icon" => "\f07a",
+        "onClick" => {
+          "action" => "addWidget",
+          "template" => "https://korap.ids-mannheim.de/plugin/external/",
+          "permissions"=> [
+            "scripts",
+            "popups"
+          ]
+        }
+      }]
+    }
+  ]
 });
 
 $t->get_ok('/')
@@ -40,8 +61,12 @@
   ->status_is(200)
   ->header_is('Content-Type','application/json;charset=UTF-8')
   ->content_unlike(qr!KorAP\.Plugins=!)
+  ->content_unlike(qr!STUB!)
   ->content_like(qr!button-icon!)
+  ->content_like(qr!exports KWICs and snippets!)
+  ->content_like(qr!Get extended access from an external provider!)
   ->json_is('/0/embed/0/title','exports KWICs and snippets')
+  ->json_is('/1/embed/0/title','Full Text')
   ;
 
 done_testing;