Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port fixes #620

Merged
merged 7 commits into from
Mar 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,19 @@ 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)
* Upgrade Asciidoctorj to v2.5.5 (#591)
* Upgrade build related Maven plugins to the latest versions (#606)
* Upgrade Asciidoctorj to v2.5.7 (#604)
* Bump netty-codec-http to v4.1.90.Final (fix several CVEs)

Documentation::

Expand Down
17 changes: 8 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,16 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.java.version>1.8</project.java.version>
<project.execution.environment>JavaSE-1.8</project.execution.environment>
<asciidoctorj.version>2.5.5</asciidoctorj.version>
<asciidoctorj.version>2.5.7</asciidoctorj.version>
<jruby.version>9.3.4.0</jruby.version>
<maven.coveralls.plugin.version>4.3.0</maven.coveralls.plugin.version>
<maven.jacoco.plugin.version>0.8.7</maven.jacoco.plugin.version>
<maven.jacoco.plugin.version>0.8.8</maven.jacoco.plugin.version>
<maven.plugin.plugin.version>3.5</maven.plugin.plugin.version>
<maven.project.version>3.0.5</maven.project.version>
<maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version>
<maven.filtering.version>3.2.0</maven.filtering.version>
<plexus.utils.version>3.0.23</plexus.utils.version>
<plexus.component.metadata.version>1.7</plexus.component.metadata.version>
<netty.version>4.1.77.Final</netty.version>
<netty.version>4.1.90.Final</netty.version>
<doxia.version>1.11.1</doxia.version>
</properties>

Expand Down Expand Up @@ -172,7 +171,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<version>3.1.0</version>
<executions>
<execution>
<id>enforce-maven</id>
Expand Down Expand Up @@ -204,7 +203,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<version>3.10.1</version>
<configuration>
<source>${project.java.version}</source>
<target>${project.java.version}</target>
Expand Down Expand Up @@ -322,17 +321,17 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.0</version>
<version>3.4.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<version>3.3.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<version>3.0.0-M7</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/org/asciidoctor/maven/AsciidoctorMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -123,14 +123,14 @@ public class AsciidoctorMojo extends AbstractMojo {
@Parameter
protected List<ExtensionConfiguration> 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<Resource> resources;

@Parameter(property = AsciidoctorMaven.PREFIX + "verbose")
@Parameter(property = AsciidoctorMaven.PREFIX + "verbose", defaultValue = "false")
protected boolean enableVerbose = false;

@Parameter
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ public void should_not_include_github_files_when_allowUriRead_is_false() throws

// then
assertThat(outputDir, "github-include.html")
.contains("link:https://raw.githubusercontent.com/cometd/cometd/4.0.x/pom.xml[]");
.contains("link:https://raw.githubusercontent.com/cometd/cometd/4.0.x/pom.xml[role=include]");
}

@Test
Expand Down
29 changes: 27 additions & 2 deletions src/test/java/org/asciidoctor/maven/AsciidoctorMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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
Expand Down
28 changes: 28 additions & 0 deletions src/test/resources/templates/erb/section.html.erb
Original file line number Diff line number Diff line change
@@ -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 = %(<a class="anchor" href="##{@id}"></a>)
elsif @document.attr? :sectlinks
link_start = %(<a class="link" href="##{@id}">)
link_end = '</a>'
end
end
if slevel.zero?
%><h1<%= @id && %( id="#{@id}") %> class="sect0"><%= %(#{anchor}#{link_start}#{title}#{link_end}) %></h1>
<%= content %><%
else
snum = @numbered && @caption.nil? && slevel <= (@document.attr 'sectnumlevels', 3).to_i ? %(#{sectnum} ) : nil
hlevel = slevel + 1
%><div class="<%= [%(sect#{slevel}),role].compact * ' ' %>">
<h<%= hlevel %><%= @id && %( id="#{@id}") %>><%= %(#{anchor}#{link_start}#{snum}#{captioned_title}#{link_end}) %></h<%= hlevel %>><%
if slevel == 1 %>
<div class="sectionbody custom-style">
<%= content %>
</div><%
else %>
<%= content %><%
end %>
</div><%
end %>