Skip to content

Commit

Permalink
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
madmas committed Jan 22, 2015
1 parent 44474f3 commit 5d80147
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 0 deletions.
21 changes: 21 additions & 0 deletions asciidoctorj-diagram/build.gradle
@@ -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
}
}
3 changes: 3 additions & 0 deletions asciidoctorj-diagram/gradle.properties
@@ -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
@@ -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();
}
}
@@ -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();
}
}
@@ -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();
}
};
}
}
22 changes: 22 additions & 0 deletions asciidoctorj-diagram/src/test/resources/sample.adoc
@@ -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 |
+-----------------------------------+
....

1 change: 1 addition & 0 deletions build.gradle
Expand Up @@ -41,6 +41,7 @@ ext {
asciidoctorGemVersion = project.hasProperty('asciidoctorGemVersion') ? project.asciidoctorGemVersion : '1.5.2' asciidoctorGemVersion = project.hasProperty('asciidoctorGemVersion') ? project.asciidoctorGemVersion : '1.5.2'
asciidoctorEpub3GemVersion = project(':asciidoctorj-epub3').version.replace('-', '.') asciidoctorEpub3GemVersion = project(':asciidoctorj-epub3').version.replace('-', '.')
asciidoctorPdfGemVersion = project(':asciidoctorj-pdf').version.replace('-', '.') asciidoctorPdfGemVersion = project(':asciidoctorj-pdf').version.replace('-', '.')
asciidoctorDiagramGemVersion = project(':asciidoctorj-diagram').version.replace('-', '.')
coderayGemVersion = '1.1.0' coderayGemVersion = '1.1.0'
erubisGemVersion = '2.7.0' erubisGemVersion = '2.7.0'
hamlGemVersion = '4.0.5' hamlGemVersion = '4.0.5'
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Expand Up @@ -2,6 +2,7 @@ rootProject.name = 'asciidoctorj'


include \ include \
'asciidoctorj', 'asciidoctorj',
'asciidoctorj-diagram',
'asciidoctorj-epub3', 'asciidoctorj-epub3',
'asciidoctorj-pdf', 'asciidoctorj-pdf',
'asciidoctorj-distribution' 'asciidoctorj-distribution'
Expand Down

0 comments on commit 5d80147

Please sign in to comment.