Skip to content

Commit

Permalink
fixes #329 (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsromero committed Jan 16, 2018
1 parent fe0f0f9 commit 49fb85f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/it/maven-site-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<version>3.4</version>
<configuration>
<asciidoc>
<baseDir>${project.basedir}/src/site/asciidoc</baseDir>
<templateDirs>
<dir>src/site/asciidoc/templates</dir>
</templateDirs>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,20 @@ else if ("requires".equals(optName)) {
}
}
else if ("templateDir".equals(optName) || "template_dir".equals(optName)) {
options.templateDir(resolveTemplateDir(project, asciidocOpt.getValue()));
options.templateDir(resolveProjectDir(project, asciidocOpt.getValue()));
}
else if ("templateDirs".equals(optName) || "template_dirs".equals(optName)) {
List<File> templateDirs = new ArrayList<File>();
for (Xpp3Dom dir : asciidocOpt.getChildren("dir")) {
templateDirs.add(resolveTemplateDir(project, dir.getValue()));
templateDirs.add(resolveProjectDir(project, dir.getValue()));
}
if (!templateDirs.isEmpty()) {
options.templateDirs(templateDirs.toArray(new File[templateDirs.size()]));
}
}
else if ("baseDir".equals(optName)) {
options.baseDir(resolveProjectDir(project, asciidocOpt.getValue()));
}
else {
options.option(optName.replaceAll("(?<!_)([A-Z])", "_$1").toLowerCase(), asciidocOpt.getValue());
}
Expand All @@ -177,12 +180,12 @@ protected String convertAsciiDoc(String source, OptionsBuilder options) {
return asciidoctor.convert(source, options);
}

protected File resolveTemplateDir(MavenProject project, String path) {
File templateDir = new File(path);
if (!templateDir.isAbsolute()) {
templateDir = new File(project.getBasedir(), templateDir.toString());
protected File resolveProjectDir(MavenProject project, String path) {
File filePath = new File(path);
if (!filePath.isAbsolute()) {
filePath = new File(project.getBasedir(), filePath.toString());
}
return templateDir;
return filePath;
}

private void requireLibrary(String require) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@ class AsciidoctorDoxiaParserTest extends Specification {
outputText.contains 'println "HelloWorld from Groovy on ${new Date()}"'
}

def "should render html with relative baseDir option"() {
given:
final File srcAsciidoc = new File("$TEST_DOCS_PATH/main-document.adoc")
final Sink sink = createSinkMock()

AsciidoctorDoxiaParser parser = new AsciidoctorDoxiaParser()
parser.@project = createMavenProjectMock("""
<configuration>
<asciidoc>
<baseDir>${TEST_DOCS_PATH}</baseDir>
</asciidoc>
</configuration>""")

when:
parser.parse(new FileReader(srcAsciidoc), sink)

then: 'include works'
String outputText = sink.sinkedText
outputText.contains '<h1>Include test</h1>'
outputText.contains 'println "HelloWorld from Groovy on ${new Date()}"'
}

def "should render html with templateDir option"() {
given:
final File srcAsciidoc = new File("$TEST_DOCS_PATH/sample.asciidoc")
Expand Down

0 comments on commit 49fb85f

Please sign in to comment.