From ccf7bfaff189c025c7a4d261ff468e56d831bf34 Mon Sep 17 00:00:00 2001 From: Robert Panzer Date: Wed, 19 Jul 2017 18:46:24 +0200 Subject: [PATCH 1/4] Fixes #359. Explicit unregistration of extensions. --- .../java/org/asciidoctor/Asciidoctor.java | 8 +- .../extension/JavaExtensionRegistry.java | 199 ++++++++++++++++++ .../extension/RubyExtensionRegistry.java | 49 ++++- .../internal/AsciidoctorModule.java | 43 +++- .../internal/JRubyAsciidoctor.java | 5 + .../asciidoctor/internal/asciidoctorclass.rb | 40 ++-- .../WhenJavaExtensionIsRegistered.java | 66 ++++++ .../WhenRubyExtensionIsRegistered.java | 33 +++ build.gradle | 2 +- 9 files changed, 415 insertions(+), 30 deletions(-) diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/Asciidoctor.java b/asciidoctorj-core/src/main/java/org/asciidoctor/Asciidoctor.java index 12f12c4f5..fdf63efe7 100644 --- a/asciidoctorj-core/src/main/java/org/asciidoctor/Asciidoctor.java +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/Asciidoctor.java @@ -638,7 +638,13 @@ String[] convertFiles(Collection asciidoctorFiles, * Unregister all registered extensions. */ void unregisterAllExtensions(); - + + /** + * Unregisters the extension represented by the given registration name. + * @param registrationName + */ + void unregisterExtension(String registrationName); + /** * This method frees all resources consumed by asciidoctorJ module. Keep in mind that if this method is called, instance becomes unusable and you should create another instance. */ diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/extension/JavaExtensionRegistry.java b/asciidoctorj-core/src/main/java/org/asciidoctor/extension/JavaExtensionRegistry.java index 2b969ae4a..e3f7340bc 100644 --- a/asciidoctorj-core/src/main/java/org/asciidoctor/extension/JavaExtensionRegistry.java +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/extension/JavaExtensionRegistry.java @@ -22,6 +22,13 @@ public void docinfoProcessor(Class docInfoProcessor) this.asciidoctorModule.docinfo_processor(RubyUtils.toRubyClass(rubyRuntime, docInfoProcessor)); } + public void docinfoProcessor(Class docInfoProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, docInfoProcessor); + this.asciidoctorModule.docinfo_processor(RubyUtils.toRubyClass(rubyRuntime, docInfoProcessor), registrationName); + } + public void docinfoProcessor(DocinfoProcessor docInfoProcessor) { // this may change in future to external class to deal with dynamic // imports @@ -29,6 +36,13 @@ public void docinfoProcessor(DocinfoProcessor docInfoProcessor) { this.asciidoctorModule.docinfo_processor(docInfoProcessor); } + public void docinfoProcessor(DocinfoProcessor docInfoProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, docInfoProcessor.getClass()); + this.asciidoctorModule.docinfo_processor(docInfoProcessor, registrationName); + } + public void docinfoProcessor(String docInfoProcessor) { // this may change in future to external class to deal with dynamic // imports @@ -36,6 +50,13 @@ public void docinfoProcessor(String docInfoProcessor) { this.asciidoctorModule.docinfo_processor(getClassName(docInfoProcessor)); } + public void docinfoProcessor(String docInfoProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, docInfoProcessor); + this.asciidoctorModule.docinfo_processor(getClassName(docInfoProcessor), registrationName); + } + public void preprocessor(Class preprocessor) { // this may change in future to external class to deal with dynamic // imports @@ -43,6 +64,13 @@ public void preprocessor(Class preprocessor) { this.asciidoctorModule.preprocessor(RubyUtils.toRubyClass(rubyRuntime, preprocessor)); } + public void preprocessor(Class preprocessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, preprocessor); + this.asciidoctorModule.preprocessor(RubyUtils.toRubyClass(rubyRuntime, preprocessor), registrationName); + } + public void preprocessor(Preprocessor preprocessor) { // this may change in future to external class to deal with dynamic // imports @@ -50,6 +78,13 @@ public void preprocessor(Preprocessor preprocessor) { this.asciidoctorModule.preprocessor(preprocessor); } + public void preprocessor(Preprocessor preprocessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, preprocessor.getClass()); + this.asciidoctorModule.preprocessor(preprocessor, registrationName); + } + public void preprocessor(String preprocessor) { // this may change in future to external class to deal with dynamic // imports @@ -57,6 +92,13 @@ public void preprocessor(String preprocessor) { this.asciidoctorModule.preprocessor(getClassName(preprocessor)); } + public void preprocessor(String preprocessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, preprocessor); + this.asciidoctorModule.preprocessor(getClassName(preprocessor), registrationName); + } + public void postprocessor(String postprocessor) { // this may change in future to external class to deal with dynamic // imports @@ -64,6 +106,13 @@ public void postprocessor(String postprocessor) { this.asciidoctorModule.postprocessor(getClassName(postprocessor)); } + public void postprocessor(String postprocessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, postprocessor); + this.asciidoctorModule.postprocessor(getClassName(postprocessor), registrationName); + } + public void postprocessor(Class postprocessor) { // this may change in future to external class to deal with dynamic // imports @@ -71,6 +120,13 @@ public void postprocessor(Class postprocessor) { this.asciidoctorModule.postprocessor(RubyUtils.toRubyClass(rubyRuntime, postprocessor)); } + public void postprocessor(Class postprocessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, postprocessor); + this.asciidoctorModule.postprocessor(RubyUtils.toRubyClass(rubyRuntime, postprocessor), registrationName); + } + public void postprocessor(Postprocessor postprocesor) { // this may change in future to external class to deal with dynamic // imports @@ -78,6 +134,13 @@ public void postprocessor(Postprocessor postprocesor) { this.asciidoctorModule.postprocessor(postprocesor); } + public void postprocessor(Postprocessor postprocesor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, postprocesor.getClass()); + this.asciidoctorModule.postprocessor(postprocesor, registrationName); + } + public void includeProcessor(String includeProcessor) { // this may change in future to external class to deal with dynamic // imports @@ -85,6 +148,13 @@ public void includeProcessor(String includeProcessor) { this.asciidoctorModule.include_processor(getClassName(includeProcessor)); } + public void includeProcessor(String includeProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, includeProcessor); + this.asciidoctorModule.include_processor(getClassName(includeProcessor), registrationName); + } + public void includeProcessor( Class includeProcessor) { // this may change in future to external class to deal with dynamic @@ -93,17 +163,36 @@ public void includeProcessor( this.asciidoctorModule.include_processor(RubyUtils.toRubyClass(rubyRuntime, includeProcessor)); } + public void includeProcessor( + Class includeProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, includeProcessor); + this.asciidoctorModule.include_processor(RubyUtils.toRubyClass(rubyRuntime, includeProcessor), registrationName); + } + public void includeProcessor(IncludeProcessor includeProcessor) { String importLine = getImportLine(includeProcessor.getClass()); javaImport(rubyRuntime, importLine); this.asciidoctorModule.include_processor(includeProcessor); } + public void includeProcessor(IncludeProcessor includeProcessor, String registrationName) { + String importLine = getImportLine(includeProcessor.getClass()); + javaImport(rubyRuntime, importLine); + this.asciidoctorModule.include_processor(includeProcessor, registrationName); + } + public void treeprocessor(Treeprocessor treeprocessor) { javaImport(rubyRuntime, treeprocessor.getClass()); this.asciidoctorModule.treeprocessor(treeprocessor); } + public void treeprocessor(Treeprocessor treeprocessor, String registrationName) { + javaImport(rubyRuntime, treeprocessor.getClass()); + this.asciidoctorModule.treeprocessor(treeprocessor, registrationName); + } + public void treeprocessor(Class treeProcessor) { // this may change in future to external class to deal with dynamic // imports @@ -111,6 +200,13 @@ public void treeprocessor(Class treeProcessor) { this.asciidoctorModule.treeprocessor(RubyUtils.toRubyClass(rubyRuntime, treeProcessor)); } + public void treeprocessor(Class treeProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, treeProcessor); + this.asciidoctorModule.treeprocessor(RubyUtils.toRubyClass(rubyRuntime, treeProcessor), registrationName); + } + public void treeprocessor(String treeProcessor) { // this may change in future to external class to deal with dynamic // imports @@ -118,6 +214,13 @@ public void treeprocessor(String treeProcessor) { this.asciidoctorModule.treeprocessor(getClassName(treeProcessor)); } + public void treeprocessor(String treeProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, treeProcessor); + this.asciidoctorModule.treeprocessor(getClassName(treeProcessor), registrationName); + } + public void block(String blockName, String blockProcessor) { // this may change in future to external class to deal with dynamic @@ -129,6 +232,17 @@ public void block(String blockName, RubyUtils.toSymbol(rubyRuntime, blockName)); } + public void block(String blockName, + String blockProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, blockProcessor); + + this.asciidoctorModule.block_processor( + getClassName(blockProcessor), + RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); + } + public void block(String blockName, Class blockProcessor) { // this may change in future to external class to deal with dynamic @@ -140,10 +254,25 @@ public void block(String blockName, RubyUtils.toSymbol(rubyRuntime, blockName)); } + public void block(String blockName, + Class blockProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, blockProcessor); + + this.asciidoctorModule.block_processor( + RubyUtils.toRubyClass(rubyRuntime, blockProcessor), + RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); + } + public void block(BlockProcessor blockProcessor) { block(blockProcessor.getName(), blockProcessor); } + public void block(BlockProcessor blockProcessor, String registrationName) { + block(blockProcessor.getName(), blockProcessor, registrationName); + } + public void block(String blockName, BlockProcessor blockProcessor) { // this may change in future to external class to deal with dynamic @@ -155,6 +284,17 @@ public void block(String blockName, RubyUtils.toSymbol(rubyRuntime, blockName)); } + public void block(String blockName, + BlockProcessor blockProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, blockProcessor.getClass()); + + this.asciidoctorModule.block_processor( + blockProcessor, + RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); + } + public void blockMacro(String blockName, Class blockMacroProcessor) { // this may change in future to external class to deal with dynamic @@ -165,6 +305,16 @@ public void blockMacro(String blockName, RubyUtils.toSymbol(rubyRuntime, blockName)); } + public void blockMacro(String blockName, + Class blockMacroProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, blockMacroProcessor); + this.asciidoctorModule.block_macro( + blockMacroProcessor.getSimpleName(), + RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); + } + public void blockMacro(String blockName, String blockMacroProcessor) { // this may change in future to external class to deal with dynamic @@ -175,6 +325,16 @@ public void blockMacro(String blockName, RubyUtils.toSymbol(rubyRuntime, blockName)); } + public void blockMacro(String blockName, + String blockMacroProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, blockMacroProcessor); + this.asciidoctorModule.block_macro( + getClassName(blockMacroProcessor), + RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); + } + public void blockMacro(BlockMacroProcessor blockMacroProcessor) { // this may change in future to external class to deal with dynamic // imports @@ -184,6 +344,15 @@ public void blockMacro(BlockMacroProcessor blockMacroProcessor) { RubyUtils.toSymbol(rubyRuntime, blockMacroProcessor.getName())); } + public void blockMacro(BlockMacroProcessor blockMacroProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, blockMacroProcessor.getClass()); + this.asciidoctorModule.block_macro( + blockMacroProcessor, + RubyUtils.toSymbol(rubyRuntime, blockMacroProcessor.getName()), registrationName); + } + public void inlineMacro(InlineMacroProcessor inlineMacroProcessor) { // this may change in future to external class to deal with dynamic // imports @@ -194,6 +363,16 @@ public void inlineMacro(InlineMacroProcessor inlineMacroProcessor) { RubyUtils.toSymbol(rubyRuntime, inlineMacroProcessor.getName())); } + public void inlineMacro(InlineMacroProcessor inlineMacroProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, inlineMacroProcessor.getClass()); + + this.asciidoctorModule.inline_macro( + inlineMacroProcessor, + RubyUtils.toSymbol(rubyRuntime, inlineMacroProcessor.getName()), registrationName); + } + public void inlineMacro(String blockName, Class inlineMacroProcessor) { // this may change in future to external class to deal with dynamic @@ -205,6 +384,17 @@ public void inlineMacro(String blockName, RubyUtils.toSymbol(rubyRuntime, blockName)); } + public void inlineMacro(String blockName, + Class inlineMacroProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic + // imports + javaImport(rubyRuntime, inlineMacroProcessor); + + this.asciidoctorModule.inline_macro( + RubyUtils.toRubyClass(rubyRuntime, inlineMacroProcessor), + RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); + } + public void inlineMacro(String blockName, String inlineMacroProcessor) { // this may change in future to external class to deal with dynamic imports javaImport(this.rubyRuntime, inlineMacroProcessor); @@ -214,6 +404,15 @@ public void inlineMacro(String blockName, String inlineMacroProcessor) { RubyUtils.toSymbol(rubyRuntime, blockName)); } + public void inlineMacro(String blockName, String inlineMacroProcessor, String registrationName) { + // this may change in future to external class to deal with dynamic imports + javaImport(this.rubyRuntime, inlineMacroProcessor); + + this.asciidoctorModule.inline_macro( + getClassName(inlineMacroProcessor), + RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); + } + private void javaImport(Ruby ruby, Class clazz) { ruby.evalScriptlet(String.format("java_import '%s'", getImportLine(clazz))); } diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/extension/RubyExtensionRegistry.java b/asciidoctorj-core/src/main/java/org/asciidoctor/extension/RubyExtensionRegistry.java index 1b429ca51..e7c6ee72e 100644 --- a/asciidoctorj-core/src/main/java/org/asciidoctor/extension/RubyExtensionRegistry.java +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/extension/RubyExtensionRegistry.java @@ -33,8 +33,18 @@ public RubyExtensionRegistry preprocessor(String preprocessor) { return this; } - public RubyExtensionRegistry postprocessor(String postprocesor) { - this.asciidoctorModule.postprocessor(postprocesor); + public RubyExtensionRegistry preprocessor(String preprocessor, String registrationName) { + this.asciidoctorModule.preprocessor(preprocessor, registrationName); + return this; + } + + public RubyExtensionRegistry postprocessor(String postprocessor) { + this.asciidoctorModule.postprocessor(postprocessor); + return this; + } + + public RubyExtensionRegistry postprocessor(String postprocessor, String registrationName) { + this.asciidoctorModule.postprocessor(postprocessor, registrationName); return this; } @@ -43,22 +53,43 @@ public RubyExtensionRegistry docinfoProcessor(String docinfoProcessor) { return this; } + public RubyExtensionRegistry docinfoProcessor(String docinfoProcessor, String registrationName) { + this.asciidoctorModule.docinfo_processor(docinfoProcessor, registrationName); + return this; + } + public RubyExtensionRegistry includeProcessor(String includeProcessor) { this.asciidoctorModule.include_processor(includeProcessor); return this; } + public RubyExtensionRegistry includeProcessor(String includeProcessor, String registrationName) { + this.asciidoctorModule.include_processor(includeProcessor, registrationName); + return this; + } + public RubyExtensionRegistry treeprocessor(String treeProcessor) { this.asciidoctorModule.treeprocessor(treeProcessor); return this; } + public RubyExtensionRegistry treeprocessor(String treeProcessor, String registrationName) { + this.asciidoctorModule.treeprocessor(treeProcessor, registrationName); + return this; + } + public RubyExtensionRegistry block(String blockName, String blockProcessor) { this.asciidoctorModule.block_processor( blockProcessor, RubyUtils.toSymbol(rubyRuntime, blockName)); return this; } + public RubyExtensionRegistry block(String blockName, String blockProcessor, String registrationName) { + this.asciidoctorModule.block_processor( + blockProcessor, RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); + return this; + } + public RubyExtensionRegistry blockMacro(String blockName, String blockMacroProcessor) { this.asciidoctorModule.block_macro( @@ -66,6 +97,13 @@ public RubyExtensionRegistry blockMacro(String blockName, String blockMacroProce return this; } + public RubyExtensionRegistry blockMacro(String blockName, String blockMacroProcessor, String registrationName) { + + this.asciidoctorModule.block_macro( + blockMacroProcessor, RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); + return this; + } + public RubyExtensionRegistry inlineMacro(String blockName, String inlineMacroProcessor) { this.asciidoctorModule.inline_macro( @@ -73,4 +111,11 @@ public RubyExtensionRegistry inlineMacro(String blockName, String inlineMacroPro return this; } + public RubyExtensionRegistry inlineMacro(String blockName, String inlineMacroProcessor, String registrationName) { + + this.asciidoctorModule.inline_macro( + inlineMacroProcessor, RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); + return this; + } + } \ No newline at end of file diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/internal/AsciidoctorModule.java b/asciidoctorj-core/src/main/java/org/asciidoctor/internal/AsciidoctorModule.java index 7aa01e418..1f08d7cef 100644 --- a/asciidoctorj-core/src/main/java/org/asciidoctor/internal/AsciidoctorModule.java +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/internal/AsciidoctorModule.java @@ -13,38 +13,63 @@ public interface AsciidoctorModule { void preprocessor(String preprocessorClassName); + void preprocessor(String preprocessorClassName, String registrationName); void preprocessor(RubyClass preprocessorClassName); - void preprocessor(Preprocessor preprocessor); - + void preprocessor(RubyClass preprocessorClassName, String registrationName); + void preprocessor(Preprocessor preprocessor); + void preprocessor(Preprocessor preprocessor, String registrationName); + void postprocessor(String postprocessorClassName); + void postprocessor(String postprocessorClassName, String registrationName); void postprocessor(RubyClass postprocessorClassName); + void postprocessor(RubyClass postprocessorClassName, String registrationName); void postprocessor(Postprocessor postprocessor); - + void postprocessor(Postprocessor postprocessor, String registrationName); + void treeprocessor(String treeprocessor); + void treeprocessor(String treeprocessor, String registrationName); void treeprocessor(RubyClass treeprocessorClassName); + void treeprocessor(RubyClass treeprocessorClassName, String registrationName); void treeprocessor(Treeprocessor treeprocessorClassName); - + void treeprocessor(Treeprocessor treeprocessorClassName, String registrationName); + void include_processor(String includeProcessorClassName); + void include_processor(String includeProcessorClassName, String registrationName); void include_processor(RubyClass includeProcessorClassName); + void include_processor(RubyClass includeProcessorClassName, String registrationName); void include_processor(IncludeProcessor includeProcessor); - + void include_processor(IncludeProcessor includeProcessor, String registrationName); + void block_processor(String blockClassName, Object blockName); + void block_processor(String blockClassName, Object blockName, String registrationName); void block_processor(RubyClass blockClass, Object blockName); + void block_processor(RubyClass blockClass, Object blockName, String registrationName); void block_processor(BlockProcessor blockInstance, Object blockName); - + void block_processor(BlockProcessor blockInstance, Object blockName, String registrationName); + void block_macro(String blockMacroClassName, Object blockName); + void block_macro(String blockMacroClassName, Object blockName, String registrationName); void block_macro(Class blockMacroClass, Object blockName); + void block_macro(Class blockMacroClass, Object blockName, String registrationName); void block_macro(BlockMacroProcessor blockMacroInstance, Object blockName); - + void block_macro(BlockMacroProcessor blockMacroInstance, Object blockName, String registrationName); + void inline_macro(String blockClassName, Object blockSymbol); + void inline_macro(String blockClassName, Object blockSymbol, String registrationName); void inline_macro(RubyClass blockClassName, Object blockSymbol); + void inline_macro(RubyClass blockClassName, Object blockSymbol, String registrationName); void inline_macro(InlineMacroProcessor blockClassName, Object blockSymbol); - + void inline_macro(InlineMacroProcessor blockClassName, Object blockSymbol, String registrationName); + void docinfo_processor(String docInfoClassName); + void docinfo_processor(String docInfoClassName, String registrationName); void docinfo_processor(RubyClass docInfoClassName); + void docinfo_processor(RubyClass docInfoClassName, String registrationName); void docinfo_processor(DocinfoProcessor docInfoClassName); - + void docinfo_processor(DocinfoProcessor docInfoClassName, String registrationName); + void unregister_all_extensions(); + void unregister_extension(String registrationName); Object convert(String content, Map options); Object convertFile(String filename, Map options); diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/internal/JRubyAsciidoctor.java b/asciidoctorj-core/src/main/java/org/asciidoctor/internal/JRubyAsciidoctor.java index 315486b75..ed663bc10 100644 --- a/asciidoctorj-core/src/main/java/org/asciidoctor/internal/JRubyAsciidoctor.java +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/internal/JRubyAsciidoctor.java @@ -497,6 +497,11 @@ public void unregisterAllExtensions() { this.asciidoctorModule.unregister_all_extensions(); } + @Override + public void unregisterExtension(String registrationName) { + this.asciidoctorModule.unregister_extension(registrationName); + } + @Override public void shutdown() { this.rubyRuntime.tearDown(); diff --git a/asciidoctorj-core/src/main/resources/org/asciidoctor/internal/asciidoctorclass.rb b/asciidoctorj-core/src/main/resources/org/asciidoctor/internal/asciidoctorclass.rb index da34f73b7..78640d92b 100644 --- a/asciidoctorj-core/src/main/resources/org/asciidoctor/internal/asciidoctorclass.rb +++ b/asciidoctorj-core/src/main/resources/org/asciidoctor/internal/asciidoctorclass.rb @@ -4,7 +4,9 @@ module Extensions include_package 'org.asciidoctor.extension' # Treeprocessor was renamed in to TreeProcessor in https://github.com/asciidoctor/asciidoctor/commit/f1dd816ade9db457b899581841e4cf7b788aa26d # This is necessary to run against both Asciidoctor 1.5.5 and 1.5.6 - TreeProcessor = Treeprocessor + if !defined? TreeProcessor + TreeProcessor = Treeprocessor + end end end @@ -19,50 +21,54 @@ def unregister_all_extensions() Asciidoctor::Extensions.unregister_all end - def docinfo_processor(extensionName) - Asciidoctor::Extensions.register do + def unregister_extension name + Asciidoctor::Extensions.unregister name + end + + def docinfo_processor(extensionName, registrationName = nil) + Asciidoctor::Extensions.register (registrationName != nil ? registrationName.to_sym : nil) do docinfo_processor extensionName end end - def treeprocessor(extensionName) - Asciidoctor::Extensions.register do + def treeprocessor(extensionName, registrationName = nil) + Asciidoctor::Extensions.register (registrationName != nil ? registrationName.to_sym : nil) do treeprocessor extensionName end end - def include_processor(extensionName) - Asciidoctor::Extensions.register do + def include_processor(extensionName, registrationName = nil) + Asciidoctor::Extensions.register (registrationName != nil ? registrationName.to_sym : nil) do include_processor extensionName end end - def preprocessor(extensionName) - Asciidoctor::Extensions.register do + def preprocessor(extensionName, registrationName = nil) + Asciidoctor::Extensions.register (registrationName != nil ? registrationName.to_sym : nil) do preprocessor extensionName end end - def postprocessor(extensionName) - Asciidoctor::Extensions.register do + def postprocessor(extensionName, registrationName = nil) + Asciidoctor::Extensions.register (registrationName != nil ? registrationName.to_sym : nil) do postprocessor extensionName end end - def block_processor(extensionName, blockSymbol) - Asciidoctor::Extensions.register do + def block_processor(extensionName, blockSymbol, registrationName = nil) + Asciidoctor::Extensions.register (registrationName != nil ? registrationName.to_sym : nil) do block extensionName, blockSymbol end end - def block_macro(extensionName, blockSymbol) - Asciidoctor::Extensions.register do + def block_macro(extensionName, blockSymbol, registrationName = nil) + Asciidoctor::Extensions.register (registrationName != nil ? registrationName.to_sym : nil) do block_macro extensionName, blockSymbol end end - def inline_macro(extensionName, blockSymbol) - Asciidoctor::Extensions.register do + def inline_macro(extensionName, blockSymbol, registrationName = nil) + Asciidoctor::Extensions.register (registrationName != nil ? registrationName.to_sym : nil) do inline_macro extensionName, blockSymbol end end diff --git a/asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenJavaExtensionIsRegistered.java b/asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenJavaExtensionIsRegistered.java index 06acc4156..08660db17 100644 --- a/asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenJavaExtensionIsRegistered.java +++ b/asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenJavaExtensionIsRegistered.java @@ -20,6 +20,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import java.util.UUID; import org.asciidoctor.Asciidoctor; import org.asciidoctor.AttributesBuilder; @@ -700,4 +701,69 @@ public void a_block_processor_instance_should_be_executed_when_registered_block_ } + @Test + public void should_unregister_postprocessor() throws IOException { + + // Given: A registered Postprocessor + JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); + final String registrationName = UUID.randomUUID().toString(); + javaExtensionRegistry.postprocessor(CustomFooterPostProcessor.class, registrationName); + + // When: I render a document + Options options = options().inPlace(false).toFile(new File(testFolder.getRoot(), "rendersample.html")) + .safe(SafeMode.UNSAFE).get(); + + asciidoctor.renderFile(classpath.getResource("rendersample.asciidoc"), options); + + // Then: it is invoked + File renderedFile = new File(testFolder.getRoot(), "rendersample.html"); + org.jsoup.nodes.Document doc = Jsoup.parse(renderedFile, "UTF-8"); + Element footer = doc.getElementById("footer-text"); + assertThat(footer.text(), containsString("Copyright Acme, Inc.")); + + // When: I unregister the Postprocessor and render again with the same Asciidoctor instance + asciidoctor.unregisterExtension(registrationName); + + Options options2 = options().inPlace(false).toFile(new File(testFolder.getRoot(), "rendersample2.html")) + .safe(SafeMode.UNSAFE).get(); + asciidoctor.renderFile(classpath.getResource("rendersample.asciidoc"), options2); + File renderedFile2 = new File(testFolder.getRoot(), "rendersample2.html"); + org.jsoup.nodes.Document doc2 = Jsoup.parse(renderedFile2, "UTF-8"); + + Element footer2 = doc2.getElementById("footer-text"); + assertThat(footer2.text(), not(containsString("Copyright Acme, Inc."))); + } + + @Test + public void should_unregister_block_processor() + throws IOException { + + JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); + final String registrationName = UUID.randomUUID().toString(); + + Map config = new HashMap(); + config.put("contexts", Arrays.asList(":paragraph")); + config.put("content_model", ":simple"); + YellBlock yellBlock = new YellBlock("yell", config); + javaExtensionRegistry.block(yellBlock, registrationName); + String content = asciidoctor.renderFile( + classpath.getResource("sample-with-yell-block.ad"), + options().toFile(false).get()); + Document doc = Jsoup.parse(content, "UTF-8"); + Elements elements = doc.getElementsByClass("paragraph"); + assertThat(elements.size(), is(1)); + assertThat(elements.get(0).text(), is("THE TIME IS NOW. GET A MOVE ON.")); + + asciidoctor.unregisterExtension(registrationName); + String contentWithoutBlock = asciidoctor.renderFile( + classpath.getResource("sample-with-yell-block.ad"), + options().toFile(false).get()); + Document docWithoutBlock = Jsoup.parse(contentWithoutBlock, "UTF-8"); + Elements elementsWithoutBlock = docWithoutBlock.getElementsByClass("paragraph"); + assertThat(elementsWithoutBlock.size(), is(1)); + assertThat(elementsWithoutBlock.get(0).text(), not(is("THE TIME IS NOW. GET A MOVE ON."))); + + } + + } diff --git a/asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenRubyExtensionIsRegistered.java b/asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenRubyExtensionIsRegistered.java index 865dd89b6..e9c677f44 100644 --- a/asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenRubyExtensionIsRegistered.java +++ b/asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenRubyExtensionIsRegistered.java @@ -2,6 +2,7 @@ import static org.asciidoctor.OptionsBuilder.options; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; import static org.junit.Assert.assertThat; import org.asciidoctor.Asciidoctor; @@ -13,6 +14,8 @@ import org.junit.Rule; import org.junit.Test; +import java.util.UUID; + public class WhenRubyExtensionIsRegistered { @Rule @@ -37,4 +40,34 @@ public void ruby_extension_should_be_registered() { } + @Test + public void ruby_extension_should_be_unregistered() { + + RubyExtensionRegistry rubyExtensionRegistry = this.asciidoctor.rubyExtensionRegistry(); + String registrationName = UUID.randomUUID().toString(); + + rubyExtensionRegistry.loadClass(Class.class.getResourceAsStream("/YellRubyBlock.rb")).block("rubyyell", "YellRubyBlock", registrationName); + + String content = asciidoctor.renderFile( + classpath.getResource("sample-with-ruby-yell-block.ad"), + 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!")); + + asciidoctor.unregisterExtension(registrationName); + + String contentWithoutBlock = asciidoctor.renderFile( + classpath.getResource("sample-with-ruby-yell-block.ad"), + options().toFile(false).get()); + + Document docWithoutBlock = Jsoup.parse(contentWithoutBlock, "UTF-8"); + Elements elementsWithoutBlock = docWithoutBlock.getElementsByClass("paragraph"); + assertThat(elementsWithoutBlock.size(), is(2)); + assertThat(elementsWithoutBlock.get(1).text(), not(is("THE TIME IS NOW! GET A MOVE ON!"))); + + } + } diff --git a/build.gradle b/build.gradle index fc48a6ae1..0be572f21 100644 --- a/build.gradle +++ b/build.gradle @@ -45,7 +45,7 @@ ext { xmlMatchersVersion = '1.0-RC1' // gem versions - asciidoctorGemVersion = project.hasProperty('asciidoctorGemVersion') ? project.asciidoctorGemVersion : '1.5.5' + asciidoctorGemVersion = project.hasProperty('asciidoctorGemVersion') ? project.asciidoctorGemVersion : '1.5.6' asciidoctorEpub3GemVersion = project(':asciidoctorj-epub3').version.replace('-', '.') asciidoctorDiagramGemVersion = project(':asciidoctorj-diagram').version.replace('-', '.') From 9942d0aab12b84a62b79d63aeb72724bfe862d93 Mon Sep 17 00:00:00 2001 From: Robert Panzer Date: Fri, 21 Jul 2017 09:21:04 +0200 Subject: [PATCH 2/4] Introduce ExtensionGroup --- .../java/org/asciidoctor/Asciidoctor.java | 14 +- .../asciidoctor/extension/ExtensionGroup.java | 74 +++ .../extension/JavaExtensionRegistry.java | 199 ------- .../extension/RubyExtensionRegistry.java | 47 +- .../internal/AsciidoctorModule.java | 2 +- .../internal/ExtensionGroupImpl.java | 506 ++++++++++++++++++ .../internal/JRubyAsciidoctor.java | 19 +- .../asciidoctor/internal/asciidoctorclass.rb | 32 +- .../WhenJavaExtensionIsRegistered.java | 152 +++--- .../WhenRubyExtensionIsRegistered.java | 54 +- 10 files changed, 752 insertions(+), 347 deletions(-) create mode 100644 asciidoctorj-core/src/main/java/org/asciidoctor/extension/ExtensionGroup.java create mode 100644 asciidoctorj-core/src/main/java/org/asciidoctor/internal/ExtensionGroupImpl.java diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/Asciidoctor.java b/asciidoctorj-core/src/main/java/org/asciidoctor/Asciidoctor.java index fdf63efe7..e00555678 100644 --- a/asciidoctorj-core/src/main/java/org/asciidoctor/Asciidoctor.java +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/Asciidoctor.java @@ -13,6 +13,7 @@ import org.asciidoctor.ast.DocumentRuby; import org.asciidoctor.ast.StructuredDocument; import org.asciidoctor.converter.JavaConverterRegistry; +import org.asciidoctor.extension.ExtensionGroup; import org.asciidoctor.extension.JavaExtensionRegistry; import org.asciidoctor.extension.RubyExtensionRegistry; import org.asciidoctor.internal.JRubyAsciidoctor; @@ -633,7 +634,18 @@ String[] convertFiles(Collection asciidoctorFiles, * @return Converter Registry object. */ JavaConverterRegistry javaConverterRegistry(); - + + /** + * Creates an ExtensionGroup that can be used to register and unregister a group of extensions. + * @return + */ + ExtensionGroup createGroup(); + + /** + * Creates an ExtensionGroup that can be used to register and unregister a group of extensions. + * @return + */ + ExtensionGroup createGroup(String groupName); /** * Unregister all registered extensions. */ diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/extension/ExtensionGroup.java b/asciidoctorj-core/src/main/java/org/asciidoctor/extension/ExtensionGroup.java new file mode 100644 index 000000000..248c5fe57 --- /dev/null +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/extension/ExtensionGroup.java @@ -0,0 +1,74 @@ +package org.asciidoctor.extension; + + +import java.io.InputStream; + +/** + * An ExtensionGroup allows to collectively register and unregister extensions. + * All extensions are registered lazily and are not effective before a call to {@link #register()}. + * + *

