Skip to content

Commit

Permalink
feat(core): add icon for group and sub-group of plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
loicmathieu committed Mar 20, 2023
1 parent b95c8ed commit 3b750e6
Show file tree
Hide file tree
Showing 12 changed files with 102 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,18 @@ private static List<Document> index(RegisteredPlugin plugin) throws IOException
builder.put("classPlugins", pluginDocumentation.getClassPlugins());
}

if (pluginDocumentation.getIcon() != null) {
builder.put("icon", pluginDocumentation.getIcon());
}

if(!plugin.getGuides().isEmpty()) {
builder.put("guides", plugin.getGuides());
}

return Collections.singletonList(new Document(
docPath(plugin),
render("index", builder.build()),
null
pluginDocumentation.getIcon()
));
}

Expand Down Expand Up @@ -187,6 +191,18 @@ public static String icon(RegisteredPlugin plugin, Class<?> cls ) {
return null;
}

@SneakyThrows
public static String icon(RegisteredPlugin plugin, String iconName) {
InputStream resourceAsStream = plugin.getClassLoader().getResourceAsStream("icons/" + iconName + ".svg");
if (resourceAsStream != null) {
return Base64.getEncoder().encodeToString(
IOUtils.toString(resourceAsStream, Charsets.UTF_8).getBytes(StandardCharsets.UTF_8)
);
}

return null;
}

private static <T> String docPath(RegisteredPlugin registeredPlugin) {
String pluginName = Slugify.of(registeredPlugin.title());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
public class PluginDocumentation {
private String title;
private String group;
private String icon;
private Map<SubGroup, Map<String, List<ClassPlugin>>> classPlugins;

private Map<String, String> guides;

private PluginDocumentation(RegisteredPlugin plugin) {
this.title = plugin.title();
this.group = plugin.group();
this.icon = DocumentationGenerator.icon(plugin, "plugin-icon");

this.classPlugins = plugin.allClassGrouped()
.entrySet()
Expand All @@ -46,7 +48,8 @@ private PluginDocumentation(RegisteredPlugin plugin) {
var subGroupDescription = pluginSubGroup != null ? pluginSubGroup.description() : null;
// hack to avoid adding the subgroup in the task URL when it's the group to keep search engine indexes
var subgroupIsGroup = cls.getPackageName().length() <= this.group.length();
var subgroup = new SubGroup(subGroupName, subGroupTitle, subGroupDescription, subgroupIsGroup);
var subGroupIcon = DocumentationGenerator.icon(plugin, cls.getPackageName());
var subgroup = new SubGroup(subGroupName, subGroupTitle, subGroupDescription, subGroupIcon, subgroupIsGroup);
builder.subgroup(subgroup);
} else {
// should never occur
Expand Down Expand Up @@ -89,6 +92,7 @@ public static class SubGroup implements Comparable<SubGroup>{
String name;
String title;
String description;
String icon;

boolean subgroupIsGroup;

Expand Down
7 changes: 4 additions & 3 deletions core/src/main/resources/docs/index.hbs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
---
title: {{ capitalizeFirst (replace title "-" " ") }}
editLink: false
{{#if icon}}icon: {{ icon }}{{~/if}}
---
# {{ capitalizeFirst (replace title "-" " ") }}
# {{#if icon ~}}<img width="25" src="data:image/svg+xml;base64,{{icon}}" /> {{/if }}{{ capitalizeFirst (replace title "-" " ") }}

{{ description }}

{{ longDescription }}

{{~#each classPlugins }}
{{~#if @key.title}}
## {{ @key.title }}
## {{#if @key.icon ~}}<img width="25" src="data:image/svg+xml;base64,{{@key.icon}}" /> {{/if }}{{ @key.title }}
{{else}}
## {{ @key.name }}
## {{#if @key.icon ~}}<img width="25" src="data:image/svg+xml;base64,{{@key.icon}}" /> {{/if }}{{ @key.name }}
{{/if}}
{{ @key.description }}

Expand Down
10 changes: 10 additions & 0 deletions core/src/main/resources/icons/io.kestra.core.tasks.debugs.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions core/src/main/resources/icons/io.kestra.core.tasks.flows.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions core/src/main/resources/icons/io.kestra.core.tasks.log.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions core/src/main/resources/icons/io.kestra.core.tasks.scripts.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions core/src/main/resources/icons/plugin-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
import jakarta.inject.Inject;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.*;

@MicronautTest
class DocumentationGeneratorTest {
@Inject
JsonSchemaGenerator jsonSchemaGenerator;

@Inject
DocumentationGenerator documentationGenerator;

@Test
void tasks() throws URISyntaxException, IOException {
Path plugins = Paths.get(Objects.requireNonNull(ClassPluginDocumentationTest.class.getClassLoader().getResource("plugins")).toURI());
Expand Down Expand Up @@ -106,4 +108,15 @@ void echo() throws IOException {
assertThat(render, containsString("Echo"));
assertThat(render, containsString("- \uD83D\uDD12 Deprecated"));
}

@Test
void pluginDoc() throws IOException, URISyntaxException {
PluginScanner pluginScanner = new PluginScanner(ClassPluginDocumentationTest.class.getClassLoader());
RegisteredPlugin core = pluginScanner.scan();

List<Document> docs = documentationGenerator.generate(core);
Document doc = docs.get(0);
assertThat(doc.getIcon(), is(notNullValue()));
assertThat(doc.getBody(), containsString("## <img width=\"25\" src=\"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5r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