'process' method in Java block extension not being executed

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

'process' method in Java block extension not being executed

abelsromero
I'm writting a block extension which is basically a rip-off of the Yell example from (https://github.com/asciidoctor/asciidoctorj#block-processor) but I'm not being able to execute it.

The example as-is fails with a ruby exception, and after checking the tests in Asciidoctorj code I see that some additional parameters are passed to the constructor:
        private static Map<String, Object> configs = new HashMap<String, Object>() {{
                put("contexts", Arrays.asList(":paragraph"));
        put("content_model", ":simple");
        }};
This works for a simple Asciidoc file with nothing more than the underlying lines, but does not work in a more complex file.
[yell]
The time is now. Get a move on.
The thing is that when I insert this block in a more complex file, the 'process' method of the extension is not executed. I can validate that the extension is correctly registered to 'yell' debugging the constructor, but the 'process' method is simply never used. Also I tried using ':compound' for 'content_model' but nothing changed.

¿Am I missing something or is it a bug?

Right now I'm testing it with a modified 'sample.asciidoc ' from the maven-plugin tests:

Document Title
==============
Doc Writer <thedoc@asciidoctor.org>
:idprefix: id_

Preamble paragraph.

NOTE: This is test, only a test.

== Section A

*Section A* paragraph.

=== Section A Subsection

*Section A* 'subsection' paragraph.

== Section B

*Section B* paragraph.

.Section B list
* Item 1
* Item 2
* Item 3

== This is an example of an block processor

[yell]
----
The time is now. Get a move on.
----
Reply | Threaded
Open this post in threaded view
|

Re: 'process' method in Java block extension not being executed

mojavelinux
Administrator
Abel,

This happens because you are putting yell on a different type of block than what is registered. In the example, it is only registered on a paragraph. Since you've placed it on a listing block, you have to tell Asciidoctor to register the extension for that block context.

 put("contexts", Arrays.asList(":listing"));

Then, it should work.

In the future, we need to find a simpler way to define the contexts for which a block extension is registered. I proposed an idea in the following issue:

https://github.com/asciidoctor/asciidoctorj/issues/196

Cheers,

-Dan


On Sat, Jan 31, 2015 at 4:37 PM, abelsromero [via Asciidoctor :: Discussion] <[hidden email]> wrote:
I'm writting a block extension which is basically a rip-off of the Yell example from (https://github.com/asciidoctor/asciidoctorj#block-processor) but I'm not being able to execute it.

The example as-is fails with a ruby exception, and after checking the tests in Asciidoctorj code I see that some additional parameters are passed to the constructor:
        private static Map<String, Object> configs = new HashMap<String, Object>() {{
                put("contexts", Arrays.asList(":paragraph"));
        put("content_model", ":simple");
        }};
This works for a simple Asciidoc file with nothing more than the underlying lines, but does not work in a more complex file.
[yell]
The time is now. Get a move on.
The thing is that when I insert this block in a more complex file, the 'process' method of the extension is not executed. I can validate that the extension is correctly registered to 'yell' debugging the constructor, but the 'process' method is simply never used. Also I tried using ':compound' for 'content_model' but nothing changed.

¿Am I missing something or is it a bug?

Right now I'm testing it with a modified 'sample.asciidoc ' from the maven-plugin tests:

Document Title
==============
Doc Writer <[hidden email]>
:idprefix: id_

Preamble paragraph.

NOTE: This is test, only a test.

== Section A

*Section A* paragraph.

=== Section A Subsection

*Section A* 'subsection' paragraph.

== Section B

*Section B* paragraph.

.Section B list
* Item 1
* Item 2
* Item 3

== This is an example of an block processor

[yell]
----
The time is now. Get a move on.
----



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/process-method-in-Java-block-extension-not-being-executed-tp2742.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Reply | Threaded
Open this post in threaded view
|

Re: 'process' method in Java block extension not being executed

abelsromero
Works peftectly, thanks a lot.

Imho, these details should be more documented because currently the documentation is confusing. From the Asciidoctorj and Asciidoctor examples (http://asciidoctor.org/docs/user-manual/#extensions) it seems as is nothing else is necessary, but truth is that you need to set some parameters on the constructors to make them work.

I found this issue https://github.com/asciidoctor/asciidoctor-documentation/issues/30 and I inderstand that the asciidoctor part is on-the-work. So, just to ease Java extensions, mind if I open and issue in asciidoctorj to improve the current examples?

Reply | Threaded
Open this post in threaded view
|

Re: 'process' method in Java block extension not being executed

mojavelinux
Administrator
This is a case when the Ruby and Java environments have very different requirements. In the Ruby side, we use the DSL to configure the blocks, whereas in the Java side its necessary to use the constructor. That's why I like the idea of opening an issue to improve the README for AsciidoctorJ, which currently serves as the "user manual" for that module. Please file the issue when you get a chance.

Thanks!

-Dan

On Sun, Feb 1, 2015 at 1:44 AM, abelsromero [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Works peftectly, thanks a lot.

Imho, these details should be more documented because currently the documentation is confusing. From the Asciidoctorj and Asciidoctor examples (http://asciidoctor.org/docs/user-manual/#extensions) it seems as is nothing else is necessary, but truth is that you need to set some parameters on the constructors to make them work.

I found this issue https://github.com/asciidoctor/asciidoctor-documentation/issues/30 and I inderstand that the asciidoctor part is on-the-work. So, just to ease Java extensions, mind if I open and issue in asciidoctorj to improve the current examples?




If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/process-method-in-Java-block-extension-not-being-executed-tp2742p2744.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--