@Override public void register(Asciidoctor asciidoctor) { asciidoctor.javaExtensionRegistry() .preprocessor(new DefaultAttributesPreprocessor()); asciidoctor.rubyExtensionRegistry() .loadClass(RestDocsExtensionRegistry.class .getResourceAsStream("/extensions/operation_block_macro.rb")) .blockMacro("operation", "OperationBlockMacro"); }
@Test public void ruby_inline_macro_processor_should_be_registered_with_macro_name() { RubyExtensionRegistry rubyExtensionRegistry = this.asciidoctor.rubyExtensionRegistry(); rubyExtensionRegistry.loadClass(getClass().getResourceAsStream("/ruby-extensions/man-inline-macro.rb")).inlineMacro("myman", "ManInlineMacro"); String content = asciidoctor.convert( "= Man Inline Macro Extension\n" + "\n" + "See myman:gittutorial[7] to get started.", options().toFile(false).get()); Document doc = Jsoup.parse(content, "UTF-8"); Elements elements = doc.getElementsByTag("a"); assertThat(elements.size(), is(1)); assertThat(elements.get(0).attr("href"), is("gittutorial.html")); }
@Test public void ruby_block_processor_should_be_registered_with_implicit_block_name() { RubyExtensionRegistry rubyExtensionRegistry = this.asciidoctor.rubyExtensionRegistry(); rubyExtensionRegistry.loadClass(getClass().getResourceAsStream("/ruby-extensions/YellRubyBlock.rb")).block("YellRubyBlock"); String content = asciidoctor.convert( "= Block Yell Example\n" + "\n" + "content\n" + "\n" + "[yell]\n" + "The time is now. Get a move on.", options().toFile(false).get()); Document doc = Jsoup.parse(content, "UTF-8"); Elements elements = doc.getElementsByClass("paragraph"); assertThat(elements.size(), is(2)); assertThat(elements.get(1).text(), is("THE TIME IS NOW! GET A MOVE ON!")); }
@Test public void ruby_postprocessor_should_be_registered() { final String rubyExtPath = classpath.getResource("ruby-extensions").getAbsolutePath(); final Asciidoctor asciidoctor = Asciidoctor.Factory.create(singletonList(rubyExtPath)); asciidoctor.rubyExtensionRegistry() .requireLibrary("xml-entity-postprocessor.rb") .postprocessor("XmlEntityPostprocessor"); String content = asciidoctor.convert( "Read §2 and it'll all be clear.", options().toFile(false).get()); assertThat(content, containsString("Read §2 and it'll all be clear.")); }
@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_treeprocessor_should_be_registered() { final String rubyExtPath = classpath.getResource("ruby-extensions").getAbsolutePath(); final Asciidoctor asciidoctor = Asciidoctor.Factory.create(singletonList(rubyExtPath)); asciidoctor.rubyExtensionRegistry() .requireLibrary("shell-session-tree-processor.rb") .treeprocessor("ShellSessionTreeProcessor"); String content = asciidoctor.convert( " $ echo \"Hello, World!\"\n" + " > Hello, World!\n" + "\n" + " $ gem install asciidoctor", options().toFile(false).get()); 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")); }
final Asciidoctor asciidoctor = Asciidoctor.Factory.create(singletonList(rubyExtPath)); asciidoctor.rubyExtensionRegistry() .requireLibrary("front-matter-preprocessor.rb") .preprocessor("FrontMatterPreprocessor");
final Asciidoctor asciidoctor = Asciidoctor.Factory.create(singletonList(rubyExtPath)); asciidoctor.rubyExtensionRegistry() .requireLibrary("view-result-docinfoprocessor.rb") .docinfoProcessor("ViewResultDocinfoProcessor");
private Options buildOptions(DocletOptions docletOptions, DocErrorReporter errorReporter) { OptionsBuilder opts = defaultOptions(); if (docletOptions.baseDir().isPresent()) { opts.baseDir(docletOptions.baseDir().get()); } if (templates.isPresent()) { opts.templateDir(templates.get().templateDir()); } opts.attributes(buildAttributes(docletOptions, errorReporter)); if (docletOptions.requires().size() > 0) { for (String require : docletOptions.requires()) { asciidoctor.rubyExtensionRegistry().requireLibrary(require); } } return opts.get(); }
@Test public void ruby_inline_macro_processor_should_be_registered_with_implicit_macro_name() { RubyExtensionRegistry rubyExtensionRegistry = this.asciidoctor.rubyExtensionRegistry(); rubyExtensionRegistry.loadClass(getClass().getResourceAsStream("/ruby-extensions/man-inline-macro.rb")) .inlineMacro("ManInlineMacro"); String content = asciidoctor.convert( "= Man Inline Macro Extension\n" + "\n" + "See man:dockertutorial[7] to get started.", options().toFile(false).get()); Document doc = Jsoup.parse(content, "UTF-8"); Elements elements = doc.getElementsByTag("a"); assertThat(elements.size(), is(1)); assertThat(elements.get(0).attr("href"), is("dockertutorial.html")); }
@Test public void ruby_block_processor_should_be_registered_with_explicit_block_name() { RubyExtensionRegistry rubyExtensionRegistry = this.asciidoctor.rubyExtensionRegistry(); rubyExtensionRegistry.loadClass(getClass().getResourceAsStream("/ruby-extensions/YellRubyBlock.rb")).block("rubyyell", "YellRubyBlock"); String content = asciidoctor.convert( "= Block Yell Example\n" + "\n" + "content\n" + "\n" + "[rubyyell]\n" + "The time is now. Get a move on.", options().toFile(false).get()); Document doc = Jsoup.parse(content, "UTF-8"); Elements elements = doc.getElementsByClass("paragraph"); assertThat(elements.size(), is(2)); assertThat(elements.get(1).text(), is("THE TIME IS NOW! GET A MOVE ON!")); }
@Test public void ruby_block_macro_processor_should_be_registered_with_block_name() { RubyExtensionRegistry rubyExtensionRegistry = this.asciidoctor.rubyExtensionRegistry(); rubyExtensionRegistry.loadClass(getClass().getResourceAsStream("/ruby-extensions/gist-block-macro.rb")).blockMacro("mygist", "GistBlockMacro"); String content = asciidoctor.convert( ".My Gist\n" + "mygist::123456[]", options().toFile(false).get()); Document doc = Jsoup.parse(content, "UTF-8"); Elements elements = doc.getElementsByTag("script"); assertThat(elements.size(), is(1)); assertThat(elements.get(0).attr("src"), is("https://gist.github.com/123456.js")); }
@Test public void ruby_block_macro_processor_should_be_registered_with_implicit_block_name() { RubyExtensionRegistry rubyExtensionRegistry = this.asciidoctor.rubyExtensionRegistry(); rubyExtensionRegistry.loadClass(getClass().getResourceAsStream("/ruby-extensions/gist-block-macro.rb")).blockMacro("GistBlockMacro"); String content = asciidoctor.convert( ".My Gist\n" + "gist::42[]", options().toFile(false).get()); Document doc = Jsoup.parse(content, "UTF-8"); Elements elements = doc.getElementsByTag("script"); assertThat(elements.size(), is(1)); assertThat(elements.get(0).attr("src"), is("https://gist.github.com/42.js")); }