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