// Path: asciidoctorj-core/src/main/java/org/asciidoctor/jruby/AsciidoctorJRuby.java
// public interface AsciidoctorJRuby extends Asciidoctor {
// 
// 
//   /**
//    * Factory for creating a new instance of Asciidoctor interface.
//    *
//    * @author lordofthejars
//    */
//   public static final class Factory {
// 
//     private Factory() {
//     }
// 
//     /**
//      * Creates a new instance of Asciidoctor.
//      *
//      * @return Asciidoctor instance which uses JRuby to wraps Asciidoctor
//      * Ruby calls.
//      */
//     public static AsciidoctorJRuby create() {
//       return JRubyAsciidoctor.create();
//     }
// 
//     /**
//      * Creates a new instance of Asciidoctor and sets GEM_PATH environment
//      * variable to provided gemPath. This method is mostly used in OSGi
//      * environments.
//      *
//      * @param gemPath where gems are located.
//      * @return Asciidoctor instance which uses JRuby to wraps Asciidoctor
//      * Ruby calls.
//      */
//     public static AsciidoctorJRuby create(String gemPath) {
//       return JRubyAsciidoctor.create(gemPath);
//     }
// 
//     /**
//      * Creates a new instance of Asciidoctor and sets loadPath to provided paths. This method is mostly used in OSGi
//      * environments.
//      *
//      * @param loadPaths where Ruby libraries are located.
//      * @return Asciidoctor instance which uses JRuby to wraps Asciidoctor
//      * Ruby calls.
//      */
//     public static AsciidoctorJRuby create(List<String> loadPaths) {
//       return JRubyAsciidoctor.create(loadPaths);
//     }
// 
//     /**
//      * Creates a new instance of Asciidoctor and sets a specific classloader for the  JRuby runtime to use.
//      * This method is for use in environments like OSGi.
//      * To initialize Asciidoctor in OSGi create the Asciidoctor instance like this:
//      *
//      * <pre>
//      * org.jruby.javasupport.JavaEmbedUtils.initialize(Arrays.asList("uri:classloader:/gems/asciidoctor-1.5.8/lib"));
//      * Asciidoctor asciidoctor = Asciidoctor.Factory.create(this.getClass().getClassLoader());
//      * </pre>
//      *
//      * @param classloader
//      * @return Asciidoctor instance which uses JRuby to wraps Asciidoctor
//      *         Ruby calls.
//      */
//     public static AsciidoctorJRuby create(ClassLoader classloader) {
//       return JRubyAsciidoctor.create(classloader);
//     }
// 
//     /**
//      * Creates a new instance of Asciidoctor and sets a specific classloader and gempath for the JRuby runtime to use.
//      * This method is for use in environments like OSGi.
//      * To initialize Asciidoctor in OSGi create the Asciidoctor instance like this:
//      *
//      * <pre>
//      * org.jruby.javasupport.JavaEmbedUtils.initialize(Arrays.asList("uri:classloader:/gems/asciidoctor-1.5.8/lib"));
//      * Asciidoctor asciidoctor = Asciidoctor.Factory.create(this.getClass().getClassLoader());
//      * </pre>
//      *
//      * @param classloader
//      * @param gemPath
//      * @return Asciidoctor instance which uses JRuby to wraps Asciidoctor
//      */
//     public static AsciidoctorJRuby create(ClassLoader classloader, String gemPath) {
//       return JRubyAsciidoctor.create(classloader, gemPath);
//     }
// 
//     /**
//      * Creates a new instance of Asciidoctor and sets loadPath to provided paths.
//      * The gem path of the Ruby instance is set to the gemPath parameter.
//      *
//      * @param loadPaths where Ruby libraries are located.
//      * @param gemPath   where gems are located.
//      * @return Asciidoctor instance which uses JRuby to wraps Asciidoctor
//      * Ruby calls.
//      */
//     public static AsciidoctorJRuby create(List<String> loadPaths, String gemPath) {
//       return JRubyAsciidoctor.create(loadPaths, gemPath);
//     }
// 
//   }
// 
// 
// }


