Skip to content

Commit

Permalink
fixes #72
Browse files Browse the repository at this point in the history
  • Loading branch information
rmpestano committed Oct 23, 2016
1 parent ba9ab9e commit d985b5c
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.github.cukedoctor.api.CukedoctorConverter;
import com.github.cukedoctor.api.DocumentAttributes;
import com.github.cukedoctor.api.model.Feature;
import com.github.cukedoctor.config.GlobalConfig;
import com.github.cukedoctor.parser.FeatureParser;
import com.github.cukedoctor.util.FileUtil;
import org.asciidoctor.Asciidoctor;
Expand Down Expand Up @@ -68,6 +69,10 @@ public class CukedoctorMain {
private String cucumberResultPaths;


@Parameter(names = "-sourceHighlighter", description = "Configures source highlighter. Default is highlightjs", required = false)
private String sourceHighlighter;


private static List<Feature> searchPathAndScan(String path) {
if (path.endsWith(".json")) {
return FeatureParser.parse(FileUtil.findJsonFile(path));
Expand Down Expand Up @@ -149,7 +154,7 @@ public String execute(String args[]) {
}


DocumentAttributes documentAttributes = new DocumentAttributes().
DocumentAttributes documentAttributes = GlobalConfig.newInstance().getDocumentAttributes().
backend(format).
toc(toc).
revNumber(docVersion).
Expand All @@ -161,6 +166,11 @@ public String execute(String args[]) {
} else {
documentAttributes.docInfo(true).pdfTheme(false);
}

if(sourceHighlighter != null){
documentAttributes.sourceHighlighter(sourceHighlighter);
}

if (outputName.contains(".")) {
outputName = outputName.substring(0, outputName.lastIndexOf(".")) + ".adoc";
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,27 @@ public void shouldCreateDocumentationWithoutStepTime() throws IOException {
}
}

@Test
public void shouldCreateDocumentationUsingCoderaySourceHighlighter() throws IOException {
try {
new CukedoctorMain().execute(new String[]{
"-hideStepTime", "",
"-sourceHighlighter", "coderay",
"-p", "\"target/test-classes/json-output/one_passing_one_failing.json\""
});
File generatedFile = FileUtil.loadFile("Living-Documentation.adoc");
assertThat(generatedFile).exists();

assertThat(contentOf(generatedFile)).
contains(":source-highlighter: coderay");

} finally {
FileUtil.removeFile("Living-Documentation.adoc");
FileUtil.removeFile("Living-Documentation.html");
}
}


@Test
public void shouldCreateDocumentationWithoutTags() throws IOException {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.github.cukedoctor.api.CukedoctorConverter;
import com.github.cukedoctor.api.DocumentAttributes;
import com.github.cukedoctor.api.model.Feature;
import com.github.cukedoctor.config.GlobalConfig;
import com.github.cukedoctor.mojo.model.Format;
import com.github.cukedoctor.mojo.model.Toc;
import com.github.cukedoctor.parser.FeatureParser;
Expand Down Expand Up @@ -102,6 +103,10 @@ public class CukedoctorMojo extends AbstractMojo {
@Parameter(required = false)
Boolean hideTags;

@Parameter(required = false)
String sourceHighlighter;


@Parameter(property = "cukedoctor.skip", defaultValue = "false")
private boolean skip;

Expand Down Expand Up @@ -162,7 +167,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}

configExtensions();
DocumentAttributes documentAttributes = new DocumentAttributes().
DocumentAttributes documentAttributes = GlobalConfig.newInstance().getDocumentAttributes().
backend(format.name().toLowerCase()).
toc(toc.name().toLowerCase()).
revNumber(docVersion).
Expand All @@ -179,6 +184,11 @@ public void execute() throws MojoExecutionException, MojoFailureException {
if (documentTitle == null) {
documentTitle = "Living Documentation";
}

if(sourceHighlighter != null) {
documentAttributes.sourceHighlighter(sourceHighlighter);
}

documentAttributes.docTitle(documentTitle);
CukedoctorConverter converter = Cukedoctor.instance(featuresFound, documentAttributes);
String targetFile = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,21 @@ public void testGeneratePdfDocs() throws Exception {
contains(":backend: pdf");
}

/**
* @throws Exception
*/
public void testGenerateHtmlDocsWithCoderayAsSourceHighlighter() throws Exception {

CukedoctorMojo mojo = (CukedoctorMojo) lookupMojo("execute", getTestFile("src/test/resources/html-docs-source-highlighter-pom.xml"));

assertNotNull(mojo);
mojo.execute();
File file = FileUtil.loadFile(mojo.getDocumentationDir() + mojo.outputFileName + ".adoc");
assertThat(file).exists();
assertThat(contentOf(file)).
contains(":source-highlighter: coderay");
}

/**
* @throws Exception
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.cukedoctor</groupId>
<artifactId>cukedoctor-mojo</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>com.github.cukedoctor</groupId>
<artifactId>cukedoctor-maven-plugin</artifactId>
<!--<version>0.1-SNAPSHOT</version>-->
<configuration>
<project implementation="com.github.cukedoctor.mojo.stub.CukedoctorMojoStub"/>
<outputFileName>documentation</outputFileName>
<outputDir>docs</outputDir>
<format>html5</format>
<toc>left</toc>
<numbered>true</numbered>
<sourceHighlighter>coderay</sourceHighlighter>
</configuration>
</plugin>
</plugins>
</build>
</project>

0 comments on commit d985b5c

Please sign in to comment.