From fee7905935a9adf963b4485b437fe4d972c14b5f Mon Sep 17 00:00:00 2001 From: Yassine Doghri Date: Thu, 4 Jul 2024 17:50:54 +0000 Subject: [PATCH] feat(plugins): load and display LICENSE.md file if found in plugin's directory --- app/Resources/js/admin.ts | 1 + docs/src/content/docs/en/plugins/index.mdx | 7 ++++ modules/Plugins/Core/BasePlugin.php | 13 +++++- package.json | 1 + pnpm-lock.yaml | 47 ++++++++++++++++++++++ themes/cp_admin/plugins/view.php | 31 ++++++++++---- 6 files changed, 90 insertions(+), 10 deletions(-) diff --git a/app/Resources/js/admin.ts b/app/Resources/js/admin.ts index 40d0f695..7d669c58 100644 --- a/app/Resources/js/admin.ts +++ b/app/Resources/js/admin.ts @@ -22,6 +22,7 @@ import ValidateFileSize from "./modules/ValidateFileSize"; import "./modules/video-clip-previewer"; import VideoClipBuilder from "./modules/VideoClipBuilder"; import "./modules/xml-editor"; +import "@patternfly/elements/pf-tabs/pf-tabs.js"; Dropdown(); Tooltip(); diff --git a/docs/src/content/docs/en/plugins/index.mdx b/docs/src/content/docs/en/plugins/index.mdx index f8da83b2..6d021afb 100644 --- a/docs/src/content/docs/en/plugins/index.mdx +++ b/docs/src/content/docs/en/plugins/index.mdx @@ -17,6 +17,7 @@ Plugins are ways to extend Castopod's core features. - … - icon.svg - manifest.json // required + - LICENSE.md - Plugin.php // required - README.md @@ -97,6 +98,12 @@ through. It should be used for any additional information to help guide the user in using the plugin. +### Plugin LICENSE + +In addition to specifying [the license in the manifest](./manifest#license), you +may add a `LICENSE.md` file. Just as the `README.md` file, its contents will be +loaded into the plugin's view page for the user to read. + ### Plugin icon The plugin icon is displayed next to its title, it is an SVG file intended to diff --git a/modules/Plugins/Core/BasePlugin.php b/modules/Plugins/Core/BasePlugin.php index 3598aef3..1335b749 100644 --- a/modules/Plugins/Core/BasePlugin.php +++ b/modules/Plugins/Core/BasePlugin.php @@ -39,6 +39,8 @@ abstract class BasePlugin implements PluginInterface protected ?string $readmeHTML; + protected ?string $licenseHTML; + public function __construct( protected string $vendor, protected string $package, @@ -56,7 +58,9 @@ abstract class BasePlugin implements PluginInterface $this->iconSrc = $this->loadIcon($directory . '/icon.svg'); - $this->readmeHTML = $this->loadReadme($directory . '/README.md'); + $this->readmeHTML = $this->loadMarkdownAsHTML($directory . '/README.md'); + + $this->licenseHTML = $this->loadMarkdownAsHTML($directory . '/LICENSE.md'); } /** @@ -270,6 +274,11 @@ abstract class BasePlugin implements PluginInterface return $this->manifest->license ?? 'UNLICENSED'; } + final public function getLicenseHTML(): ?string + { + return $this->licenseHTML; + } + /** * @param PluginStatus::ACTIVE|PluginStatus::INACTIVE $value */ @@ -313,7 +322,7 @@ abstract class BasePlugin implements PluginInterface ); } - private function loadReadme(string $path): ?string + private function loadMarkdownAsHTML(string $path): ?string { // TODO: cache readme $readmeMD = @file_get_contents($path); diff --git a/package.json b/package.json index 5ae1005c..7141fecc 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "@github/hotkey": "^3.1.1", "@github/markdown-toolbar-element": "^2.2.3", "@github/relative-time-element": "^4.4.2", + "@patternfly/elements": "^3.0.2", "@tailwindcss/nesting": "0.0.0-insiders.565cd3e", "@vime/core": "^5.4.1", "choices.js": "^10.2.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1e036b60..629edefa 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -43,6 +43,9 @@ importers: "@github/relative-time-element": specifier: ^4.4.2 version: 4.4.2 + "@patternfly/elements": + specifier: ^3.0.2 + version: 3.0.2 "@tailwindcss/nesting": specifier: 0.0.0-insiders.565cd3e version: 0.0.0-insiders.565cd3e(postcss@8.4.39) @@ -2125,6 +2128,12 @@ packages: integrity: sha512-yWJKmpGE6lUURKAaIltoPIE/wrbY3TEkqQt+X0m+7fQNnAv0keydnYvbiJFP1PnMhizmIWRWOG5KLhYyc/xl+g==, } + "@lit/context@1.1.2": + resolution: + { + integrity: sha512-S0nw2C6Tkm7fVX5TGYqeROGD+Z9Coa2iFpW+ysYBDH3YvCqOY3wVQvSgwbaliLJkjTnSEYCBe9qFqKV8WUFpVw==, + } + "@lit/reactive-element@2.0.4": resolution: { @@ -2233,6 +2242,24 @@ packages: integrity: sha512-Y73oOAzRBAUzR/iRAbGULzpNkX8vaxKCqEtg6K74Ff3w9f5apFnWtE/2nade7dMWWW3bS5Kkd6DJS4HF04xreg==, } + "@patternfly/elements@3.0.2": + resolution: + { + integrity: sha512-YsmDu0XP7YyWdwIKXQIvtI81JfQ9+R3QszKQyFlEuhiS1ufA86f7L/1toQvOhZgmEBfAitnJBejndYi5s13EGw==, + } + + "@patternfly/icons@1.0.3": + resolution: + { + integrity: sha512-8BARaCFBUZU2/TxuOQb8R2/VIpxGMnFwdw5ddT1AMnR2KSifdo+d05SgZtVmFkOIAOA0oCo/YKRgSORDA47wig==, + } + + "@patternfly/pfe-core@3.0.0": + resolution: + { + integrity: sha512-zxJ2dksvTsurQ74EHlNWv03P1HH/ZO+axX0XPyjDdkOWpbyL4UDK6x5VXDRRtiZ3CrRs7VX3RbBfB5EQ1gBZ5A==, + } + "@pkgjs/parseargs@0.11.0": resolution: { @@ -10781,6 +10808,10 @@ snapshots: "@lit-labs/ssr-dom-shim@1.2.0": {} + "@lit/context@1.1.2": + dependencies: + "@lit/reactive-element": 2.0.4 + "@lit/reactive-element@2.0.4": dependencies: "@lit-labs/ssr-dom-shim": 1.2.0 @@ -10855,6 +10886,22 @@ snapshots: dependencies: "@octokit/openapi-types": 22.1.0 + "@patternfly/elements@3.0.2": + dependencies: + "@lit/context": 1.1.2 + "@patternfly/icons": 1.0.3 + "@patternfly/pfe-core": 3.0.0 + lit: 3.1.4 + tslib: 2.6.2 + + "@patternfly/icons@1.0.3": {} + + "@patternfly/pfe-core@3.0.0": + dependencies: + "@floating-ui/dom": 1.6.7 + "@lit/context": 1.1.2 + lit: 3.1.4 + "@pkgjs/parseargs@0.11.0": optional: true diff --git a/themes/cp_admin/plugins/view.php b/themes/cp_admin/plugins/view.php index fecff29a..a0310ff1 100644 --- a/themes/cp_admin/plugins/view.php +++ b/themes/cp_admin/plugins/view.php @@ -116,17 +116,32 @@ + + 'icon', + ]) ?>README.md getReadmeHTML()): ?> -
+ getReadmeHTML() ?> -
+ -
- 'text-gray-300 text-6xl', - ]) ?> -

-
+ +
+ 'text-gray-300 text-6xl', + ]) ?> +

+
+
+ getLicenseHTML()): ?> + 'icon', + ]) ?>LICENSE.md + + getLicenseHTML() ?> + + +
endSection() ?> \ No newline at end of file