Skip to content

Commit bfea074

Browse files
committed
Fixes conversion failure when using erb template
Internally erubi option was set as null which caused Asciidoctor to fail with 'Unknown ERB implementation'. The fix sets the option only when a non empty value is present, delegating to AsciidoctorJ default which is 'erb' (consistent with current docs).
1 parent d7cb395 commit bfea074

File tree

6 files changed

+68
-7
lines changed

6 files changed

+68
-7
lines changed

CHANGELOG.adoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/main[co
1313

1414
== Unreleased
1515

16+
Bug Fixes::
17+
18+
* Fixed default value for eruby which caused a fail when using erb templates (#610)
19+
1620
Improvements::
1721

1822
* Split plugin and site integration in sub-modules: asciidoctor-maven-plugin and asciidoctor-doxia-module (#595)

asciidoctor-maven-plugin/src/main/java/org/asciidoctor/maven/AsciidoctorMojo.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.asciidoctor.jruby.AsciidoctorJRuby;
1111
import org.asciidoctor.jruby.internal.JRubyRuntimeContext;
1212
import org.asciidoctor.maven.commons.AsciidoctorHelper;
13+
import org.asciidoctor.maven.commons.StringUtils;
1314
import org.asciidoctor.maven.extensions.AsciidoctorJExtensionRegistry;
1415
import org.asciidoctor.maven.extensions.ExtensionConfiguration;
1516
import org.asciidoctor.maven.extensions.ExtensionRegistry;
@@ -32,6 +33,7 @@
3233
import java.util.logging.Logger;
3334
import java.util.stream.Collectors;
3435

36+
import static org.asciidoctor.maven.commons.StringUtils.isBlank;
3537
import static org.asciidoctor.maven.process.SourceDirectoryFinder.DEFAULT_SOURCE_DIR;
3638

3739

@@ -81,13 +83,13 @@ public class AsciidoctorMojo extends AbstractMojo {
8183
protected String attributesChain = "";
8284

8385
@Parameter(property = AsciidoctorMaven.PREFIX + Options.BACKEND, defaultValue = "html5")
84-
protected String backend = "";
86+
protected String backend = "html5";
8587

8688
@Parameter(property = AsciidoctorMaven.PREFIX + Options.DOCTYPE)
8789
protected String doctype;
8890

8991
@Parameter(property = AsciidoctorMaven.PREFIX + Options.ERUBY)
90-
protected String eruby = "";
92+
protected String eruby;
9193

9294
@Parameter(property = AsciidoctorMaven.PREFIX + "headerFooter")
9395
protected boolean headerFooter = true;
@@ -116,14 +118,14 @@ public class AsciidoctorMojo extends AbstractMojo {
116118
@Parameter
117119
protected List<ExtensionConfiguration> extensions = new ArrayList<>();
118120

119-
@Parameter(property = AsciidoctorMaven.PREFIX + "embedAssets")
121+
@Parameter(property = AsciidoctorMaven.PREFIX + "embedAssets", defaultValue = "false")
120122
protected boolean embedAssets = false;
121123

122124
// List of resources to copy to the output directory (e.g., images, css). By default everything is copied
123125
@Parameter
124126
protected List<Resource> resources;
125127

126-
@Parameter(property = AsciidoctorMaven.PREFIX + "verbose")
128+
@Parameter(property = AsciidoctorMaven.PREFIX + "verbose", defaultValue = "false")
127129
protected boolean enableVerbose = false;
128130

129131
@Parameter
@@ -388,9 +390,11 @@ protected OptionsBuilder createOptionsBuilder(AsciidoctorMojo configuration, Att
388390
.backend(configuration.getBackend())
389391
.safe(SafeMode.UNSAFE)
390392
.headerFooter(configuration.isHeaderFooter())
391-
.eruby(configuration.getEruby())
392393
.mkDirs(true);
393394

395+
if (!isBlank(configuration.getEruby()))
396+
optionsBuilder.eruby(configuration.getEruby());
397+
394398
if (configuration.isSourcemap())
395399
optionsBuilder.option(Options.SOURCEMAP, true);
396400

asciidoctor-maven-plugin/src/test/java/org/asciidoctor/maven/AsciidoctorMojoTest.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ public void should_convert_to_html_with_attributes() throws MojoFailureException
177177
}
178178

179179
@Test
180-
public void should_convert_to_html_with_a_custom_template() throws MojoFailureException, MojoExecutionException {
180+
public void should_convert_to_html_with_a_custom_slim_template() throws MojoFailureException, MojoExecutionException {
181181
// given
182-
final String templatesPath = "target/test-classes/templates/";
182+
final String templatesPath = "target/test-classes/templates/slim/";
183183
File srcDir = new File(DEFAULT_SOURCE_DIRECTORY);
184184
File outputDir = newOutputTestDirectory();
185185

@@ -203,6 +203,31 @@ public void should_convert_to_html_with_a_custom_template() throws MojoFailureEx
203203
.contains("custom-block-style");
204204
}
205205

206+
@Test
207+
public void should_convert_to_html_with_a_custom_erb_template() throws MojoFailureException, MojoExecutionException {
208+
// given
209+
final String templatesPath = "target/test-classes/templates/";
210+
File srcDir = new File(DEFAULT_SOURCE_DIRECTORY);
211+
File outputDir = newOutputTestDirectory();
212+
213+
// when
214+
AsciidoctorMojo mojo = mockAsciidoctorMojo();
215+
mojo.backend = "html";
216+
mojo.sourceDirectory = srcDir;
217+
mojo.sourceDocumentName = "sample.asciidoc";
218+
mojo.resources = excludeAll();
219+
mojo.outputDirectory = outputDir;
220+
mojo.templateDirs = Arrays.asList(
221+
new File(templatesPath, "erb")
222+
);
223+
mojo.execute();
224+
225+
// then
226+
assertThat(outputDir, "sample.html")
227+
.isNotEmpty()
228+
.contains("custom-style");
229+
}
230+
206231
@Test
207232
public void should_set_output_file() throws MojoFailureException, MojoExecutionException {
208233
// given
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<%#encoding:UTF-8%><%
2+
slevel = @level.zero? && @special ? 1 : @level
3+
anchor = link_start = link_end = nil
4+
if @id
5+
if @document.attr? :sectanchors
6+
anchor = %(<a class="anchor" href="##{@id}"></a>)
7+
elsif @document.attr? :sectlinks
8+
link_start = %(<a class="link" href="##{@id}">)
9+
link_end = '</a>'
10+
end
11+
end
12+
if slevel.zero?
13+
%><h1<%= @id && %( id="#{@id}") %> class="sect0"><%= %(#{anchor}#{link_start}#{title}#{link_end}) %></h1>
14+
<%= content %><%
15+
else
16+
snum = @numbered && @caption.nil? && slevel <= (@document.attr 'sectnumlevels', 3).to_i ? %(#{sectnum} ) : nil
17+
hlevel = slevel + 1
18+
%><div class="<%= [%(sect#{slevel}),role].compact * ' ' %>">
19+
<h<%= hlevel %><%= @id && %( id="#{@id}") %>><%= %(#{anchor}#{link_start}#{snum}#{captioned_title}#{link_end}) %></h<%= hlevel %>><%
20+
if slevel == 1 %>
21+
<div class="sectionbody custom-style">
22+
<%= content %>
23+
</div><%
24+
else %>
25+
<%= content %><%
26+
end %>
27+
</div><%
28+
end %>

0 commit comments

Comments
 (0)