org.asciidoctor.extension.InlineMacroProcessor Java Examples

The following examples show how to use org.asciidoctor.extension.InlineMacroProcessor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InlineMacroProcessorProxy.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
public static RubyClass register(final JRubyAsciidoctor asciidoctor, final Class<? extends InlineMacroProcessor> inlineMacroProcessor) {
    RubyClass rubyClass = ProcessorProxyUtil.defineProcessorClass(asciidoctor.getRubyRuntime(), SUPER_CLASS_NAME, new JRubyAsciidoctorObjectAllocator(asciidoctor) {
        @Override
        public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
            return new InlineMacroProcessorProxy(asciidoctor, klazz, inlineMacroProcessor);
        }
    });

    applyAnnotations(inlineMacroProcessor, rubyClass);

    ProcessorProxyUtil.defineAnnotatedMethods(rubyClass, InlineMacroProcessorProxy.class);
    return rubyClass;
}
 
Example #2
Source File: InlineMacroProcessorProxy.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
public static RubyClass register(final JRubyAsciidoctor asciidoctor, final InlineMacroProcessor inlineMacroProcessor) {
    RubyClass rubyClass = ProcessorProxyUtil.defineProcessorClass(asciidoctor.getRubyRuntime(), SUPER_CLASS_NAME, new JRubyAsciidoctorObjectAllocator(asciidoctor) {
        @Override
        public IRubyObject allocate(Ruby runtime, RubyClass klazz) {
            return new InlineMacroProcessorProxy(asciidoctor, klazz, inlineMacroProcessor);
        }
    });

    applyAnnotations(inlineMacroProcessor.getClass(), rubyClass);

    ProcessorProxyUtil.defineAnnotatedMethods(rubyClass, InlineMacroProcessorProxy.class);
    return rubyClass;
}
 
Example #3
Source File: ExtensionGroupImpl.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Override
public ExtensionGroup inlineMacro(final InlineMacroProcessor inlineMacroProcessor) {
  final RubyClass rubyClass = InlineMacroProcessorProxy.register(asciidoctor, inlineMacroProcessor);
  registrators.add(new Registrator() {
    @Override
    public void register(IRubyObject registry) {
      registry.callMethod(rubyRuntime.getCurrentContext(), "inline_macro", new IRubyObject[]{rubyClass, rubyRuntime.newSymbol(inlineMacroProcessor.getName())});
    }
  });
  return this;
}
 
Example #4
Source File: ExtensionGroupImpl.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Override
public ExtensionGroup inlineMacro(final String name, final Class<? extends InlineMacroProcessor> inlineMacroProcessor) {
  final RubyClass rubyClass = InlineMacroProcessorProxy.register(asciidoctor, inlineMacroProcessor);
  registrators.add(new Registrator() {
    @Override
    public void register(IRubyObject registry) {
      registry.callMethod(rubyRuntime.getCurrentContext(), "inline_macro", new IRubyObject[]{rubyClass, rubyRuntime.newSymbol(name)});
    }
  });
  return this;
}
 
Example #5
Source File: ExtensionGroupImpl.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Override
public ExtensionGroup inlineMacro(final Class<? extends InlineMacroProcessor> inlineMacroProcessor) {
  final RubyClass rubyClass = InlineMacroProcessorProxy.register(asciidoctor, inlineMacroProcessor);
  registrators.add(new Registrator() {
    @Override
    public void register(IRubyObject registry) {
      registry.callMethod(rubyRuntime.getCurrentContext(), "inline_macro", new IRubyObject[]{rubyClass, rubyRuntime.newSymbol(AbstractProcessorProxy.getName(inlineMacroProcessor))});
    }
  });
  return this;
}
 
Example #6
Source File: ExtensionGroupImpl.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Override
public ExtensionGroup inlineMacro(final String name, final String inlineMacroProcessor) {
  try {
    Class<? extends InlineMacroProcessor>  inlineMacroProcessorClass = (Class<? extends InlineMacroProcessor>) Class.forName(inlineMacroProcessor);
    return inlineMacro(name, inlineMacroProcessorClass);
  } catch (ClassNotFoundException e) {
    throw new RuntimeException(e);
  }
}
 
Example #7
Source File: ExtensionGroupImpl.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Override
public ExtensionGroup inlineMacro(final String inlineMacroProcessor) {
  try {
    Class<? extends InlineMacroProcessor>  inlineMacroProcessorClass = (Class<? extends InlineMacroProcessor>) Class.forName(inlineMacroProcessor);
    return inlineMacro(inlineMacroProcessorClass);
  } catch (ClassNotFoundException e) {
    throw new RuntimeException(e);
  }
}
 
Example #8
Source File: JavaExtensionRegistryImpl.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Override
public JavaExtensionRegistry inlineMacro(String macroName,
                                         InlineMacroProcessor inlineMacroProcessor) {
    RubyClass rubyClass = InlineMacroProcessorProxy.register(asciidoctor, inlineMacroProcessor);
    getAsciidoctorModule().callMethod("inline_macro", rubyClass, rubyRuntime.newString(macroName));
    return this;
}
 