import org.asciidoctor.SafeMode;
import org.asciidoctor.arquillian.api.Unshared;
import org.asciidoctor.jruby.AsciidoctorJRuby;
import org.asciidoctor.util.ClasspathResources;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.TextNode;
import org.jsoup.select.Elements;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.Iterator;
import static java.util.Collections.singletonList;
import static org.asciidoctor.OptionsBuilder.options;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
        final Document document = Jsoup.parse(content);
        final TextNode commandElement = document.getElementsByClass("command").get(0).textNodes().get(0);
        assertThat(commandElement.getWholeText(), is("echo \"Hello, World!\""));
        final TextNode commandElement2 = document.getElementsByClass("command").get(1).textNodes().get(0);
        assertThat(commandElement2.getWholeText(), is("gem install asciidoctor"));
    }

    @Test
    public void ruby_includeprocessor_should_be_registered() {
        asciidoctor.rubyExtensionRegistry()
            .loadClass(getClass().getResourceAsStream("/ruby-extensions/response-include-processor.rb"))
            .includeProcessor("ResponseIncludeProcessor");

        String content = asciidoctor.convert(
            "The response to everything is\n" +
                "\n" +
                "include::response[]" +
                "",
            options().toFile(false).safe(SafeMode.SAFE).get());

        final Document document = Jsoup.parse(content);
        assertThat(
            document.getElementsByClass("paragraph").get(1).getElementsByTag("p").get(0).toString(),
            is("<p>42</p>"));
    }

    @Test
    public void ruby_postprocessor_should_be_registered() {

        final String rubyExtPath = classpath.getResource("ruby-extensions").getAbsolutePath();
// Path: asciidoctorj-core/src/main/java/org/asciidoctor/jruby/AsciidoctorJRuby.java
// public interface AsciidoctorJRuby extends Asciidoctor {
// 
// 
//   /**
//    * Factory for creating a new instance of Asciidoctor interface.
//    *
//    * @author lordofthejars
//    */
//   public static final class Factory {
// 
//     private Factory() {
//     }
// 
//     /**
//      * Creates a new instance of Asciidoctor.
//      *
//      * @return Asciidoctor instance which uses JRuby to wraps Asciidoctor
//      * Ruby calls.
//      */
//     public static AsciidoctorJRuby create() {
//       return JRubyAsciidoctor.create();
//     }
// 
//     /**
//      * Creates a new instance of Asciidoctor and sets GEM_PATH environment
//      * variable to provided gemPath. This method is mostly used in OSGi
//      * environments.
//      *
//      * @param gemPath where gems are located.
//      * @return Asciidoctor instance which uses JRuby to wraps Asciidoctor
//      * Ruby calls.
//      */
//     public static AsciidoctorJRuby create(String gemPath) {
//       return JRubyAsciidoctor.create(gemPath);
//     }
// 
//     /**
//      * Creates a new instance of Asciidoctor and sets loadPath to provided paths. This method is mostly used in OSGi
//      * environments.
//      *
//      * @param loadPaths where Ruby libraries are located.
//      * @return Asciidoctor instance which uses JRuby to wraps Asciidoctor
//      * Ruby calls.
//      */
//     public static AsciidoctorJRuby create(List<String> loadPaths) {
//       return JRubyAsciidoctor.create(loadPaths);
//     }
// 
//     /**
//      * Creates a new instance of Asciidoctor and sets a specific classloader for the  JRuby runtime to use.
//      * This method is for use in environments like OSGi.
//      * To initialize Asciidoctor in OSGi create the Asciidoctor instance like this:
//      *
//      * <pre>
//      * org.jruby.javasupport.JavaEmbedUtils.initialize(Arrays.asList("uri:classloader:/gems/asciidoctor-1.5.8/lib"));
//      * Asciidoctor asciidoctor = Asciidoctor.Factory.create(this.getClass().getClassLoader());
//      * </pre>
//      *
//      * @param classloader
//      * @return Asciidoctor instance which uses JRuby to wraps Asciidoctor
//      *         Ruby calls.
//      */
//     public static AsciidoctorJRuby create(ClassLoader classloader) {
//       return JRubyAsciidoctor.create(classloader);
//     }
// 
//     /**
//      * Creates a new instance of Asciidoctor and sets a specific classloader and gempath for the JRuby runtime to use.
//      * This method is for use in environments like OSGi.
//      * To initialize Asciidoctor in OSGi create the Asciidoctor instance like this:
//      *
//      * <pre>
//      * org.jruby.javasupport.JavaEmbedUtils.initialize(Arrays.asList("uri:classloader:/gems/asciidoctor-1.5.8/lib"));
//      * Asciidoctor asciidoctor = Asciidoctor.Factory.create(this.getClass().getClassLoader());
//      * </pre>
//      *
//      * @param classloader
//      * @param gemPath
//      * @return Asciidoctor instance which uses JRuby to wraps Asciidoctor
//      */
//     public static AsciidoctorJRuby create(ClassLoader classloader, String gemPath) {
//       return JRubyAsciidoctor.create(classloader, gemPath);
//     }
// 
//     /**
//      * Creates a new instance of Asciidoctor and sets loadPath to provided paths.
//      * The gem path of the Ruby instance is set to the gemPath parameter.
//      *
//      * @param loadPaths where Ruby libraries are located.
//      * @param gemPath   where gems are located.
//      * @return Asciidoctor instance which uses JRuby to wraps Asciidoctor
//      * Ruby calls.
//      */
//     public static AsciidoctorJRuby create(List<String> loadPaths, String gemPath) {
//       return JRubyAsciidoctor.create(loadPaths, gemPath);
//     }
// 
//   }
// 
// 
// }


// Path: asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenRubyExtensionIsRegistered.java
import org.asciidoctor.SafeMode;
import org.asciidoctor.arquillian.api.Unshared;
import org.asciidoctor.jruby.AsciidoctorJRuby;
import org.asciidoctor.util.ClasspathResources;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.TextNode;
import org.jsoup.select.Elements;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.Iterator;
import static java.util.Collections.singletonList;
import static org.asciidoctor.OptionsBuilder.options;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

        final Document document = Jsoup.parse(content);
        final TextNode commandElement = document.getElementsByClass("command").get(0).textNodes().get(0);
        assertThat(commandElement.getWholeText(), is("echo \"Hello, World!\""));
        final TextNode commandElement2 = document.getElementsByClass("command").get(1).textNodes().get(0);
        assertThat(commandElement2.getWholeText(), is("gem install asciidoctor"));
    }

    @Test
    public void ruby_includeprocessor_should_be_registered() {
        asciidoctor.rubyExtensionRegistry()
            .loadClass(getClass().getResourceAsStream("/ruby-extensions/response-include-processor.rb"))
            .includeProcessor("ResponseIncludeProcessor");

        String content = asciidoctor.convert(
            "The response to everything is\n" +
                "\n" +
                "include::response[]" +
                "",
            options().toFile(false).safe(SafeMode.SAFE).get());

        final Document document = Jsoup.parse(content);
        assertThat(
            document.getElementsByClass("paragraph").get(1).getElementsByTag("p").get(0).toString(),
            is("<p>42</p>"));
    }

    @Test
    public void ruby_postprocessor_should_be_registered() {

        final String rubyExtPath = classpath.getResource("ruby-extensions").getAbsolutePath();
        final AsciidoctorJRuby asciidoctor = AsciidoctorJRuby.Factory.create(singletonList(rubyExtPath));