Example: + *

+ * ExtensionGroup group = asciidoctor.createGroup();
+ * group.block(myBlock).preprocessor(mypreprocessor);
+ *
+ * // Convert with extensions
+ * group.register();
+ * asciidoctor.convert(...);
+ * group.unregister();
+ *
+ * // Convert without extensions
+ * asciidoctor.convert(...);
+ * 

+ */ +public interface ExtensionGroup { + + public void register(); + + public void unregister(); + + public ExtensionGroup docinfoProcessor(Class docInfoProcessor); + public ExtensionGroup docinfoProcessor(DocinfoProcessor docInfoProcessor); + public ExtensionGroup docinfoProcessor(String docInfoProcessor); + + public ExtensionGroup preprocessor(Class preprocessor); + public ExtensionGroup preprocessor(Preprocessor preprocessor); + public ExtensionGroup preprocessor(String preprocessor); + + public ExtensionGroup postprocessor(String postprocessor); + public ExtensionGroup postprocessor(Class postprocessor); + public ExtensionGroup postprocessor(Postprocessor postprocesor); + + public ExtensionGroup includeProcessor(String includeProcessor); + public ExtensionGroup includeProcessor(Class includeProcessor); + public ExtensionGroup includeProcessor(IncludeProcessor includeProcessor); + + public ExtensionGroup treeprocessor(Treeprocessor treeprocessor); + public ExtensionGroup treeprocessor(Class treeProcessor); + public ExtensionGroup treeprocessor(String treeProcessor); + + public ExtensionGroup block(String blockName, String blockProcessor); + public ExtensionGroup block(String blockName, Class blockProcessor); + public ExtensionGroup block(BlockProcessor blockProcessor); + public ExtensionGroup block(String blockName, BlockProcessor blockProcessor); + + public ExtensionGroup blockMacro(String blockName, Class blockMacroProcessor); + public ExtensionGroup blockMacro(String blockName, String blockMacroProcessor); + public ExtensionGroup blockMacro(BlockMacroProcessor blockMacroProcessor); + + public ExtensionGroup inlineMacro(InlineMacroProcessor inlineMacroProcessor); + public ExtensionGroup inlineMacro(String blockName, Class inlineMacroProcessor); + public ExtensionGroup inlineMacro(String blockName, String inlineMacroProcessor); + + public ExtensionGroup requireRubyLibrary(String requiredLibrary); + public ExtensionGroup loadRubyClass(InputStream rubyClassStream); + + public ExtensionGroup rubyPreprocessor(String preprocessor); + public ExtensionGroup rubyPostprocessor(String postprocessor); + public ExtensionGroup rubyDocinfoProcessor(String docinfoProcessor); + public ExtensionGroup rubyIncludeProcessor(String includeProcessor); + public ExtensionGroup rubyTreeprocessor(String treeProcessor); + public ExtensionGroup rubyBlock(String blockName, String blockProcessor); + public ExtensionGroup rubyBlockMacro(String blockName, String blockMacroProcessor); + public ExtensionGroup rubyInlineMacro(String blockName, String inlineMacroProcessor); +} diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/extension/JavaExtensionRegistry.java b/asciidoctorj-core/src/main/java/org/asciidoctor/extension/JavaExtensionRegistry.java index e3f7340bc..2b969ae4a 100644 --- a/asciidoctorj-core/src/main/java/org/asciidoctor/extension/JavaExtensionRegistry.java +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/extension/JavaExtensionRegistry.java @@ -22,13 +22,6 @@ public void docinfoProcessor(Class docInfoProcessor) this.asciidoctorModule.docinfo_processor(RubyUtils.toRubyClass(rubyRuntime, docInfoProcessor)); } - public void docinfoProcessor(Class docInfoProcessor, String registrationName) { - // this may change in future to external class to deal with dynamic - // imports - javaImport(rubyRuntime, docInfoProcessor); - this.asciidoctorModule.docinfo_processor(RubyUtils.toRubyClass(rubyRuntime, docInfoProcessor), registrationName); - } - public void docinfoProcessor(DocinfoProcessor docInfoProcessor) { // this may change in future to external class to deal with dynamic // imports @@ -36,13 +29,6 @@ public void docinfoProcessor(DocinfoProcessor docInfoProcessor) { this.asciidoctorModule.docinfo_processor(docInfoProcessor); } - public void docinfoProcessor(DocinfoProcessor docInfoProcessor, String registrationName) { - // this may change in future to external class to deal with dynamic - // imports - javaImport(rubyRuntime, docInfoProcessor.getClass()); - this.asciidoctorModule.docinfo_processor(docInfoProcessor, registrationName); - } - public void docinfoProcessor(String docInfoProcessor) { // this may change in future to external class to deal with dynamic // imports @@ -50,13 +36,6 @@ public void docinfoProcessor(String docInfoProcessor) { this.asciidoctorModule.docinfo_processor(getClassName(docInfoProcessor)); } - public void docinfoProcessor(String docInfoProcessor, String registrationName) { - // this may change in future to external class to deal with dynamic - // imports - javaImport(rubyRuntime, docInfoProcessor); - this.asciidoctorModule.docinfo_processor(getClassName(docInfoProcessor), registrationName); - } - public void preprocessor(Class preprocessor) { // this may change in future to external class to deal with dynamic // imports @@ -64,13 +43,6 @@ public void preprocessor(Class preprocessor) { this.asciidoctorModule.preprocessor(RubyUtils.toRubyClass(rubyRuntime, preprocessor)); } - public void preprocessor(Class preprocessor, String registrationName) { - // this may change in future to external class to deal with dynamic - // imports - javaImport(rubyRuntime, preprocessor); - this.asciidoctorModule.preprocessor(RubyUtils.toRubyClass(rubyRuntime, preprocessor), registrationName); - } - public void preprocessor(Preprocessor preprocessor) { // this may change in future to external class to deal with dynamic // imports @@ -78,13 +50,6 @@ public void preprocessor(Preprocessor preprocessor) { this.asciidoctorModule.preprocessor(preprocessor); } - public void preprocessor(Preprocessor preprocessor, String registrationName) { - // this may change in future to external class to deal with dynamic - // imports - javaImport(rubyRuntime, preprocessor.getClass()); - this.asciidoctorModule.preprocessor(preprocessor, registrationName); - } - public void preprocessor(String preprocessor) { // this may change in future to external class to deal with dynamic // imports @@ -92,13 +57,6 @@ public void preprocessor(String preprocessor) { this.asciidoctorModule.preprocessor(getClassName(preprocessor)); } - public void preprocessor(String preprocessor, String registrationName) { - // this may change in future to external class to deal with dynamic - // imports - javaImport(rubyRuntime, preprocessor); - this.asciidoctorModule.preprocessor(getClassName(preprocessor), registrationName); - } - public void postprocessor(String postprocessor) { // this may change in future to external class to deal with dynamic // imports @@ -106,13 +64,6 @@ public void postprocessor(String postprocessor) { this.asciidoctorModule.postprocessor(getClassName(postprocessor)); } - public void postprocessor(String postprocessor, String registrationName) { - // this may change in future to external class to deal with dynamic - // imports - javaImport(rubyRuntime, postprocessor); - this.asciidoctorModule.postprocessor(getClassName(postprocessor), registrationName); - } - public void postprocessor(Class postprocessor) { // this may change in future to external class to deal with dynamic // imports @@ -120,13 +71,6 @@ public void postprocessor(Class postprocessor) { this.asciidoctorModule.postprocessor(RubyUtils.toRubyClass(rubyRuntime, postprocessor)); } - public void postprocessor(Class postprocessor, String registrationName) { - // this may change in future to external class to deal with dynamic - // imports - javaImport(rubyRuntime, postprocessor); - this.asciidoctorModule.postprocessor(RubyUtils.toRubyClass(rubyRuntime, postprocessor), registrationName); - } - public void postprocessor(Postprocessor postprocesor) { // this may change in future to external class to deal with dynamic // imports @@ -134,13 +78,6 @@ public void postprocessor(Postprocessor postprocesor) { this.asciidoctorModule.postprocessor(postprocesor); } - public void postprocessor(Postprocessor postprocesor, String registrationName) { - // this may change in future to external class to deal with dynamic - // imports - javaImport(rubyRuntime, postprocesor.getClass()); - this.asciidoctorModule.postprocessor(postprocesor, registrationName); - } - public void includeProcessor(String includeProcessor) { // this may change in future to external class to deal with dynamic // imports @@ -148,13 +85,6 @@ public void includeProcessor(String includeProcessor) { this.asciidoctorModule.include_processor(getClassName(includeProcessor)); } - public void includeProcessor(String includeProcessor, String registrationName) { - // this may change in future to external class to deal with dynamic - // imports - javaImport(rubyRuntime, includeProcessor); - this.asciidoctorModule.include_processor(getClassName(includeProcessor), registrationName); - } - public void includeProcessor( Class includeProcessor) { // this may change in future to external class to deal with dynamic @@ -163,36 +93,17 @@ public void includeProcessor( this.asciidoctorModule.include_processor(RubyUtils.toRubyClass(rubyRuntime, includeProcessor)); } - public void includeProcessor( - Class includeProcessor, String registrationName) { - // this may change in future to external class to deal with dynamic - // imports - javaImport(rubyRuntime, includeProcessor); - this.asciidoctorModule.include_processor(RubyUtils.toRubyClass(rubyRuntime, includeProcessor), registrationName); - } - public void includeProcessor(IncludeProcessor includeProcessor) { String importLine = getImportLine(includeProcessor.getClass()); javaImport(rubyRuntime, importLine); this.asciidoctorModule.include_processor(includeProcessor); } - public void includeProcessor(IncludeProcessor includeProcessor, String registrationName) { - String importLine = getImportLine(includeProcessor.getClass()); - javaImport(rubyRuntime, importLine); - this.asciidoctorModule.include_processor(includeProcessor, registrationName); - } - public void treeprocessor(Treeprocessor treeprocessor) { javaImport(rubyRuntime, treeprocessor.getClass()); this.asciidoctorModule.treeprocessor(treeprocessor); } - public void treeprocessor(Treeprocessor treeprocessor, String registrationName) { - javaImport(rubyRuntime, treeprocessor.getClass()); - this.asciidoctorModule.treeprocessor(treeprocessor, registrationName); - } - public void treeprocessor(Class treeProcessor) { // this may change in future to external class to deal with dynamic // imports @@ -200,13 +111,6 @@ public void treeprocessor(Class treeProcessor) { this.asciidoctorModule.treeprocessor(RubyUtils.toRubyClass(rubyRuntime, treeProcessor)); } - public void treeprocessor(Class treeProcessor, String registrationName) { - // this may change in future to external class to deal with dynamic - // imports - javaImport(rubyRuntime, treeProcessor); - this.asciidoctorModule.treeprocessor(RubyUtils.toRubyClass(rubyRuntime, treeProcessor), registrationName); - } - public void treeprocessor(String treeProcessor) { // this may change in future to external class to deal with dynamic // imports @@ -214,13 +118,6 @@ public void treeprocessor(String treeProcessor) { this.asciidoctorModule.treeprocessor(getClassName(treeProcessor)); } - public void treeprocessor(String treeProcessor, String registrationName) { - // this may change in future to external class to deal with dynamic - // imports - javaImport(rubyRuntime, treeProcessor); - this.asciidoctorModule.treeprocessor(getClassName(treeProcessor), registrationName); - } - public void block(String blockName, String blockProcessor) { // this may change in future to external class to deal with dynamic @@ -232,17 +129,6 @@ public void block(String blockName, RubyUtils.toSymbol(rubyRuntime, blockName)); } - public void block(String blockName, - String blockProcessor, String registrationName) { - // this may change in future to external class to deal with dynamic - // imports - javaImport(rubyRuntime, blockProcessor); - - this.asciidoctorModule.block_processor( - getClassName(blockProcessor), - RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); - } - public void block(String blockName, Class blockProcessor) { // this may change in future to external class to deal with dynamic @@ -254,25 +140,10 @@ public void block(String blockName, RubyUtils.toSymbol(rubyRuntime, blockName)); } - public void block(String blockName, - Class blockProcessor, String registrationName) { - // this may change in future to external class to deal with dynamic - // imports - javaImport(rubyRuntime, blockProcessor); - - this.asciidoctorModule.block_processor( - RubyUtils.toRubyClass(rubyRuntime, blockProcessor), - RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); - } - public void block(BlockProcessor blockProcessor) { block(blockProcessor.getName(), blockProcessor); } - public void block(BlockProcessor blockProcessor, String registrationName) { - block(blockProcessor.getName(), blockProcessor, registrationName); - } - public void block(String blockName, BlockProcessor blockProcessor) { // this may change in future to external class to deal with dynamic @@ -284,17 +155,6 @@ public void block(String blockName, RubyUtils.toSymbol(rubyRuntime, blockName)); } - public void block(String blockName, - BlockProcessor blockProcessor, String registrationName) { - // this may change in future to external class to deal with dynamic - // imports - javaImport(rubyRuntime, blockProcessor.getClass()); - - this.asciidoctorModule.block_processor( - blockProcessor, - RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); - } - public void blockMacro(String blockName, Class blockMacroProcessor) { // this may change in future to external class to deal with dynamic @@ -305,16 +165,6 @@ public void blockMacro(String blockName, RubyUtils.toSymbol(rubyRuntime, blockName)); } - public void blockMacro(String blockName, - Class blockMacroProcessor, String registrationName) { - // this may change in future to external class to deal with dynamic - // imports - javaImport(rubyRuntime, blockMacroProcessor); - this.asciidoctorModule.block_macro( - blockMacroProcessor.getSimpleName(), - RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); - } - public void blockMacro(String blockName, String blockMacroProcessor) { // this may change in future to external class to deal with dynamic @@ -325,16 +175,6 @@ public void blockMacro(String blockName, RubyUtils.toSymbol(rubyRuntime, blockName)); } - public void blockMacro(String blockName, - String blockMacroProcessor, String registrationName) { - // this may change in future to external class to deal with dynamic - // imports - javaImport(rubyRuntime, blockMacroProcessor); - this.asciidoctorModule.block_macro( - getClassName(blockMacroProcessor), - RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); - } - public void blockMacro(BlockMacroProcessor blockMacroProcessor) { // this may change in future to external class to deal with dynamic // imports @@ -344,15 +184,6 @@ public void blockMacro(BlockMacroProcessor blockMacroProcessor) { RubyUtils.toSymbol(rubyRuntime, blockMacroProcessor.getName())); } - public void blockMacro(BlockMacroProcessor blockMacroProcessor, String registrationName) { - // this may change in future to external class to deal with dynamic - // imports - javaImport(rubyRuntime, blockMacroProcessor.getClass()); - this.asciidoctorModule.block_macro( - blockMacroProcessor, - RubyUtils.toSymbol(rubyRuntime, blockMacroProcessor.getName()), registrationName); - } - public void inlineMacro(InlineMacroProcessor inlineMacroProcessor) { // this may change in future to external class to deal with dynamic // imports @@ -363,16 +194,6 @@ public void inlineMacro(InlineMacroProcessor inlineMacroProcessor) { RubyUtils.toSymbol(rubyRuntime, inlineMacroProcessor.getName())); } - public void inlineMacro(InlineMacroProcessor inlineMacroProcessor, String registrationName) { - // this may change in future to external class to deal with dynamic - // imports - javaImport(rubyRuntime, inlineMacroProcessor.getClass()); - - this.asciidoctorModule.inline_macro( - inlineMacroProcessor, - RubyUtils.toSymbol(rubyRuntime, inlineMacroProcessor.getName()), registrationName); - } - public void inlineMacro(String blockName, Class inlineMacroProcessor) { // this may change in future to external class to deal with dynamic @@ -384,17 +205,6 @@ public void inlineMacro(String blockName, RubyUtils.toSymbol(rubyRuntime, blockName)); } - public void inlineMacro(String blockName, - Class inlineMacroProcessor, String registrationName) { - // this may change in future to external class to deal with dynamic - // imports - javaImport(rubyRuntime, inlineMacroProcessor); - - this.asciidoctorModule.inline_macro( - RubyUtils.toRubyClass(rubyRuntime, inlineMacroProcessor), - RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); - } - public void inlineMacro(String blockName, String inlineMacroProcessor) { // this may change in future to external class to deal with dynamic imports javaImport(this.rubyRuntime, inlineMacroProcessor); @@ -404,15 +214,6 @@ public void inlineMacro(String blockName, String inlineMacroProcessor) { RubyUtils.toSymbol(rubyRuntime, blockName)); } - public void inlineMacro(String blockName, String inlineMacroProcessor, String registrationName) { - // this may change in future to external class to deal with dynamic imports - javaImport(this.rubyRuntime, inlineMacroProcessor); - - this.asciidoctorModule.inline_macro( - getClassName(inlineMacroProcessor), - RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); - } - private void javaImport(Ruby ruby, Class clazz) { ruby.evalScriptlet(String.format("java_import '%s'", getImportLine(clazz))); } diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/extension/RubyExtensionRegistry.java b/asciidoctorj-core/src/main/java/org/asciidoctor/extension/RubyExtensionRegistry.java index e7c6ee72e..69a1e19db 100644 --- a/asciidoctorj-core/src/main/java/org/asciidoctor/extension/RubyExtensionRegistry.java +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/extension/RubyExtensionRegistry.java @@ -9,6 +9,7 @@ public class RubyExtensionRegistry { private AsciidoctorModule asciidoctorModule; + private Ruby rubyRuntime; public RubyExtensionRegistry(AsciidoctorModule asciidoctorModule, @@ -33,63 +34,32 @@ public RubyExtensionRegistry preprocessor(String preprocessor) { return this; } - public RubyExtensionRegistry preprocessor(String preprocessor, String registrationName) { - this.asciidoctorModule.preprocessor(preprocessor, registrationName); - return this; - } - public RubyExtensionRegistry postprocessor(String postprocessor) { this.asciidoctorModule.postprocessor(postprocessor); return this; } - public RubyExtensionRegistry postprocessor(String postprocessor, String registrationName) { - this.asciidoctorModule.postprocessor(postprocessor, registrationName); - return this; - } - public RubyExtensionRegistry docinfoProcessor(String docinfoProcessor) { this.asciidoctorModule.docinfo_processor(docinfoProcessor); return this; } - public RubyExtensionRegistry docinfoProcessor(String docinfoProcessor, String registrationName) { - this.asciidoctorModule.docinfo_processor(docinfoProcessor, registrationName); - return this; - } - public RubyExtensionRegistry includeProcessor(String includeProcessor) { this.asciidoctorModule.include_processor(includeProcessor); return this; } - public RubyExtensionRegistry includeProcessor(String includeProcessor, String registrationName) { - this.asciidoctorModule.include_processor(includeProcessor, registrationName); - return this; - } - public RubyExtensionRegistry treeprocessor(String treeProcessor) { this.asciidoctorModule.treeprocessor(treeProcessor); return this; } - public RubyExtensionRegistry treeprocessor(String treeProcessor, String registrationName) { - this.asciidoctorModule.treeprocessor(treeProcessor, registrationName); - return this; - } - public RubyExtensionRegistry block(String blockName, String blockProcessor) { this.asciidoctorModule.block_processor( blockProcessor, RubyUtils.toSymbol(rubyRuntime, blockName)); return this; } - public RubyExtensionRegistry block(String blockName, String blockProcessor, String registrationName) { - this.asciidoctorModule.block_processor( - blockProcessor, RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); - return this; - } - public RubyExtensionRegistry blockMacro(String blockName, String blockMacroProcessor) { this.asciidoctorModule.block_macro( @@ -97,25 +67,10 @@ public RubyExtensionRegistry blockMacro(String blockName, String blockMacroProce return this; } - public RubyExtensionRegistry blockMacro(String blockName, String blockMacroProcessor, String registrationName) { - - this.asciidoctorModule.block_macro( - blockMacroProcessor, RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); - return this; - } - public RubyExtensionRegistry inlineMacro(String blockName, String inlineMacroProcessor) { this.asciidoctorModule.inline_macro( inlineMacroProcessor, RubyUtils.toSymbol(rubyRuntime, blockName)); return this; } - - public RubyExtensionRegistry inlineMacro(String blockName, String inlineMacroProcessor, String registrationName) { - - this.asciidoctorModule.inline_macro( - inlineMacroProcessor, RubyUtils.toSymbol(rubyRuntime, blockName), registrationName); - return this; - } - } \ No newline at end of file diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/internal/AsciidoctorModule.java b/asciidoctorj-core/src/main/java/org/asciidoctor/internal/AsciidoctorModule.java index 1f08d7cef..6a0399b42 100644 --- a/asciidoctorj-core/src/main/java/org/asciidoctor/internal/AsciidoctorModule.java +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/internal/AsciidoctorModule.java @@ -69,7 +69,7 @@ public interface AsciidoctorModule { void docinfo_processor(DocinfoProcessor docInfoClassName, String registrationName); void unregister_all_extensions(); - void unregister_extension(String registrationName); + void unregister_extension(String groupName); Object convert(String content, Map options); Object convertFile(String filename, Map options); diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/internal/ExtensionGroupImpl.java b/asciidoctorj-core/src/main/java/org/asciidoctor/internal/ExtensionGroupImpl.java new file mode 100644 index 000000000..4d7586982 --- /dev/null +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/internal/ExtensionGroupImpl.java @@ -0,0 +1,506 @@ +package org.asciidoctor.internal; + +import org.asciidoctor.extension.BlockMacroProcessor; +import org.asciidoctor.extension.BlockProcessor; +import org.asciidoctor.extension.DocinfoProcessor; +import org.asciidoctor.extension.ExtensionGroup; +import org.asciidoctor.extension.IncludeProcessor; +import org.asciidoctor.extension.InlineMacroProcessor; +import org.asciidoctor.extension.Postprocessor; +import org.asciidoctor.extension.Preprocessor; +import org.asciidoctor.extension.Treeprocessor; +import org.jruby.Ruby; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by robertpanzer on 21.07.17. + */ +public class ExtensionGroupImpl implements ExtensionGroup { + + private final JRubyAsciidoctor asciidoctor; + + private final Ruby rubyRuntime; + + private final AsciidoctorModule asciidoctorModule; + + private final String groupName; + + private final List registrations = new ArrayList(); + + public ExtensionGroupImpl(String groupName, JRubyAsciidoctor asciidoctor) { + this.groupName = groupName; + this.asciidoctor = asciidoctor; + this.rubyRuntime = asciidoctor.getRubyRuntime(); + asciidoctorModule = asciidoctor.getAsciidoctorModule(); + } + + @Override + public void register() { + for (Runnable r: registrations) { + r.run(); + } + } + + @Override + public void unregister() { + asciidoctorModule.unregister_extension(groupName); + } + + @Override + public ExtensionGroup docinfoProcessor(final Class docInfoProcessor) { + registrations.add(new Runnable() { + @Override + public void run() { + javaImport(rubyRuntime, docInfoProcessor); + asciidoctorModule.docinfo_processor(RubyUtils.toRubyClass(rubyRuntime, docInfoProcessor), groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup docinfoProcessor(final DocinfoProcessor docInfoProcessor) { + registrations.add(new Runnable() { + @Override + public void run() { + javaImport(rubyRuntime, docInfoProcessor.getClass()); + asciidoctorModule.docinfo_processor(docInfoProcessor, groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup docinfoProcessor(final String docInfoProcessor) { + registrations.add(new Runnable() { + @Override + public void run() { + javaImport(rubyRuntime, docInfoProcessor); + asciidoctorModule.docinfo_processor(getClassName(docInfoProcessor), groupName); + + } + }); + return this; + } + + @Override + public ExtensionGroup preprocessor(final Class preprocessor) { + registrations.add(new Runnable() { + @Override + public void run() { + javaImport(rubyRuntime, preprocessor); + asciidoctorModule.preprocessor(RubyUtils.toRubyClass(rubyRuntime, preprocessor), groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup preprocessor(final Preprocessor preprocessor) { + registrations.add(new Runnable() { + @Override + public void run() { + javaImport(rubyRuntime, preprocessor.getClass()); + asciidoctorModule.preprocessor(preprocessor, groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup preprocessor(final String preprocessor) { + registrations.add(new Runnable() { + @Override + public void run() { + javaImport(rubyRuntime, preprocessor); + asciidoctorModule.preprocessor(getClassName(preprocessor), groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup postprocessor(final String postprocessor) { + registrations.add(new Runnable() { + @Override + public void run() { + javaImport(rubyRuntime, postprocessor); + asciidoctorModule.postprocessor(getClassName(postprocessor), groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup postprocessor(final Class postprocessor) { + registrations.add(new Runnable() { + @Override + public void run() { + javaImport(rubyRuntime, postprocessor); + asciidoctorModule.postprocessor(RubyUtils.toRubyClass(rubyRuntime, postprocessor), groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup postprocessor(final Postprocessor postprocesor) { + registrations.add(new Runnable() { + @Override + public void run() { + javaImport(rubyRuntime, postprocesor.getClass()); + asciidoctorModule.postprocessor(postprocesor, groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup includeProcessor(final String includeProcessor) { + registrations.add(new Runnable() { + @Override + public void run() { + javaImport(rubyRuntime, includeProcessor); + asciidoctorModule.include_processor(getClassName(includeProcessor), groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup includeProcessor(final Class includeProcessor) { + registrations.add(new Runnable() { + @Override + public void run() { + javaImport(rubyRuntime, includeProcessor); + asciidoctorModule.include_processor(RubyUtils.toRubyClass(rubyRuntime, includeProcessor), groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup includeProcessor(final IncludeProcessor includeProcessor) { + registrations.add(new Runnable() { + @Override + public void run() { + String importLine = getImportLine(includeProcessor.getClass()); + javaImport(rubyRuntime, importLine); + asciidoctorModule.include_processor(includeProcessor, groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup treeprocessor(final Treeprocessor treeprocessor) { + registrations.add(new Runnable() { + @Override + public void run() { + javaImport(rubyRuntime, treeprocessor.getClass()); + asciidoctorModule.treeprocessor(treeprocessor, groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup treeprocessor(final Class treeProcessor) { + registrations.add(new Runnable() { + @Override + public void run() { + javaImport(rubyRuntime, treeProcessor); + asciidoctorModule.treeprocessor(RubyUtils.toRubyClass(rubyRuntime, treeProcessor), groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup treeprocessor(final String treeProcessor) { + registrations.add(new Runnable() { + @Override + public void run() { + javaImport(rubyRuntime, treeProcessor); + asciidoctorModule.treeprocessor(getClassName(treeProcessor), groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup block(final String blockName, final String blockProcessor) { + registrations.add(new Runnable() { + @Override + public void run() { + javaImport(rubyRuntime, blockProcessor); + + asciidoctorModule.block_processor( + getClassName(blockProcessor), + RubyUtils.toSymbol(rubyRuntime, blockName), groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup block(final String blockName, final Class blockProcessor) { + registrations.add(new Runnable() { + @Override + public void run() { + javaImport(rubyRuntime, blockProcessor); + + asciidoctorModule.block_processor( + RubyUtils.toRubyClass(rubyRuntime, blockProcessor), + RubyUtils.toSymbol(rubyRuntime, blockName), groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup block(final BlockProcessor blockProcessor) { + block(blockProcessor.getName(), blockProcessor); + return this; + } + + @Override + public ExtensionGroup block(final String blockName, final BlockProcessor blockProcessor) { + registrations.add(new Runnable() { + @Override + public void run() { + javaImport(rubyRuntime, blockProcessor.getClass()); + + asciidoctorModule.block_processor( + blockProcessor, + RubyUtils.toSymbol(rubyRuntime, blockName), groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup blockMacro(final String blockName, final Class blockMacroProcessor) { + registrations.add(new Runnable() { + @Override + public void run() { + javaImport(rubyRuntime, blockMacroProcessor); + asciidoctorModule.block_macro( + blockMacroProcessor.getSimpleName(), + RubyUtils.toSymbol(rubyRuntime, blockName), groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup blockMacro(final String blockName, final String blockMacroProcessor) { + registrations.add(new Runnable() { + @Override + public void run() { + javaImport(rubyRuntime, blockMacroProcessor); + asciidoctorModule.block_macro( + getClassName(blockMacroProcessor), + RubyUtils.toSymbol(rubyRuntime, blockName), groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup blockMacro(final BlockMacroProcessor blockMacroProcessor) { + registrations.add(new Runnable() { + @Override + public void run() { + javaImport(rubyRuntime, blockMacroProcessor.getClass()); + asciidoctorModule.block_macro( + blockMacroProcessor, + RubyUtils.toSymbol(rubyRuntime, blockMacroProcessor.getName()), groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup inlineMacro(final InlineMacroProcessor inlineMacroProcessor) { + registrations.add(new Runnable() { + @Override + public void run() { + javaImport(rubyRuntime, inlineMacroProcessor.getClass()); + + asciidoctorModule.inline_macro( + inlineMacroProcessor, + RubyUtils.toSymbol(rubyRuntime, inlineMacroProcessor.getName()), groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup inlineMacro(final String blockName, final Class inlineMacroProcessor) { + registrations.add(new Runnable() { + @Override + public void run() { + javaImport(rubyRuntime, inlineMacroProcessor); + + asciidoctorModule.inline_macro( + RubyUtils.toRubyClass(rubyRuntime, inlineMacroProcessor), + RubyUtils.toSymbol(rubyRuntime, blockName), groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup inlineMacro(final String blockName, final String inlineMacroProcessor) { + registrations.add(new Runnable() { + @Override + public void run() { + javaImport(rubyRuntime, inlineMacroProcessor); + + asciidoctorModule.inline_macro( + getClassName(inlineMacroProcessor), + RubyUtils.toSymbol(rubyRuntime, blockName), groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup requireRubyLibrary(final String requiredLibrary) { + registrations.add(new Runnable() { + @Override + public void run() { + RubyUtils.requireLibrary(rubyRuntime, requiredLibrary); + } + }); + return this; + } + + @Override + public ExtensionGroup loadRubyClass(final InputStream rubyClassStream) { + registrations.add(new Runnable() { + @Override + public void run() { + RubyUtils.loadRubyClass(rubyRuntime, rubyClassStream); + } + }); + return this; + } + + @Override + public ExtensionGroup rubyPreprocessor(final String preprocessor) { + registrations.add(new Runnable() { + @Override + public void run() { + asciidoctorModule.preprocessor(preprocessor, groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup rubyPostprocessor(final String postprocessor) { + registrations.add(new Runnable() { + @Override + public void run() { + asciidoctorModule.postprocessor(postprocessor, groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup rubyDocinfoProcessor(final String docinfoProcessor) { + registrations.add(new Runnable() { + @Override + public void run() { + asciidoctorModule.docinfo_processor(docinfoProcessor, groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup rubyIncludeProcessor(final String includeProcessor) { + registrations.add(new Runnable() { + @Override + public void run() { + asciidoctorModule.include_processor(includeProcessor, groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup rubyTreeprocessor(final String treeProcessor) { + registrations.add(new Runnable() { + @Override + public void run() { + asciidoctorModule.treeprocessor(treeProcessor, groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup rubyBlock(final String blockName, final String blockProcessor) { + registrations.add(new Runnable() { + @Override + public void run() { + asciidoctorModule.block_processor( + blockProcessor, RubyUtils.toSymbol(rubyRuntime, blockName), groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup rubyBlockMacro(final String blockName, final String blockMacroProcessor) { + registrations.add(new Runnable() { + @Override + public void run() { + asciidoctorModule.block_macro( + blockMacroProcessor, RubyUtils.toSymbol(rubyRuntime, blockName), groupName); + } + }); + return this; + } + + @Override + public ExtensionGroup rubyInlineMacro(final String blockName, final String inlineMacroProcessor) { + registrations.add(new Runnable() { + @Override + public void run() { + asciidoctorModule.inline_macro( + inlineMacroProcessor, RubyUtils.toSymbol(rubyRuntime, blockName), groupName); + } + }); + return this; + } + + private void javaImport(Ruby ruby, Class clazz) { + ruby.evalScriptlet(String.format("java_import '%s'", getImportLine(clazz))); + } + + private void javaImport(Ruby ruby, String className) { + ruby.evalScriptlet(String.format("java_import '%s'", className)); + } + + private String getImportLine(Class extensionClass) { + int dollarPosition = -1; + String className = extensionClass.getName(); + if ((dollarPosition = className.indexOf("$")) != -1) { + className = className.substring(0, dollarPosition); + } + return className; + } + + private String getClassName(String clazz) { + return clazz.substring(clazz.lastIndexOf(".")+1); + } + +} diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/internal/JRubyAsciidoctor.java b/asciidoctorj-core/src/main/java/org/asciidoctor/internal/JRubyAsciidoctor.java index ed663bc10..8bddb2212 100644 --- a/asciidoctorj-core/src/main/java/org/asciidoctor/internal/JRubyAsciidoctor.java +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/internal/JRubyAsciidoctor.java @@ -14,6 +14,7 @@ import org.asciidoctor.ast.Title; import org.asciidoctor.converter.JavaConverterRegistry; import org.asciidoctor.converter.internal.ConverterRegistryExecutor; +import org.asciidoctor.extension.ExtensionGroup; import org.asciidoctor.extension.JavaExtensionRegistry; import org.asciidoctor.extension.RubyExtensionRegistry; import org.asciidoctor.extension.internal.ExtensionRegistryExecutor; @@ -28,7 +29,6 @@ import java.io.*; import java.util.*; -import java.util.logging.Level; import java.util.logging.Logger; public class JRubyAsciidoctor implements Asciidoctor { @@ -597,6 +597,23 @@ public Document load(String content, Map options) { public Document loadFile(File file, Map options) { RubyHash rubyHash = RubyHashUtil.convertMapToRubyHashWithSymbols(rubyRuntime, options); return new Document(this.asciidoctorModule.load_file(file.getAbsolutePath(), rubyHash), this.rubyRuntime); + } + + Ruby getRubyRuntime() { + return this.rubyRuntime; + } + + AsciidoctorModule getAsciidoctorModule() { + return asciidoctorModule; + } + @Override + public ExtensionGroup createGroup() { + return new ExtensionGroupImpl(UUID.randomUUID().toString(), this); + } + + @Override + public ExtensionGroup createGroup(String groupName) { + return new ExtensionGroupImpl(groupName, this); } } diff --git a/asciidoctorj-core/src/main/resources/org/asciidoctor/internal/asciidoctorclass.rb b/asciidoctorj-core/src/main/resources/org/asciidoctor/internal/asciidoctorclass.rb index 78640d92b..6b06c9787 100644 --- a/asciidoctorj-core/src/main/resources/org/asciidoctor/internal/asciidoctorclass.rb +++ b/asciidoctorj-core/src/main/resources/org/asciidoctor/internal/asciidoctorclass.rb @@ -25,50 +25,50 @@ def unregister_extension name Asciidoctor::Extensions.unregister name end - def docinfo_processor(extensionName, registrationName = nil) - Asciidoctor::Extensions.register (registrationName != nil ? registrationName.to_sym : nil) do + def docinfo_processor(extensionName, groupName = nil) + Asciidoctor::Extensions.register (groupName != nil ? groupName.to_sym : nil) do docinfo_processor extensionName end end - def treeprocessor(extensionName, registrationName = nil) - Asciidoctor::Extensions.register (registrationName != nil ? registrationName.to_sym : nil) do + def treeprocessor(extensionName, groupName = nil) + Asciidoctor::Extensions.register (groupName != nil ? groupName.to_sym : nil) do treeprocessor extensionName end end - def include_processor(extensionName, registrationName = nil) - Asciidoctor::Extensions.register (registrationName != nil ? registrationName.to_sym : nil) do + def include_processor(extensionName, groupName = nil) + Asciidoctor::Extensions.register (groupName != nil ? groupName.to_sym : nil) do include_processor extensionName end end - def preprocessor(extensionName, registrationName = nil) - Asciidoctor::Extensions.register (registrationName != nil ? registrationName.to_sym : nil) do + def preprocessor(extensionName, groupName = nil) + Asciidoctor::Extensions.register (groupName != nil ? groupName.to_sym : nil) do preprocessor extensionName end end - def postprocessor(extensionName, registrationName = nil) - Asciidoctor::Extensions.register (registrationName != nil ? registrationName.to_sym : nil) do + def postprocessor(extensionName, groupName = nil) + Asciidoctor::Extensions.register (groupName != nil ? groupName.to_sym : nil) do postprocessor extensionName end end - def block_processor(extensionName, blockSymbol, registrationName = nil) - Asciidoctor::Extensions.register (registrationName != nil ? registrationName.to_sym : nil) do + def block_processor(extensionName, blockSymbol, groupName = nil) + Asciidoctor::Extensions.register (groupName != nil ? groupName.to_sym : nil) do block extensionName, blockSymbol end end - def block_macro(extensionName, blockSymbol, registrationName = nil) - Asciidoctor::Extensions.register (registrationName != nil ? registrationName.to_sym : nil) do + def block_macro(extensionName, blockSymbol, groupName = nil) + Asciidoctor::Extensions.register (groupName != nil ? groupName.to_sym : nil) do block_macro extensionName, blockSymbol end end - def inline_macro(extensionName, blockSymbol, registrationName = nil) - Asciidoctor::Extensions.register (registrationName != nil ? registrationName.to_sym : nil) do + def inline_macro(extensionName, blockSymbol, groupName = nil) + Asciidoctor::Extensions.register (groupName != nil ? groupName.to_sym : nil) do inline_macro extensionName, blockSymbol end end diff --git a/asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenJavaExtensionIsRegistered.java b/asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenJavaExtensionIsRegistered.java index 08660db17..cd3b7ca08 100644 --- a/asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenJavaExtensionIsRegistered.java +++ b/asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenJavaExtensionIsRegistered.java @@ -1,27 +1,5 @@ package org.asciidoctor.extension; -import static org.asciidoctor.OptionsBuilder.options; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.CoreMatchers.startsWith; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - import org.asciidoctor.Asciidoctor; import org.asciidoctor.AttributesBuilder; import org.asciidoctor.Options; @@ -38,6 +16,28 @@ import org.junit.Test; import org.junit.rules.TemporaryFolder; +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import static org.asciidoctor.OptionsBuilder.options; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.startsWith; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; + public class WhenJavaExtensionIsRegistered { @Rule @@ -705,64 +705,94 @@ public void a_block_processor_instance_should_be_executed_when_registered_block_ public void should_unregister_postprocessor() throws IOException { // Given: A registered Postprocessor - JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); - final String registrationName = UUID.randomUUID().toString(); - javaExtensionRegistry.postprocessor(CustomFooterPostProcessor.class, registrationName); + ExtensionGroup extensionGroup = asciidoctor.createGroup(UUID.randomUUID().toString()) + .postprocessor(CustomFooterPostProcessor.class); - // When: I render a document - Options options = options().inPlace(false).toFile(new File(testFolder.getRoot(), "rendersample.html")) - .safe(SafeMode.UNSAFE).get(); + // When: I render a document without registering the ExtensionGroup + { + Options options = options().inPlace(false).toFile(new File(testFolder.getRoot(), "rendersample.html")) + .safe(SafeMode.UNSAFE).get(); - asciidoctor.renderFile(classpath.getResource("rendersample.asciidoc"), options); + asciidoctor.renderFile(classpath.getResource("rendersample.asciidoc"), options); - // Then: it is invoked - File renderedFile = new File(testFolder.getRoot(), "rendersample.html"); - org.jsoup.nodes.Document doc = Jsoup.parse(renderedFile, "UTF-8"); - Element footer = doc.getElementById("footer-text"); - assertThat(footer.text(), containsString("Copyright Acme, Inc.")); + // Then: it is invoked + File renderedFile = new File(testFolder.getRoot(), "rendersample.html"); + org.jsoup.nodes.Document doc = Jsoup.parse(renderedFile, "UTF-8"); + Element footer = doc.getElementById("footer-text"); + assertThat(footer.text(), not(containsString("Copyright Acme, Inc."))); + } + // When: I register the ExtensionGroup and render a document + { + extensionGroup.register(); + Options options = options().inPlace(false).toFile(new File(testFolder.getRoot(), "rendersample.html")) + .safe(SafeMode.UNSAFE).get(); + + asciidoctor.renderFile(classpath.getResource("rendersample.asciidoc"), options); + + // Then: it is invoked + File renderedFile = new File(testFolder.getRoot(), "rendersample.html"); + org.jsoup.nodes.Document doc = Jsoup.parse(renderedFile, "UTF-8"); + Element footer = doc.getElementById("footer-text"); + assertThat(footer.text(), containsString("Copyright Acme, Inc.")); + } // When: I unregister the Postprocessor and render again with the same Asciidoctor instance - asciidoctor.unregisterExtension(registrationName); + { + extensionGroup.unregister();; - Options options2 = options().inPlace(false).toFile(new File(testFolder.getRoot(), "rendersample2.html")) - .safe(SafeMode.UNSAFE).get(); - asciidoctor.renderFile(classpath.getResource("rendersample.asciidoc"), options2); - File renderedFile2 = new File(testFolder.getRoot(), "rendersample2.html"); - org.jsoup.nodes.Document doc2 = Jsoup.parse(renderedFile2, "UTF-8"); + Options options2 = options().inPlace(false).toFile(new File(testFolder.getRoot(), "rendersample2.html")) + .safe(SafeMode.UNSAFE).get(); + asciidoctor.renderFile(classpath.getResource("rendersample.asciidoc"), options2); + File renderedFile2 = new File(testFolder.getRoot(), "rendersample2.html"); + org.jsoup.nodes.Document doc2 = Jsoup.parse(renderedFile2, "UTF-8"); - Element footer2 = doc2.getElementById("footer-text"); - assertThat(footer2.text(), not(containsString("Copyright Acme, Inc."))); + Element footer2 = doc2.getElementById("footer-text"); + assertThat(footer2.text(), not(containsString("Copyright Acme, Inc."))); + } } @Test public void should_unregister_block_processor() throws IOException { - JavaExtensionRegistry javaExtensionRegistry = this.asciidoctor.javaExtensionRegistry(); - final String registrationName = UUID.randomUUID().toString(); - Map config = new HashMap(); config.put("contexts", Arrays.asList(":paragraph")); config.put("content_model", ":simple"); YellBlock yellBlock = new YellBlock("yell", config); - javaExtensionRegistry.block(yellBlock, registrationName); - String content = asciidoctor.renderFile( - classpath.getResource("sample-with-yell-block.ad"), - options().toFile(false).get()); - Document doc = Jsoup.parse(content, "UTF-8"); - Elements elements = doc.getElementsByClass("paragraph"); - assertThat(elements.size(), is(1)); - assertThat(elements.get(0).text(), is("THE TIME IS NOW. GET A MOVE ON.")); - asciidoctor.unregisterExtension(registrationName); - String contentWithoutBlock = asciidoctor.renderFile( - classpath.getResource("sample-with-yell-block.ad"), - options().toFile(false).get()); - Document docWithoutBlock = Jsoup.parse(contentWithoutBlock, "UTF-8"); - Elements elementsWithoutBlock = docWithoutBlock.getElementsByClass("paragraph"); - assertThat(elementsWithoutBlock.size(), is(1)); - assertThat(elementsWithoutBlock.get(0).text(), not(is("THE TIME IS NOW. GET A MOVE ON."))); + ExtensionGroup extensionGroup = this.asciidoctor.createGroup().block(yellBlock); + { + String contentWithoutBlock = asciidoctor.renderFile( + classpath.getResource("sample-with-yell-block.ad"), + options().toFile(false).get()); + Document docWithoutBlock = Jsoup.parse(contentWithoutBlock, "UTF-8"); + Elements elementsWithoutBlock = docWithoutBlock.getElementsByClass("paragraph"); + assertThat(elementsWithoutBlock.size(), is(1)); + assertThat(elementsWithoutBlock.get(0).text(), not(is("THE TIME IS NOW. GET A MOVE ON."))); + } + + { + extensionGroup.register(); + String content = asciidoctor.renderFile( + classpath.getResource("sample-with-yell-block.ad"), + options().toFile(false).get()); + Document doc = Jsoup.parse(content, "UTF-8"); + Elements elements = doc.getElementsByClass("paragraph"); + assertThat(elements.size(), is(1)); + assertThat(elements.get(0).text(), is("THE TIME IS NOW. GET A MOVE ON.")); + } + + { + extensionGroup.unregister(); + String contentWithoutBlock = asciidoctor.renderFile( + classpath.getResource("sample-with-yell-block.ad"), + options().toFile(false).get()); + Document docWithoutBlock = Jsoup.parse(contentWithoutBlock, "UTF-8"); + Elements elementsWithoutBlock = docWithoutBlock.getElementsByClass("paragraph"); + assertThat(elementsWithoutBlock.size(), is(1)); + assertThat(elementsWithoutBlock.get(0).text(), not(is("THE TIME IS NOW. GET A MOVE ON."))); + } } diff --git a/asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenRubyExtensionIsRegistered.java b/asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenRubyExtensionIsRegistered.java index e9c677f44..b833a16e1 100644 --- a/asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenRubyExtensionIsRegistered.java +++ b/asciidoctorj-core/src/test/java/org/asciidoctor/extension/WhenRubyExtensionIsRegistered.java @@ -1,10 +1,5 @@ package org.asciidoctor.extension; -import static org.asciidoctor.OptionsBuilder.options; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.junit.Assert.assertThat; - import org.asciidoctor.Asciidoctor; import org.asciidoctor.internal.JRubyAsciidoctor; import org.asciidoctor.util.ClasspathResources; @@ -14,7 +9,10 @@ import org.junit.Rule; import org.junit.Test; -import java.util.UUID; +import static org.asciidoctor.OptionsBuilder.options; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.junit.Assert.assertThat; public class WhenRubyExtensionIsRegistered { @@ -43,31 +41,43 @@ public void ruby_extension_should_be_registered() { @Test public void ruby_extension_should_be_unregistered() { - RubyExtensionRegistry rubyExtensionRegistry = this.asciidoctor.rubyExtensionRegistry(); - String registrationName = UUID.randomUUID().toString(); + ExtensionGroup extensionGroup = this.asciidoctor.createGroup() + .loadRubyClass(Class.class.getResourceAsStream("/YellRubyBlock.rb")) + .rubyBlock("rubyyell", "YellRubyBlock"); - rubyExtensionRegistry.loadClass(Class.class.getResourceAsStream("/YellRubyBlock.rb")).block("rubyyell", "YellRubyBlock", registrationName); - - String content = asciidoctor.renderFile( + { + String contentWithoutBlock = asciidoctor.renderFile( classpath.getResource("sample-with-ruby-yell-block.ad"), 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!")); + Document docWithoutBlock = Jsoup.parse(contentWithoutBlock, "UTF-8"); + Elements elementsWithoutBlock = docWithoutBlock.getElementsByClass("paragraph"); + assertThat(elementsWithoutBlock.size(), is(2)); + assertThat(elementsWithoutBlock.get(1).text(), not(is("THE TIME IS NOW! GET A MOVE ON!"))); + } + { + extensionGroup.register(); + String content = asciidoctor.renderFile( + classpath.getResource("sample-with-ruby-yell-block.ad"), + options().toFile(false).get()); - asciidoctor.unregisterExtension(registrationName); + 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!")); + } + { + extensionGroup.unregister(); - String contentWithoutBlock = asciidoctor.renderFile( + String contentWithoutBlock = asciidoctor.renderFile( classpath.getResource("sample-with-ruby-yell-block.ad"), options().toFile(false).get()); - Document docWithoutBlock = Jsoup.parse(contentWithoutBlock, "UTF-8"); - Elements elementsWithoutBlock = docWithoutBlock.getElementsByClass("paragraph"); - assertThat(elementsWithoutBlock.size(), is(2)); - assertThat(elementsWithoutBlock.get(1).text(), not(is("THE TIME IS NOW! GET A MOVE ON!"))); - + Document docWithoutBlock = Jsoup.parse(contentWithoutBlock, "UTF-8"); + Elements elementsWithoutBlock = docWithoutBlock.getElementsByClass("paragraph"); + assertThat(elementsWithoutBlock.size(), is(2)); + assertThat(elementsWithoutBlock.get(1).text(), not(is("THE TIME IS NOW! GET A MOVE ON!"))); + } } } From f4952986c0a0bfcfef37622746f8831b5c08f71d Mon Sep 17 00:00:00 2001 From: Robert Panzer Date: Fri, 28 Jul 2017 09:13:50 +0200 Subject: [PATCH 3/4] Implemented review comments --- .../java/org/asciidoctor/Asciidoctor.java | 6 ------ .../internal/JRubyAsciidoctor.java | 5 ----- .../asciidoctor/internal/asciidoctorclass.rb | 20 +++++++++---------- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/Asciidoctor.java b/asciidoctorj-core/src/main/java/org/asciidoctor/Asciidoctor.java index e00555678..1d539b6db 100644 --- a/asciidoctorj-core/src/main/java/org/asciidoctor/Asciidoctor.java +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/Asciidoctor.java @@ -651,12 +651,6 @@ String[] convertFiles(Collection asciidoctorFiles, */ void unregisterAllExtensions(); - /** - * Unregisters the extension represented by the given registration name. - * @param registrationName - */ - void unregisterExtension(String registrationName); - /** * This method frees all resources consumed by asciidoctorJ module. Keep in mind that if this method is called, instance becomes unusable and you should create another instance. */ diff --git a/asciidoctorj-core/src/main/java/org/asciidoctor/internal/JRubyAsciidoctor.java b/asciidoctorj-core/src/main/java/org/asciidoctor/internal/JRubyAsciidoctor.java index 8bddb2212..b5e9c9f2b 100644 --- a/asciidoctorj-core/src/main/java/org/asciidoctor/internal/JRubyAsciidoctor.java +++ b/asciidoctorj-core/src/main/java/org/asciidoctor/internal/JRubyAsciidoctor.java @@ -497,11 +497,6 @@ public void unregisterAllExtensions() { this.asciidoctorModule.unregister_all_extensions(); } - @Override - public void unregisterExtension(String registrationName) { - this.asciidoctorModule.unregister_extension(registrationName); - } - @Override public void shutdown() { this.rubyRuntime.tearDown(); diff --git a/asciidoctorj-core/src/main/resources/org/asciidoctor/internal/asciidoctorclass.rb b/asciidoctorj-core/src/main/resources/org/asciidoctor/internal/asciidoctorclass.rb index 6b06c9787..fa8573710 100644 --- a/asciidoctorj-core/src/main/resources/org/asciidoctor/internal/asciidoctorclass.rb +++ b/asciidoctorj-core/src/main/resources/org/asciidoctor/internal/asciidoctorclass.rb @@ -4,9 +4,7 @@ module Extensions include_package 'org.asciidoctor.extension' # Treeprocessor was renamed in to TreeProcessor in https://github.com/asciidoctor/asciidoctor/commit/f1dd816ade9db457b899581841e4cf7b788aa26d # This is necessary to run against both Asciidoctor 1.5.5 and 1.5.6 - if !defined? TreeProcessor - TreeProcessor = Treeprocessor - end + TreeProcessor = Treeprocessor unless defined? TreeProcessor end end @@ -26,49 +24,49 @@ def unregister_extension name end def docinfo_processor(extensionName, groupName = nil) - Asciidoctor::Extensions.register (groupName != nil ? groupName.to_sym : nil) do + Asciidoctor::Extensions.register(groupName != nil ? groupName.to_sym : nil) do docinfo_processor extensionName end end def treeprocessor(extensionName, groupName = nil) - Asciidoctor::Extensions.register (groupName != nil ? groupName.to_sym : nil) do + Asciidoctor::Extensions.register(groupName != nil ? groupName.to_sym : nil) do treeprocessor extensionName end end def include_processor(extensionName, groupName = nil) - Asciidoctor::Extensions.register (groupName != nil ? groupName.to_sym : nil) do + Asciidoctor::Extensions.register(groupName != nil ? groupName.to_sym : nil) do include_processor extensionName end end def preprocessor(extensionName, groupName = nil) - Asciidoctor::Extensions.register (groupName != nil ? groupName.to_sym : nil) do + Asciidoctor::Extensions.register(groupName != nil ? groupName.to_sym : nil) do preprocessor extensionName end end def postprocessor(extensionName, groupName = nil) - Asciidoctor::Extensions.register (groupName != nil ? groupName.to_sym : nil) do + Asciidoctor::Extensions.register(groupName != nil ? groupName.to_sym : nil) do postprocessor extensionName end end def block_processor(extensionName, blockSymbol, groupName = nil) - Asciidoctor::Extensions.register (groupName != nil ? groupName.to_sym : nil) do + Asciidoctor::Extensions.register(groupName != nil ? groupName.to_sym : nil) do block extensionName, blockSymbol end end def block_macro(extensionName, blockSymbol, groupName = nil) - Asciidoctor::Extensions.register (groupName != nil ? groupName.to_sym : nil) do + Asciidoctor::Extensions.register(groupName != nil ? groupName.to_sym : nil) do block_macro extensionName, blockSymbol end end def inline_macro(extensionName, blockSymbol, groupName = nil) - Asciidoctor::Extensions.register (groupName != nil ? groupName.to_sym : nil) do + Asciidoctor::Extensions.register(groupName != nil ? groupName.to_sym : nil) do inline_macro extensionName, blockSymbol end end From 13eada6c4e7c970cfa492cbcd1bff0dd43d50b0c Mon Sep 17 00:00:00 2001 From: Robert Panzer Date: Fri, 28 Jul 2017 10:21:22 +0200 Subject: [PATCH 4/4] Remove coercion of extension group names to symbols --- .../org/asciidoctor/internal/asciidoctorclass.rb | 16 ++++++++-------- build.gradle | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/asciidoctorj-core/src/main/resources/org/asciidoctor/internal/asciidoctorclass.rb b/asciidoctorj-core/src/main/resources/org/asciidoctor/internal/asciidoctorclass.rb index fa8573710..f05927e8f 100644 --- a/asciidoctorj-core/src/main/resources/org/asciidoctor/internal/asciidoctorclass.rb +++ b/asciidoctorj-core/src/main/resources/org/asciidoctor/internal/asciidoctorclass.rb @@ -24,49 +24,49 @@ def unregister_extension name end def docinfo_processor(extensionName, groupName = nil) - Asciidoctor::Extensions.register(groupName != nil ? groupName.to_sym : nil) do + Asciidoctor::Extensions.register groupName do docinfo_processor extensionName end end def treeprocessor(extensionName, groupName = nil) - Asciidoctor::Extensions.register(groupName != nil ? groupName.to_sym : nil) do + Asciidoctor::Extensions.register groupName do treeprocessor extensionName end end def include_processor(extensionName, groupName = nil) - Asciidoctor::Extensions.register(groupName != nil ? groupName.to_sym : nil) do + Asciidoctor::Extensions.register groupName do include_processor extensionName end end def preprocessor(extensionName, groupName = nil) - Asciidoctor::Extensions.register(groupName != nil ? groupName.to_sym : nil) do + Asciidoctor::Extensions.register groupName do preprocessor extensionName end end def postprocessor(extensionName, groupName = nil) - Asciidoctor::Extensions.register(groupName != nil ? groupName.to_sym : nil) do + Asciidoctor::Extensions.register groupName do postprocessor extensionName end end def block_processor(extensionName, blockSymbol, groupName = nil) - Asciidoctor::Extensions.register(groupName != nil ? groupName.to_sym : nil) do + Asciidoctor::Extensions.register groupName do block extensionName, blockSymbol end end def block_macro(extensionName, blockSymbol, groupName = nil) - Asciidoctor::Extensions.register(groupName != nil ? groupName.to_sym : nil) do + Asciidoctor::Extensions.register groupName do block_macro extensionName, blockSymbol end end def inline_macro(extensionName, blockSymbol, groupName = nil) - Asciidoctor::Extensions.register(groupName != nil ? groupName.to_sym : nil) do + Asciidoctor::Extensions.register groupName do inline_macro extensionName, blockSymbol end end diff --git a/build.gradle b/build.gradle index 0be572f21..db1682956 100644 --- a/build.gradle +++ b/build.gradle @@ -45,7 +45,7 @@ ext { xmlMatchersVersion = '1.0-RC1' // gem versions - asciidoctorGemVersion = project.hasProperty('asciidoctorGemVersion') ? project.asciidoctorGemVersion : '1.5.6' + asciidoctorGemVersion = project.hasProperty('asciidoctorGemVersion') ? project.asciidoctorGemVersion : '1.5.6.1' asciidoctorEpub3GemVersion = project(':asciidoctorj-epub3').version.replace('-', '.') asciidoctorDiagramGemVersion = project(':asciidoctorj-diagram').version.replace('-', '.')