Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
add everything to use asciidoctor-diagram as asciidoctorj-diagram
done at Hackergarten Basel January 2015 by @_max1m and @madmas
- Loading branch information
Showing
8 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,21 @@ | |||
dependencies { | |||
compile project(':asciidoctorj') | |||
gems("rubygems:asciidoctor-diagram:$asciidoctorDiagramGemVersion") { | |||
// Exclude gems provided by AsciidoctorJ core | |||
exclude module: 'asciidoctor' | |||
exclude module: 'thread_safe' | |||
} | |||
} | |||
|
|||
def gemFiles = fileTree(jruby.gemInstallDir) { | |||
include 'specifications/*.gemspec' | |||
include 'gems/*/lib/**' | |||
include "gems/asciidoctor-diagram-${asciidoctorDiagramGemVersion}/data/**" | |||
} | |||
|
|||
jrubyPrepareGems << { | |||
copy { // bundles the gems inside this artifact | |||
from gemFiles | |||
into sourceSets.main.output.resourcesDir | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
properName=AsciidoctorJ Diagram | |||
description=AsciidoctorJ Diagram bundles the Asciidoctor Diagram RubyGem (asciidoctor-diagram) so it can be loaded into the JVM using JRuby. | |||
version=1.3.0.preview.1 |
32 changes: 32 additions & 0 deletions
32
asciidoctorj-diagram/src/test/java/org/asciidoctor/WhenDocumentContainsDitaaDiagram.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,32 @@ | |||
package org.asciidoctor; | |||
|
|||
import java.io.File; | |||
|
|||
import org.asciidoctor.util.ClasspathResources; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
|
|||
import static org.asciidoctor.OptionsBuilder.options; | |||
import static org.hamcrest.CoreMatchers.is; | |||
import static org.junit.Assert.assertThat; | |||
|
|||
public class WhenDocumentContainsDitaaDiagram { | |||
|
|||
private Asciidoctor asciidoctor = Asciidoctor.Factory.create(); | |||
|
|||
@Rule | |||
public ClasspathResources classpath = new ClasspathResources(); | |||
|
|||
@Test | |||
public void png_should_be_rendered_for_diagram() { | |||
File inputFile = classpath.getResource("sample.adoc"); | |||
File outputFile1 = new File(inputFile.getParentFile(), "asciidoctor-diagram-process.png"); | |||
File outputFile2 = new File(inputFile.getParentFile(), "asciidoctor-diagram-process.png.cache"); | |||
asciidoctor.requireLibrary("asciidoctor-diagram"); | |||
asciidoctor.convertFile(inputFile, options().backend("html5").get()); | |||
assertThat(outputFile1.exists(), is(true)); | |||
assertThat(outputFile2.exists(), is(true)); | |||
outputFile1.delete(); | |||
outputFile2.delete(); | |||
} | |||
} |
50 changes: 50 additions & 0 deletions
50
asciidoctorj-diagram/src/test/java/org/asciidoctor/util/ClasspathHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,50 @@ | |||
package org.asciidoctor.util; | |||
|
|||
import java.io.File; | |||
import java.io.FileNotFoundException; | |||
import java.net.URISyntaxException; | |||
import java.net.URL; | |||
|
|||
/** | |||
* Hels getting files from the classpath. | |||
*/ | |||
public class ClasspathHelper { | |||
|
|||
private ClassLoader classloader; | |||
|
|||
/** | |||
* Gets a resourse in a similar way as {@link File#File(String)} | |||
*/ | |||
public File getResource(String pathname) { | |||
try { | |||
URL resource = classloader.getResource(pathname); | |||
if (resource != null) { | |||
return new File(classloader.getResource(pathname).toURI()); | |||
} | |||
else { | |||
throw new RuntimeException(new FileNotFoundException(pathname)); | |||
} | |||
} catch (URISyntaxException e) { | |||
throw new RuntimeException(e.getMessage(), e); | |||
} | |||
} | |||
|
|||
/** | |||
* Gets a resourse in a similar way as {@link File#File(String, String)} | |||
*/ | |||
public File getResource(String parent, String child) { | |||
return new File(getResource(parent), child); | |||
} | |||
|
|||
public ClassLoader getClassloader() { | |||
return classloader; | |||
} | |||
|
|||
public void setClassloader(ClassLoader classloader) { | |||
this.classloader = classloader; | |||
} | |||
|
|||
public void setClassloader(Class<?> clazz) { | |||
this.classloader = clazz.getClassLoader(); | |||
} | |||
} |
28 changes: 28 additions & 0 deletions
28
asciidoctorj-diagram/src/test/java/org/asciidoctor/util/ClasspathResources.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,28 @@ | |||
package org.asciidoctor.util; | |||
|
|||
import org.junit.rules.TestRule; | |||
import org.junit.runner.Description; | |||
import org.junit.runners.model.Statement; | |||
|
|||
/** | |||
* JUnit TestRule to handle classpath files. | |||
* | |||
* Delegates to {@link ClasspathHelper} | |||
*/ | |||
public class ClasspathResources extends ClasspathHelper implements TestRule { | |||
|
|||
protected void before(Class<?> clazz) throws Throwable { | |||
super.setClassloader(clazz); | |||
} | |||
|
|||
@Override | |||
public Statement apply(final Statement base, final Description description) { | |||
return new Statement() { | |||
@Override | |||
public void evaluate() throws Throwable { | |||
before(description.getTestClass()); | |||
base.evaluate(); | |||
} | |||
}; | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,22 @@ | |||
= Document Title | |||
|
|||
[ditaa,asciidoctor-diagram-process] | |||
.... | |||
+-------------+ | |||
| Asciidoctor |-------+ | |||
| diagram | | | |||
+-------------+ | PNG out | |||
^ | | |||
| ditaa in | | |||
| v | |||
+--------+ +--------+----+ /---------------\ | |||
| |---+ Asciidoctor +--->| | | |||
| Text | +-------------+ | Beautiful | | |||
|Document| | !magic! | | Output | | |||
| {d}| | | | | | |||
+---+----+ +-------------+ \---------------/ | |||
: ^ | |||
| Lots of work | | |||
+-----------------------------------+ | |||
.... | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters