Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e8096b6e6 | ||
|
|
3b880a6a0d | ||
|
|
7a87b33776 | ||
|
|
e5a94cc9d2 | ||
|
|
a52661bb77 |
24
README.adoc
24
README.adoc
@@ -1,9 +1,9 @@
|
||||
= MarkupDocBuilder
|
||||
:author: Robert Winkler
|
||||
:version: 0.1.1
|
||||
:version: 0.1.2
|
||||
:hardbreaks:
|
||||
|
||||
image:https://travis-ci.org/RobWin/markup-document-builder.svg["Build Status", link="https://travis-ci.org/RobWin/markup-document-builder"] image:https://coveralls.io/repos/RobWin/markup-document-builder/badge.svg["Coverage Status", link="https://coveralls.io/r/RobWin/markup-document-builder"] image:http://img.shields.io/:version-{version}-blue.svg["Semantic Versioning", link="https://bintray.com/robwin/maven/markup-document-builder/0.1.1/view"] image:http://img.shields.io/badge/license-ASF2-blue.svg["Apache License 2", link="http://www.apache.org/licenses/LICENSE-2.0.txt"]
|
||||
image:https://travis-ci.org/RobWin/markup-document-builder.svg["Build Status", link="https://travis-ci.org/RobWin/markup-document-builder"] image:https://coveralls.io/repos/RobWin/markup-document-builder/badge.svg["Coverage Status", link="https://coveralls.io/r/RobWin/markup-document-builder"] image:https://api.bintray.com/packages/robwin/maven/markup-document-builder/images/download.svg[link="https://bintray.com/robwin/maven/markup-document-builder/_latestVersion"] image:http://img.shields.io/badge/license-ASF2-blue.svg["Apache License 2", link="http://www.apache.org/licenses/LICENSE-2.0.txt"]
|
||||
|
||||
== Overview
|
||||
|
||||
@@ -33,7 +33,7 @@ The project is published in JCenter and Maven Central.
|
||||
<dependency>
|
||||
<groupId>io.github.robwin</groupId>
|
||||
<artifactId>markup-document-builder</artifactId>
|
||||
<version>0.1.1</version>
|
||||
<version>0.1.2</version>
|
||||
</dependency>
|
||||
----
|
||||
|
||||
@@ -45,7 +45,7 @@ repositories {
|
||||
jcenter()
|
||||
}
|
||||
|
||||
compile "io.github.robwin:markup-document-builder:0.1.1"
|
||||
compile "io.github.robwin:markup-document-builder:0.1.2"
|
||||
----
|
||||
|
||||
=== Using MarkupDocBuilder
|
||||
@@ -56,14 +56,14 @@ The MarkupDocBuilder allows to build an AsciiDoc or Markdown document via the Bu
|
||||
----
|
||||
public class MarkupDocBuilderTest {
|
||||
|
||||
List<String> tableCsvRows;
|
||||
List<String> tableRowsInPSV;
|
||||
|
||||
@Before
|
||||
public void setUp(){
|
||||
tableCsvRows = new ArrayList<>();
|
||||
tableCsvRows.add("Header 1,Header 2,Header2");
|
||||
tableCsvRows.add("Row 1 Column 1,Row 1 Column 2,Row 1 Column 3");
|
||||
tableCsvRows.add("Row 2 Column 1,Row 2 Column 2,Row 2 Column 3");
|
||||
tableRowsInPSV = new ArrayList<>();
|
||||
tableRowsInPSV.add("Header 1 | Header 2 | Header2");
|
||||
tableRowsInPSV.add("Row 1, Column 1 | Row 1, Column 2 | Row 1, Column 3");
|
||||
tableRowsInPSV.add("Row 2, Column 1 | Row 2, Column 2 | Row 2, Column 3");
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ public class MarkupDocBuilderTest {
|
||||
.paragraph("Paragraph with long text bla bla bla bla bla")
|
||||
.listing("Source code listing")
|
||||
.source("MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC)", "java")
|
||||
.tableWithHeaderRow(tableCsvRows)
|
||||
.tableWithHeaderRow(tableRowsInPSV)
|
||||
.sectionTitleLevel1("Section Level 1b")
|
||||
.sectionTitleLevel2("Section Level 2b")
|
||||
.boldTextLine("Bold text line b")
|
||||
@@ -95,8 +95,8 @@ public class MarkupDocBuilderTest {
|
||||
.sectionTitleLevel3("Section Level 3a")
|
||||
.paragraph("Paragraph with long text bla bla bla bla bla")
|
||||
.listing("Source code listing")
|
||||
.source("MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC)", "java")
|
||||
.tableWithHeaderRow(tableCsvRows)
|
||||
.source("MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN)", "java")
|
||||
.tableWithHeaderRow(tableRowsInPSV)
|
||||
.sectionTitleLevel1("Section Level 1b")
|
||||
.sectionTitleLevel2("Section Level 2b")
|
||||
.boldTextLine("Bold text line b")
|
||||
|
||||
@@ -13,7 +13,7 @@ buildscript {
|
||||
}
|
||||
}
|
||||
description = 'A Markup (Markdown, AsciiDoc) document builder'
|
||||
version = '0.1.1'
|
||||
version = '0.1.2'
|
||||
group = 'io.github.robwin'
|
||||
|
||||
apply plugin: 'java'
|
||||
|
||||
@@ -65,6 +65,15 @@ publishing {
|
||||
pom.withXml {
|
||||
def devs = ['RobWin': 'Robert Winkler']
|
||||
def root = asNode()
|
||||
|
||||
root.dependencies.'*'.findAll() {
|
||||
it.scope.text() == 'runtime' && project.configurations.compile.allDependencies.find { dep ->
|
||||
dep.name == it.artifactId.text()
|
||||
}
|
||||
}.each() {
|
||||
it.scope*.value = 'compile'
|
||||
}
|
||||
|
||||
root.appendNode('name', 'markup-document-builder')
|
||||
root.appendNode('packaging', 'jar')
|
||||
root.appendNode('url', 'https://github.com/RobWin/markup-document-builder')
|
||||
|
||||
@@ -32,7 +32,9 @@ public interface MarkupDocBuilder {
|
||||
|
||||
MarkupDocBuilder unorderedList(List<String> list);
|
||||
|
||||
MarkupDocBuilder tableWithHeaderRow(List<String> rowsInCSV);
|
||||
MarkupDocBuilder tableWithHeaderRow(List<String> rowsInPSV);
|
||||
|
||||
MarkupDocBuilder crossReference(String text);
|
||||
|
||||
MarkupDocBuilder newLine();
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import io.github.robwin.markup.builder.Markup;
|
||||
public enum AsciiDoc implements Markup {
|
||||
LABELED(":: "),
|
||||
TABLE("|==="),
|
||||
TABLE_COLUMN_DELIMITER("|"),
|
||||
LISTING("----"),
|
||||
HARDBREAKS(":hardbreaks:"),
|
||||
DOCUMENT_TITLE("= "),
|
||||
@@ -17,7 +18,9 @@ public enum AsciiDoc implements Markup {
|
||||
SECTION_TITLE_LEVEL3("==== "),
|
||||
BOLD("*"),
|
||||
ITALIC("_"),
|
||||
LIST_ENTRY("* ");
|
||||
LIST_ENTRY("* "),
|
||||
CROSS_REFERENCE_START("<<"),
|
||||
CROSS_REFERENCE_END(">>");
|
||||
|
||||
private final String markup;
|
||||
|
||||
|
||||
@@ -80,16 +80,22 @@ public class AsciiDocBuilder extends AbstractMarkupDocBuilder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder tableWithHeaderRow(List<String> rowsInCSV){
|
||||
documentBuilder.append("[format=\"csv\", options=\"header\"]").append(newLine);
|
||||
public MarkupDocBuilder tableWithHeaderRow(List<String> rowsInPSV){
|
||||
documentBuilder.append("[options=\"header\"]").append(newLine);
|
||||
documentBuilder.append(AsciiDoc.TABLE).append(newLine);
|
||||
for(String row : rowsInCSV){
|
||||
documentBuilder.append(row).append(newLine);
|
||||
for(String row : rowsInPSV){
|
||||
documentBuilder.append(AsciiDoc.TABLE_COLUMN_DELIMITER).append(row).append(newLine);
|
||||
}
|
||||
documentBuilder.append(AsciiDoc.TABLE).append(newLine).append(newLine);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder crossReference(String text) {
|
||||
documentBuilder.append(AsciiDoc.CROSS_REFERENCE_START).append(text).append(AsciiDoc.CROSS_REFERENCE_END);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToFile(String directory, String fileName, Charset charset) throws IOException {
|
||||
String fileNameWithExtension = fileName + ".adoc";
|
||||
|
||||
@@ -7,7 +7,7 @@ import io.github.robwin.markup.builder.Markup;
|
||||
*/
|
||||
public enum Markdown implements Markup {
|
||||
HARDBREAKS(""),
|
||||
TABLE_COLUMN("|"),
|
||||
TABLE_COLUMN_DELIMITER("|"),
|
||||
TABLE_ROW("-"),
|
||||
LISTING("```"),
|
||||
DOCUMENT_TITLE("# "),
|
||||
|
||||
@@ -82,38 +82,42 @@ public class MarkdownBuilder extends AbstractMarkupDocBuilder
|
||||
}
|
||||
|
||||
@Override
|
||||
public MarkupDocBuilder tableWithHeaderRow(List<String> rowsInCSV){
|
||||
String headersInCSV = rowsInCSV.get(0);
|
||||
List<String> contentRowsInCSV = rowsInCSV.subList(1, rowsInCSV.size());
|
||||
List<String> headers = Arrays.asList(headersInCSV.split(","));
|
||||
public MarkupDocBuilder tableWithHeaderRow(List<String> rowsInPSV){
|
||||
String headersInPSV = rowsInPSV.get(0);
|
||||
List<String> contentRowsInPSV = rowsInPSV.subList(1, rowsInPSV.size());
|
||||
String[] headersAsArray = headersInPSV.split(String.format("\\%s", Markdown.TABLE_COLUMN_DELIMITER.toString()));
|
||||
List<String> headers = Arrays.asList(headersAsArray);
|
||||
// Header
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN);
|
||||
for(String header : headers){
|
||||
documentBuilder.append(header).append(Markdown.TABLE_COLUMN);
|
||||
}
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
|
||||
documentBuilder.append(headersInPSV);
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
|
||||
newLine();
|
||||
// Header/Content separator
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN);
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
|
||||
for(String header : headers){
|
||||
for(int i = 1; i<5; i++) {
|
||||
documentBuilder.append(Markdown.TABLE_ROW);
|
||||
}
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN);
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
|
||||
}
|
||||
newLine();
|
||||
// Content
|
||||
for(String contentRow : contentRowsInCSV){
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN);
|
||||
List<String> columns = Arrays.asList(contentRow.split(","));
|
||||
for(String columnText : columns){
|
||||
documentBuilder.append(columnText).append(Markdown.TABLE_COLUMN);
|
||||
}
|
||||
for(String contentRowInPSV : contentRowsInPSV){
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
|
||||
documentBuilder.append(contentRowInPSV);
|
||||
documentBuilder.append(Markdown.TABLE_COLUMN_DELIMITER.toString());
|
||||
newLine();
|
||||
}
|
||||
newLine().newLine();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
// TODO
|
||||
public MarkupDocBuilder crossReference(String text) {
|
||||
throw new UnsupportedOperationException("Not yet supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToFile(String directory, String fileName, Charset charset) throws IOException {
|
||||
String fileNameWithExtension = fileName + ".md";
|
||||
|
||||
@@ -14,14 +14,14 @@ import java.util.List;
|
||||
*/
|
||||
public class MarkupDocBuilderTest {
|
||||
|
||||
List<String> tableCsvRows;
|
||||
List<String> tableRowsInPSV;
|
||||
|
||||
@Before
|
||||
public void setUp(){
|
||||
tableCsvRows = new ArrayList<>();
|
||||
tableCsvRows.add("Header 1,Header 2,Header2");
|
||||
tableCsvRows.add("Row 1 Column 1,Row 1 Column 2,Row 1 Column 3");
|
||||
tableCsvRows.add("Row 2 Column 1,Row 2 Column 2,Row 2 Column 3");
|
||||
tableRowsInPSV = new ArrayList<>();
|
||||
tableRowsInPSV.add("Header 1 | Header 2 | Header2");
|
||||
tableRowsInPSV.add("Row 1, Column 1 | Row 1, Column 2 | Row 1, Column 3");
|
||||
tableRowsInPSV.add("Row 2, Column 1 | Row 2, Column 2 | Row 2, Column 3");
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public class MarkupDocBuilderTest {
|
||||
.paragraph("Paragraph with long text bla bla bla bla bla")
|
||||
.listing("Source code listing")
|
||||
.source("MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC)", "java")
|
||||
.tableWithHeaderRow(tableCsvRows)
|
||||
.tableWithHeaderRow(tableRowsInPSV)
|
||||
.sectionTitleLevel1("Section Level 1b")
|
||||
.sectionTitleLevel2("Section Level 2b")
|
||||
.boldTextLine("Bold text line b")
|
||||
@@ -53,8 +53,8 @@ public class MarkupDocBuilderTest {
|
||||
.sectionTitleLevel3("Section Level 3a")
|
||||
.paragraph("Paragraph with long text bla bla bla bla bla")
|
||||
.listing("Source code listing")
|
||||
.source("MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.ASCIIDOC)", "java")
|
||||
.tableWithHeaderRow(tableCsvRows)
|
||||
.source("MarkupDocBuilder builder = MarkupDocBuilders.documentBuilder(MarkupLanguage.MARKDOWN)", "java")
|
||||
.tableWithHeaderRow(tableRowsInPSV)
|
||||
.sectionTitleLevel1("Section Level 1b")
|
||||
.sectionTitleLevel2("Section Level 2b")
|
||||
.boldTextLine("Bold text line b")
|
||||
|
||||
Reference in New Issue
Block a user