Skip to content

Commit

Permalink
Merge pull request #172 from fnonnenmacher/markdown-exporter
Browse files Browse the repository at this point in the history
Markdown Exporter (#159)
  • Loading branch information
rdmueller committed Jul 13, 2018
2 parents 0aef53c + 2f6bef4 commit 666f6cd
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 1 deletion.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ apply from: 'scripts/exportVisio.gradle'
apply from: 'scripts/exportChangelog.gradle'
apply from: 'scripts/exportJiraIssues.gradle'
apply from: 'scripts/exportExcel.gradle'
apply from: 'scripts/exportMarkdown.gradle'
apply from: 'scripts/pandoc.gradle'
apply from: 'scripts/publishToConfluence.gradle'
apply from: 'scripts/htmlSanityCheck.gradle'

// let's set a defaultTask for convenience
//defaultTasks 'exportChangeLog','exportJiraIssues','asciidoctor'
defaultTasks 'exportChangeLog', 'generateHTML', 'generatePDF', 'htmlSanityCheck'
defaultTasks 'exportChangeLog', 'exportMarkdown', 'generateHTML', 'generatePDF', 'htmlSanityCheck'
32 changes: 32 additions & 0 deletions scripts/exportMarkdown.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
buildscript {
dependencies {
//for the markdown conversion
classpath 'nl.jworks.markdown_to_asciidoc:markdown_to_asciidoc:1.0'
}
repositories {
jcenter()
}
}

//tag::exportMarkdown[]
task exportMarkdown(
description: 'exports all markdown files to AsciiDoc',
group: 'docToolchain',
type: Copy
) {
from srcDir

include("**/*.md") //include only markdown files
includeEmptyDirs = false
rename(/(.+).md/, '$1.adoc') //rename all files from *.md to *.adoc
filter(Markdown2AdocFilter) // convert the content of the files

into targetDir
}

class Markdown2AdocFilter extends FilterReader {
Markdown2AdocFilter(Reader input) {
super(new StringReader(nl.jworks.markdown_to_asciidoc.Converter.convertMarkdownToAsciiDoc(input.text)))
}
}
//end::exportMarkdown[]
5 changes: 5 additions & 0 deletions src/docs/exportMarkdownDocs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# exportMarkdown

The *exportMarkdown* task can be used to include [markdown](http://markdown.de) files into the documentation.

The task is scanning the directory `/src/docs` for markdown files (`*.md`) and converts them into AsciiDoc files.
6 changes: 6 additions & 0 deletions src/docs/manual.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ include::manual/03_task_exportExcel.adoc[leveloffset=+2]

<<<<

include::manual/03_task_exportMarkdown.adoc[leveloffset=+2]

---

<<<<

include::manual/03_task_htmlSanityCheck.adoc[leveloffset=+2]

---
Expand Down
11 changes: 11 additions & 0 deletions src/docs/manual/03_task_exportMarkdown.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ifndef::imagesdir[:imagesdir: ../images]

include::../../../build/docs/exportMarkdownDocs.adoc[]

== Source

.exportMarkdown.gradle
[source,groovy]
----
include::../../../scripts/exportMarkdown.gradle[tags=exportMarkdown]
----
1 change: 1 addition & 0 deletions src/docs/manual/05_contributors.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Here is an incomplete and unordered list of contributors:
- https://twitter.com/marioggar[Mario García]
- https://github.com/joex2[Joe]
- https://github.com/davidmc24[David M. Carr]
- https://github.com/fnonnenmacher[Fabian Nonnenmacher]
(please update your entry to match your preferences! :-)

Expand Down
33 changes: 33 additions & 0 deletions src/test/groovy/docToolchain/ExportMarkdownSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package docToolchain

import org.gradle.testkit.runner.GradleRunner
import spock.lang.Specification

import static org.gradle.testkit.runner.TaskOutcome.SUCCESS

class ExportMarkdownSpec extends Specification {


public static final File exportedMarkdownFile = new File('./build/docs/exportMarkdownDocs.adoc')

void 'test conversion of sample markdown file'() {

given: 'a clean the environment'
exportedMarkdownFile.delete()

when: 'executing the gradle task `exportMarkdown`'
def result = GradleRunner.create()
.withProjectDir(new File('.'))
.withArguments('exportMarkdown')
.build()

then: 'the task has been successfully executed'
result.task(":exportMarkdown").outcome == SUCCESS

and: 'the AsciiDoc file has been created'
exportedMarkdownFile.exists()

and: 'its content is in AsciiDoc syntax'
exportedMarkdownFile.text.startsWith('= exportMarkdown')
}
}

0 comments on commit 666f6cd

Please sign in to comment.