Example #9
Source File: JavaExtensionRegistryImpl.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Override
public JavaExtensionRegistry inlineMacro(String macroName,
                                         Class<? extends InlineMacroProcessor> inlineMacroProcessor) {
    RubyClass rubyClass = InlineMacroProcessorProxy.register(asciidoctor, inlineMacroProcessor);
    getAsciidoctorModule().callMethod("inline_macro", rubyClass, rubyRuntime.newString(macroName));
    return this;
}
 
Example #10
Source File: JavaExtensionRegistryImpl.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Override
public JavaExtensionRegistry inlineMacro(Class<? extends InlineMacroProcessor> inlineMacroProcessor) {
    String name = getName(inlineMacroProcessor);
    RubyClass rubyClass = InlineMacroProcessorProxy.register(asciidoctor, inlineMacroProcessor);
    getAsciidoctorModule().callMethod("inline_macro", rubyClass, rubyRuntime.newString(name));
    return this;
}
 
Example #11
Source File: JavaExtensionRegistryImpl.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Override
public JavaExtensionRegistry inlineMacro(String macroName, String inlineMacroProcessor) {
    try {
        Class<? extends InlineMacroProcessor> inlineMacroProcessorClass = (Class<? extends InlineMacroProcessor>) Class.forName(inlineMacroProcessor);
        inlineMacro(macroName, inlineMacroProcessorClass);
        return this;
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}
 
Example #12
Source File: JavaExtensionRegistryImpl.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
@Override
public JavaExtensionRegistry inlineMacro(String inlineMacroProcessor) {
    try {
        Class<? extends InlineMacroProcessor> inlineMacroProcessorClass = (Class<? extends InlineMacroProcessor>) Class.forName(inlineMacroProcessor);
        inlineMacro(inlineMacroProcessorClass);
        return this;
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}
 
Example #13
Source File: InlineMacroProcessorProxy.java    From asciidoctorj with Apache License 2.0 4 votes vote down vote up
public InlineMacroProcessorProxy(JRubyAsciidoctor asciidoctor, RubyClass metaClass, Class<? extends InlineMacroProcessor> inlineMacroProcessorClass) {
    super(asciidoctor, metaClass, inlineMacroProcessorClass);
}
 
Example #14
Source File: InlineMacroProcessorProxy.java    From asciidoctorj with Apache License 2.0 4 votes vote down vote up
public InlineMacroProcessorProxy(JRubyAsciidoctor asciidoctor, RubyClass metaClass, InlineMacroProcessor inlineMacroProcessor) {
    super(asciidoctor, metaClass, inlineMacroProcessor);
}
 
Example #15
Source File: JavaExtensionRegistryImpl.java    From asciidoctorj with Apache License 2.0 4 votes vote down vote up
@Override
public JavaExtensionRegistry inlineMacro(InlineMacroProcessor inlineMacroProcessor) {
    RubyClass rubyClass = InlineMacroProcessorProxy.register(asciidoctor, inlineMacroProcessor);
    getAsciidoctorModule().callMethod("inline_macro", rubyClass);
    return this;
}
 
Example #16
Source File: AsciidoctorJExtensionRegistry.java    From asciidoctor-maven-plugin with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void register(String extensionClassName, String blockName) throws MojoExecutionException {

    Class<? extends Processor> clazz;
    try {
        clazz = (Class<Processor>) Class.forName(extensionClassName);
    } catch (ClassCastException cce) {
        // Use RuntimeException to avoid catching, we only want the message in the Mojo
        throw new RuntimeException("'" + extensionClassName + "' is not a valid AsciidoctorJ processor class");
    } catch (ClassNotFoundException e) {
        throw new RuntimeException("'" + extensionClassName + "' not found in classpath");
    }

    // TODO: Replace with direct method calls again as soon as this project compiles against AsciidoctorJ 1.6.0
    if (DocinfoProcessor.class.isAssignableFrom(clazz)) {
        register(javaExtensionRegistry, "docinfoProcessor", clazz);
    } else if (Preprocessor.class.isAssignableFrom(clazz)) {
        register(javaExtensionRegistry, "preprocessor", clazz);
    } else if (Postprocessor.class.isAssignableFrom(clazz)) {
        register(javaExtensionRegistry, "postprocessor", clazz);
    } else if (Treeprocessor.class.isAssignableFrom(clazz)) {
        register(javaExtensionRegistry, "treeprocessor", clazz);
    } else if (BlockProcessor.class.isAssignableFrom(clazz)) {
        if (blockName == null) {
            register(javaExtensionRegistry, "block", clazz);
        } else {
            register(javaExtensionRegistry, "block", blockName, clazz);
        }
    } else if (IncludeProcessor.class.isAssignableFrom(clazz)) {
        register(javaExtensionRegistry, "includeProcessor", clazz);
    } else if (BlockMacroProcessor.class.isAssignableFrom(clazz)) {
        if (blockName == null) {
            register(javaExtensionRegistry, "blockMacro", clazz);
        } else {
            register(javaExtensionRegistry, "blockMacro", blockName, clazz);
        }
    } else if (InlineMacroProcessor.class.isAssignableFrom(clazz)) {
        if (blockName == null) {
            register(javaExtensionRegistry, "inlineMacro", clazz);
        } else {
            register(javaExtensionRegistry, "inlineMacro", blockName, clazz);
        }
    }
}