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

Register a Treeprocessor with Class argument #443

Closed
ggrossetie opened this issue Apr 7, 2016 · 5 comments
Closed

Register a Treeprocessor with Class argument #443

ggrossetie opened this issue Apr 7, 2016 · 5 comments

Comments

@ggrossetie
Copy link
Member

When I register a Treeprocessor with a Class argument, JRuby raises an exception:

Exception in thread "main" org.jruby.exceptions.RaiseException: (NameError) undefined local variable or method `fr' for main:Object
    at RUBY.(root)(<script>:1)

Given the following code:

package fr.edf.distribution.automation.asciidoctor.extension;

import java.util.List;
import java.util.Map;

import org.asciidoctor.ast.AbstractBlock;
import org.asciidoctor.ast.Block;
import org.asciidoctor.ast.Document;
import org.asciidoctor.extension.Preprocessor;
import org.asciidoctor.extension.PreprocessorReader;
import org.asciidoctor.extension.Treeprocessor;

public class LunrTreeprocessor extends Treeprocessor {
  // ...
}
public class LunrExtension implements ExtensionRegistry {

    public void register(Asciidoctor asciidoctor) {
        JavaExtensionRegistry javaExtensionRegistry = asciidoctor.javaExtensionRegistry();
        javaExtensionRegistry.treeprocessor(LunrTreeprocessor.class);
    }
}

If I register LunrTreeprocessor with javaExtensionRegistry.treeprocessor("fr.edf.distribution.automation.asciidoctor.extension.LunrTreeprocessor"); or javaExtensionRegistry.treeprocessor(new LunrTreeprocessor()); this is working fine.

I'm using AsciidoctorJ 1.5.4

@mojavelinux
Copy link
Member

This is the 'ol JRuby only understands certain package prefix problem.

JRuby recognizes the top-level Java packages java, javax, javafx, org, and com. You can also type in a fully qualified class name basically as in Java, for example, java.lang.System or org.abc.def.className ..."

See http://stackoverflow.com/questions/32423423/importing-jar-file-in-ruby-how-to-use-the-class

@robertpanzer
Copy link
Member

That's a bingo! :-)

We already had a similar issue in the past and all extension registration methods were fixed, except for... exactly this one.

@robertpanzer
Copy link
Member

BTW 1.6.0 should not be affected because the handling of extensions is completely different there: The actual processor implementation is never directly passed to JRuby, but generated Ruby proxies instead.

@mojavelinux
Copy link
Member

👍

robertpanzer added a commit that referenced this issue Apr 8, 2016
Fixes #443. Don't fail when registering a treeprocessor with an unusu…
@ggrossetie
Copy link
Member Author

Perfect thanks!
Le 8 avr. 2016 7:23 AM, "Robert Panzer" [email protected] a écrit :

Closed #443 #443 via
2be6bf7
2be6bf7
.


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
#443 (comment)

abelsromero pushed a commit to abelsromero/asciidoctorj that referenced this issue Dec 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants