Add asciidoctorj-revealjs to distribution
MODIFY
CHANGELOG.adoc
CHANGELOG.adoc
@@ -13,6 +13,10 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[
== Unreleased
+Improvement::
+
+ * Add asciidoctor-revealjs to distribution (#910)
+
Build::
* Upgrade jruby-gradle-plugin to 2.0.0-alpha.7 and load Gems directly from rubygems.org instead of using torquebox Maven proxy.

MODIFY
asciidoctorj-core/src/main/java/org/asciidoctor/jruby/internal/RubyGemsPreloader.java
asciidoctorj-core/src/main/java/org/asciidoctor/jruby/internal/RubyGemsPreloader.java
@@ -13,6 +13,7 @@ public class RubyGemsPreloader {
private static final String ERUBIS = "erubis";
private static final String EPUB3 = "epub3";
private static final String PDF = "pdf";
+ private static final String REVEALJS = "asciidoctor-revealjs";
private static final Map<String, String> optionToRequiredGem = new HashMap<String, String>() {
{
@@ -23,6 +24,7 @@ public class RubyGemsPreloader {
put(Attributes.CACHE_URI, "require 'open-uri/cached'");
put(EPUB3, "require 'asciidoctor-epub3'");
put(PDF, "require 'asciidoctor-pdf'");
+ put(REVEALJS, "require 'asciidoctor-revealjs'");
}
};
@@ -66,6 +68,10 @@ public class RubyGemsPreloader {
if(isOptionSet(options, Options.BACKEND) && "pdf".equalsIgnoreCase((String) options.get(Options.BACKEND))) {
preloadLibrary(PDF);
}
+
+ if(isOptionSet(options, Options.BACKEND) && "revealjs".equalsIgnoreCase((String) options.get(Options.BACKEND))) {
+ preloadLibrary(REVEALJS);
+ }
}
private void preloadLibrary(String option) {

MODIFY
asciidoctorj-distribution/build.gradle
asciidoctorj-distribution/build.gradle
@@ -22,9 +22,13 @@ dependencies {
compile("org.asciidoctor:asciidoctorj-pdf:$asciidoctorjPdfVersion") {
transitive = false
}
+ compile("org.asciidoctor:asciidoctorj-revealjs:$asciidoctorjRevealJsVersion") {
+ transitive = false
+ }
compile "org.jruby:jruby-complete:$jrubyVersion"
testCompile project(':asciidoctorj-arquillian-extension')
testCompile "org.apache.pdfbox:pdfbox:$pdfboxVersion"
+ testCompile "org.jsoup:jsoup:$jsoupVersion"
}
jar.enabled = false

ADD
asciidoctorj-distribution/src/test/java/org/asciidoctor/WhenBackendIsRevealJs.java
+package org.asciidoctor;
+
+import org.asciidoctor.jruby.cli.AsciidoctorInvoker;
+import org.jsoup.Jsoup;
+import org.jsoup.nodes.Document;
+import org.jsoup.nodes.Element;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import static java.util.stream.Collectors.toList;
+import static org.asciidoctor.OptionsBuilder.options;
+import static org.hamcrest.Matchers.hasItems;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.startsWith;
+import static org.junit.Assert.assertThat;
+
+public class WhenBackendIsRevealJs {
+
+ private Asciidoctor asciidoctor;
+
+ @Before
+ public void initAsciidoctor() {
+ this.asciidoctor = Asciidoctor.Factory.create();
+ }
+
+ @Test
+ public void should_create_simple_slides() throws IOException {
+ String filename = "sample";
+ File inputFile = new File("build/resources/test/" + filename + ".adoc");
+ File outputFile1 = new File(inputFile.getParentFile(), filename + ".html");
+ removeFileIfItExists(outputFile1);
+
+ AsciidoctorInvoker.main(new String[]{
+ "-b", "revealjs",
+ "-r", "asciidoctor-diagram",
+ "-a", "revealjsdir=https://cdn.jsdelivr.net/npm/reveal.js@3.9.2",
+ inputFile.getAbsolutePath()
+ });
+
+ Document doc = Jsoup.parse(outputFile1, "UTF-8");
+
+ assertThat(outputFile1.exists(), is(true));
+
+ List<String> stylesheets = doc.head().getElementsByTag("link").stream()
+ .filter(element -> "stylesheet".equals(element.attr("rel")))
+ .map(element -> element.attr("href"))
+ .collect(toList());
+ assertThat(stylesheets,
+ hasItems(
+ "https://cdn.jsdelivr.net/npm/reveal.js@3.9.2/css/reveal.css",
+ "https://cdn.jsdelivr.net/npm/reveal.js@3.9.2/css/theme/black.css"));
+
+ Element diagramSlide = doc.selectFirst("#diagram");
+ assertThat(diagramSlide, notNullValue());
+
+ Element diagram = diagramSlide.selectFirst("div.imageblock img");
+ assertThat(diagram, notNullValue());
+
+ assertThat(diagram.attr("src"), startsWith("data:image/svg+xml;base64,"));
+ }
+
+
+ private void removeFileIfItExists(File file) throws IOException {
+ if (file.exists()) {
+ if (!file.delete()) {
+ throw new IOException("can't delete file");
+ }
+ }
+ }
+}

ADD
asciidoctorj-distribution/src/test/resources/sample.adoc
+= Reveal.js Sample document
+:source-highlighter: highlightjs
+:data-uri:
+
+== Slide 1
+
+This is a slide
+
+== Slide 2 with some code
+
+[source,java]
+----
+System.out.println("Hello World");
+----
+
+[[diagram]]
+== Slide 3 with a diagram
+
+[plantuml,test,svg]
+----
+A --> B
+----
\ No newline at end of file

MODIFY
build.gradle
build.gradle
@@ -43,12 +43,13 @@ ext {
asciidoctorjPdfVersion = '1.5.0-rc.2'
asciidoctorjEpub3Version = '1.5.0-alpha.15'
asciidoctorjDiagramVersion = '2.0.1'
+ asciidoctorjRevealJsVersion = '4.0.1'
commonsioVersion = '2.4'
guavaVersion = '18.0'
hamcrestVersion = '1.3'
jcommanderVersion = '1.72'
jrubyVersion = '9.2.9.0'
- jsoupVersion = '1.10.2'
+ jsoupVersion = '1.12.1'
junitVersion = '4.12'
nettyVersion = '4.0.33.Final'
saxonVersion = '9.9.0-2'

Add asciidoctorj-revealjs to distribution