From ecef520cb35eb493a22f68804eb0f153d2b684aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Vav=C5=99=C3=ADk?= Date: Sat, 9 Nov 2024 17:57:17 +0100 Subject: [PATCH] Add copy button for configuration property --- .../config/doc/GenerateConfigDocMojo.java | 16 +++++++++++--- .../default/tags/configProperty.qute.adoc | 4 ++-- .../default/tags/propertyCopyButton.qute.adoc | 1 + docs/pom.xml | 5 +++++ ...ropertyCopyButtonInlineMacroProcessor.java | 22 +++++++++++++++++++ 5 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 devtools/config-doc-maven-plugin/src/main/resources/templates/asciidoc/default/tags/propertyCopyButton.qute.adoc create mode 100644 docs/src/main/java/io/quarkus/docs/generation/PropertyCopyButtonInlineMacroProcessor.java diff --git a/devtools/config-doc-maven-plugin/src/main/java/io/quarkus/maven/config/doc/GenerateConfigDocMojo.java b/devtools/config-doc-maven-plugin/src/main/java/io/quarkus/maven/config/doc/GenerateConfigDocMojo.java index ba0cf3fff9f25..be0d17b360bce 100644 --- a/devtools/config-doc-maven-plugin/src/main/java/io/quarkus/maven/config/doc/GenerateConfigDocMojo.java +++ b/devtools/config-doc-maven-plugin/src/main/java/io/quarkus/maven/config/doc/GenerateConfigDocMojo.java @@ -40,6 +40,7 @@ import io.quarkus.maven.config.doc.generator.GenerationReport; import io.quarkus.maven.config.doc.generator.GenerationReport.GenerationViolation; import io.quarkus.qute.Engine; +import io.quarkus.qute.EngineBuilder; import io.quarkus.qute.ReflectionValueResolver; import io.quarkus.qute.UserTagSectionHelper; import io.quarkus.qute.ValueResolver; @@ -296,7 +297,7 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th } private static Engine initializeQuteEngine(Formatter formatter, Format format, String theme) { - Engine engine = Engine.builder() + EngineBuilder engineBuilder = Engine.builder() .addDefaults() .addSectionHelper(new UserTagSectionHelper.Factory("configProperty", "configProperty")) .addSectionHelper(new UserTagSectionHelper.Factory("configSection", "configSection")) @@ -402,9 +403,13 @@ private static Engine initializeQuteEngine(Formatter formatter, Format format, S .applyToName("formatName") .applyToNoParameters() .resolveSync(ctx -> formatter.formatName((Extension) ctx.getBase())) - .build()) - .build(); + .build()); + + if (format == Format.asciidoc) { + engineBuilder.addSectionHelper(new UserTagSectionHelper.Factory("propertyCopyButton", "propertyCopyButton")); + } + Engine engine = engineBuilder.build(); engine.putTemplate("configReference", engine.parse(getTemplate("templates", format, theme, "configReference", false))); engine.putTemplate("allConfig", @@ -420,6 +425,11 @@ private static Engine initializeQuteEngine(Formatter formatter, Format format, S engine.putTemplate("memorySizeNote", engine.parse(getTemplate("templates", format, theme, "memorySizeNote", true))); + if (format == Format.asciidoc) { + engine.putTemplate("propertyCopyButton", + engine.parse(getTemplate("templates", format, theme, "propertyCopyButton", true))); + } + return engine; } diff --git a/devtools/config-doc-maven-plugin/src/main/resources/templates/asciidoc/default/tags/configProperty.qute.adoc b/devtools/config-doc-maven-plugin/src/main/resources/templates/asciidoc/default/tags/configProperty.qute.adoc index b57486b8dbc47..cfa58175f327c 100644 --- a/devtools/config-doc-maven-plugin/src/main/resources/templates/asciidoc/default/tags/configProperty.qute.adoc +++ b/devtools/config-doc-maven-plugin/src/main/resources/templates/asciidoc/default/tags/configProperty.qute.adoc @@ -1,7 +1,7 @@ -a|{#if configProperty.phase.fixedAtBuildTime}icon:lock[title=Fixed at build time]{/if} [[{configProperty.toAnchor(extension, additionalAnchorPrefix)}]] [.property-path]##link:#{configProperty.toAnchor(extension, additionalAnchorPrefix)}[`{configProperty.path.property}`]## +a|{#if configProperty.phase.fixedAtBuildTime}icon:lock[title=Fixed at build time]{/if} [[{configProperty.toAnchor(extension, additionalAnchorPrefix)}]] [.property-path]##link:#{configProperty.toAnchor(extension, additionalAnchorPrefix)}[`{configProperty.path.property}`]## {#propertyCopyButton configProperty.path.property /} {#for additionalPath in configProperty.additionalPaths} -`{additionalPath.property}` +`{additionalPath.property}` {#propertyCopyButton additionalPath.property /} {/for} [.description] diff --git a/devtools/config-doc-maven-plugin/src/main/resources/templates/asciidoc/default/tags/propertyCopyButton.qute.adoc b/devtools/config-doc-maven-plugin/src/main/resources/templates/asciidoc/default/tags/propertyCopyButton.qute.adoc new file mode 100644 index 0000000000000..7fcf95242be8f --- /dev/null +++ b/devtools/config-doc-maven-plugin/src/main/resources/templates/asciidoc/default/tags/propertyCopyButton.qute.adoc @@ -0,0 +1 @@ +config_property_copy_button:+++{it}+++[] \ No newline at end of file diff --git a/docs/pom.xml b/docs/pom.xml index 29dd7a55c0a9f..19bec36fe73d4 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -3442,6 +3442,11 @@ io.quarkus.docs.generation.TooltipInlineMacroProcessor tooltip + + + io.quarkus.docs.generation.PropertyCopyButtonInlineMacroProcessor + config_property_copy_button + diff --git a/docs/src/main/java/io/quarkus/docs/generation/PropertyCopyButtonInlineMacroProcessor.java b/docs/src/main/java/io/quarkus/docs/generation/PropertyCopyButtonInlineMacroProcessor.java new file mode 100644 index 0000000000000..b99e88f4c4b53 --- /dev/null +++ b/docs/src/main/java/io/quarkus/docs/generation/PropertyCopyButtonInlineMacroProcessor.java @@ -0,0 +1,22 @@ +package io.quarkus.docs.generation; + +import java.util.Map; + +import org.asciidoctor.ast.ContentNode; +import org.asciidoctor.extension.InlineMacroProcessor; +import org.asciidoctor.extension.Name; + +/** + * Inline macro implementation for PDF (HTML) files where copy button is not supported. + * The copy button macro is replaced with empty HTML 'code' element. The empty element is part of the DOM but not visible. + * This processor must exist because we cannot use Asciidoc 'ifdef' directive inline inside a config table row. + */ +@Name("config_property_copy_button") +public class PropertyCopyButtonInlineMacroProcessor extends InlineMacroProcessor { + + @Override + public Object process(ContentNode contentNode, String target, Map map) { + // creates empty 'code' element: + return createPhraseNode(contentNode, "quoted", ""); + } +}