diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 5c6ea198..b6f4d96c 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -13,8 +13,12 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/main[co == Unreleased +Bug Fixes:: + + * Fixed default value for eruby which caused a fail when using erb templates (#610) + Build / Infrastructure:: - + * Bump Doxia to v1.11.1 and maven-site-plugin in IT to 3.12.0 (#579) * Bump netty-codec-http to v4.1.77.Final (fix CVE-2021-21290) (#582) * Upgrade Asciidoctorj to v2.5.4 and jRuby to v9.3.4.0 (#584) diff --git a/src/main/java/org/asciidoctor/maven/AsciidoctorMojo.java b/src/main/java/org/asciidoctor/maven/AsciidoctorMojo.java index 303ff49a..95782c7a 100644 --- a/src/main/java/org/asciidoctor/maven/AsciidoctorMojo.java +++ b/src/main/java/org/asciidoctor/maven/AsciidoctorMojo.java @@ -88,13 +88,13 @@ public class AsciidoctorMojo extends AbstractMojo { protected String attributesChain = ""; @Parameter(property = AsciidoctorMaven.PREFIX + Options.BACKEND, defaultValue = "html5") - protected String backend = ""; + protected String backend = "html5"; @Parameter(property = AsciidoctorMaven.PREFIX + Options.DOCTYPE) protected String doctype; @Parameter(property = AsciidoctorMaven.PREFIX + Options.ERUBY) - protected String eruby = ""; + protected String eruby; @Parameter(property = AsciidoctorMaven.PREFIX + "headerFooter") protected boolean headerFooter = true; @@ -123,14 +123,14 @@ public class AsciidoctorMojo extends AbstractMojo { @Parameter protected List extensions = new ArrayList<>(); - @Parameter(property = AsciidoctorMaven.PREFIX + "embedAssets") + @Parameter(property = AsciidoctorMaven.PREFIX + "embedAssets", defaultValue = "false") protected boolean embedAssets = false; // List of resources to copy to the output directory (e.g., images, css). By default everything is copied @Parameter protected List resources; - @Parameter(property = AsciidoctorMaven.PREFIX + "verbose") + @Parameter(property = AsciidoctorMaven.PREFIX + "verbose", defaultValue = "false") protected boolean enableVerbose = false; @Parameter @@ -476,9 +476,11 @@ protected OptionsBuilder createOptionsBuilder(AsciidoctorMojo configuration, Att .backend(configuration.getBackend()) .safe(SafeMode.UNSAFE) .headerFooter(configuration.isHeaderFooter()) - .eruby(configuration.getEruby()) .mkDirs(true); + if (!isBlank(configuration.getEruby())) + optionsBuilder.eruby(configuration.getEruby()); + if (configuration.isSourcemap()) optionsBuilder.option(Options.SOURCEMAP, true); diff --git a/src/test/java/org/asciidoctor/maven/AsciidoctorMojoTest.java b/src/test/java/org/asciidoctor/maven/AsciidoctorMojoTest.java index d4162dc5..d6342af5 100644 --- a/src/test/java/org/asciidoctor/maven/AsciidoctorMojoTest.java +++ b/src/test/java/org/asciidoctor/maven/AsciidoctorMojoTest.java @@ -179,9 +179,9 @@ public void should_convert_to_html_with_attributes() throws MojoFailureException } @Test - public void should_convert_to_html_with_a_custom_template() throws MojoFailureException, MojoExecutionException { + public void should_convert_to_html_with_a_custom_slim_template() throws MojoFailureException, MojoExecutionException { // given - final String templatesPath = "target/test-classes/templates/"; + final String templatesPath = "target/test-classes/templates/slim/"; File srcDir = new File(DEFAULT_SOURCE_DIRECTORY); File outputDir = newOutputTestDirectory(); @@ -205,6 +205,31 @@ public void should_convert_to_html_with_a_custom_template() throws MojoFailureEx .contains("custom-block-style"); } + @Test + public void should_convert_to_html_with_a_custom_erb_template() throws MojoFailureException, MojoExecutionException { + // given + final String templatesPath = "target/test-classes/templates/"; + File srcDir = new File(DEFAULT_SOURCE_DIRECTORY); + File outputDir = newOutputTestDirectory(); + + // when + AsciidoctorMojo mojo = mockAsciidoctorMojo(); + mojo.backend = "html"; + mojo.sourceDirectory = srcDir; + mojo.sourceDocumentName = "sample.asciidoc"; + mojo.resources = excludeAll(); + mojo.outputDirectory = outputDir; + mojo.templateDirs = Arrays.asList( + new File(templatesPath, "erb") + ); + mojo.execute(); + + // then + assertThat(outputDir, "sample.html") + .isNotEmpty() + .contains("custom-style"); + } + @Test public void should_set_output_file() throws MojoFailureException, MojoExecutionException { // given diff --git a/src/test/resources/templates/erb/section.html.erb b/src/test/resources/templates/erb/section.html.erb new file mode 100644 index 00000000..3f54c5db --- /dev/null +++ b/src/test/resources/templates/erb/section.html.erb @@ -0,0 +1,28 @@ +<%#encoding:UTF-8%><% +slevel = @level.zero? && @special ? 1 : @level +anchor = link_start = link_end = nil +if @id + if @document.attr? :sectanchors + anchor = %() + elsif @document.attr? :sectlinks + link_start = %() + link_end = '' + end +end +if slevel.zero? + %> class="sect0"><%= %(#{anchor}#{link_start}#{title}#{link_end}) %> +<%= content %><% +else + snum = @numbered && @caption.nil? && slevel <= (@document.attr 'sectnumlevels', 3).to_i ? %(#{sectnum} ) : nil + hlevel = slevel + 1 + %>
+<%= @id && %( id="#{@id}") %>><%= %(#{anchor}#{link_start}#{snum}#{captioned_title}#{link_end}) %>><% + if slevel == 1 %> +
+<%= content %> +
<% + else %> +<%= content %><% + end %> +
<% +end %> diff --git a/src/test/resources/templates/set-1/admonition.html.slim b/src/test/resources/templates/slim/set-1/admonition.html.slim similarity index 100% rename from src/test/resources/templates/set-1/admonition.html.slim rename to src/test/resources/templates/slim/set-1/admonition.html.slim diff --git a/src/test/resources/templates/set-2/block_paragraph.html.slim b/src/test/resources/templates/slim/set-2/block_paragraph.html.slim similarity index 100% rename from src/test/resources/templates/set-2/block_paragraph.html.slim rename to src/test/resources/templates/slim/set-2/block_paragraph.html.slim