Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #359. Explicit unregistration of extensions. #564

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions asciidoctorj-core/src/main/java/org/asciidoctor/Asciidoctor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -633,12 +634,23 @@ String[] convertFiles(Collection<File> 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.
*/
void unregisterAllExtensions();

/**
* 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.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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()}.
*
* <p>Example:
* <code><pre>
* ExtensionGroup group = asciidoctor.createGroup();
* group.block(myBlock).preprocessor(mypreprocessor);
*
* // Convert with extensions
* group.register();
* asciidoctor.convert(...);
* group.unregister();
*
* // Convert without extensions
* asciidoctor.convert(...);
* </pre></code></p>
*/
public interface ExtensionGroup {

public void register();

public void unregister();

public ExtensionGroup docinfoProcessor(Class<? extends DocinfoProcessor> docInfoProcessor);
public ExtensionGroup docinfoProcessor(DocinfoProcessor docInfoProcessor);
public ExtensionGroup docinfoProcessor(String docInfoProcessor);

public ExtensionGroup preprocessor(Class<? extends Preprocessor> preprocessor);
public ExtensionGroup preprocessor(Preprocessor preprocessor);
public ExtensionGroup preprocessor(String preprocessor);

public ExtensionGroup postprocessor(String postprocessor);
public ExtensionGroup postprocessor(Class<? extends Postprocessor> postprocessor);
public ExtensionGroup postprocessor(Postprocessor postprocesor);

public ExtensionGroup includeProcessor(String includeProcessor);
public ExtensionGroup includeProcessor(Class<? extends IncludeProcessor> includeProcessor);
public ExtensionGroup includeProcessor(IncludeProcessor includeProcessor);

public ExtensionGroup treeprocessor(Treeprocessor treeprocessor);
public ExtensionGroup treeprocessor(Class<? extends Treeprocessor> treeProcessor);
public ExtensionGroup treeprocessor(String treeProcessor);

public ExtensionGroup block(String blockName, String blockProcessor);
public ExtensionGroup block(String blockName, Class<? extends BlockProcessor> blockProcessor);
public ExtensionGroup block(BlockProcessor blockProcessor);
public ExtensionGroup block(String blockName, BlockProcessor blockProcessor);

public ExtensionGroup blockMacro(String blockName, Class<? extends BlockMacroProcessor> blockMacroProcessor);
public ExtensionGroup blockMacro(String blockName, String blockMacroProcessor);
public ExtensionGroup blockMacro(BlockMacroProcessor blockMacroProcessor);

public ExtensionGroup inlineMacro(InlineMacroProcessor inlineMacroProcessor);
public ExtensionGroup inlineMacro(String blockName, Class<? extends InlineMacroProcessor> 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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
public class RubyExtensionRegistry {

private AsciidoctorModule asciidoctorModule;

private Ruby rubyRuntime;

public RubyExtensionRegistry(AsciidoctorModule asciidoctorModule,
Expand All @@ -33,8 +34,8 @@ public RubyExtensionRegistry preprocessor(String preprocessor) {
return this;
}

public RubyExtensionRegistry postprocessor(String postprocesor) {
this.asciidoctorModule.postprocessor(postprocesor);
public RubyExtensionRegistry postprocessor(String postprocessor) {
this.asciidoctorModule.postprocessor(postprocessor);
return this;
}

Expand Down Expand Up @@ -72,5 +73,4 @@ public RubyExtensionRegistry inlineMacro(String blockName, String inlineMacroPro
inlineMacroProcessor, RubyUtils.toSymbol(rubyRuntime, blockName));
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<BlockMacroProcessor> blockMacroClass, Object blockName);
void block_macro(Class<BlockMacroProcessor> 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 groupName);

Object convert(String content, Map<String, Object> options);
Object convertFile(String filename, Map<String, Object> options);
Expand Down
Loading