@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_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")); }
@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_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_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_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_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>")); }