Integrate asciidoctor-gradle plugin with asciidoctor diagram?
Posted by
owahlen on
May 26, 2014; 12:25pm
URL: https://discuss.asciidoctor.org/Integrate-asciidoctor-gradle-plugin-with-asciidoctor-diagram-tp1769.html
I use the asciidoctor-gradle plugin to create a deckjs based presentation.
However I also need ditaa for some diagrams which I cannot get to work.
My main problem is that asciidoctor-diagram needs additional ruby gems and I do not know how to integrate them into the gradle build.
My current approach is to download the asciidoctor-diagram gem using gradle from torquebox and then add it to the rubyRuntime class instance inside the gradle build process.
I am pretty familiar with Java and gradle. However my Ruby knowledge is not sufficient to get this to work.
Can someone please have a look at the following build.gradle and point me into the right direction?
import java.lang.reflect.Field
buildscript {
repositories {
maven {
name 'Bintray Asciidoctor repo'
url 'http://dl.bintray.com/content/aalmiray/asciidoctor'
}
maven {
name 'Bintray JCenter'
url 'http://jcenter.bintray.com'
}
mavenLocal()
}
dependencies {
classpath 'org.asciidoctor:asciidoctor-gradle-plugin:0.7.0'
}
}
apply plugin: 'asciidoctor'
repositories {
maven {
name 'rubygems-release'
url 'http://rubygems-proxy.torquebox.org/releases'
}
maven {
name 'rubygems-prerelease'
url 'http://rubygems-proxy.torquebox.org/prereleases'
}
}
configurations {
// create a Configuration called "gems" and add it to the project’s ConfigurationsContainer:
gems
}
dependencies {
// Add dependencies to the gems-Configuration
// I am not sure what other gems are needed...
// gems 'rubygems:thread_safe:0.2.0@gem'
// gems 'rubygems:haml:4.0.4@gem'
// gems 'rubygems:open-uri-cached:0.0.5@gem'
// gems 'rubygems:asciidoctor:1.5.0.preview3-SNAPSHOT@gem'
// gems 'rubygems:coderay:1.1.0@gem'
// gems 'rubygems:tilt:2.0.0@gem'
// gems 'rubygems:erubis:2.7.0@gem'
// gems 'rubygems:slim:2.0.2@gem'
// gems 'rubygems:rjb:1.4.9@gem'
gems 'rubygems:asciidoctor-diagram:1.1.5@gem'
}
import org.asciidoctor.Asciidoctor
import org.asciidoctor.internal.JRubyAsciidoctor
import org.jruby.Ruby
import static org.asciidoctor.internal.JRubyAsciidoctor.*;
// task that copies the needed gems from torquebox into the "build/gems" directory (this works!)
File gemPath = new File(buildDir, 'gems')
task provideGemFiles(type: Copy) {
from configurations.gems
into gemPath
}
asciidoctor {
// this is really dirty: I have to access the rubyRuntime via reflection since it is protected...
JRubyAsciidoctor jRubyAsciidoctor = (JRubyAsciidoctor) Asciidoctor.Factory.create()
Field field = JRubyAsciidoctor.class.getDeclaredField('rubyRuntime')
field.setAccessible(true)
Ruby ruby = (Ruby) field.get(jRubyAsciidoctor)
ruby.instanceConfig.setLoadPaths([gemPath.canonicalPath])
ruby.evalScriptlet("require 'rubygems‘")
// the following require statement does not work since Ruby does not find the asciidoctor-diagram gem
ruby.evalScriptlet("require 'asciidoctor-diagram'")
asciidoctor = jRubyAsciidoctor
sourceDir = file('asciidoc')
outputDir = buildDir
backend = 'deckjs'
options = [
template_dir: 'asciidoctor-backends/haml',
eruby : 'erubis',
attributes : [
backend : 'deckjs',
deckjs_theme: 'Web-2.0',
deckjs_transition: 'fade',
customjs: '',
customcss: '',
blank: '',
goto: '',
menu: '',
navigation: '',
status: '',
toc: '',
'source-highlighter': 'highlightjs'
]
]
}
asciidoctor.dependsOn(provideGemFiles)
task build(dependsOn: 'asciidoctor')