How to generate block for diagram plugin in own plugin?

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

How to generate block for diagram plugin in own plugin?

Ole
I would really like to generate a block like this:
[graphviz, Mini, svg]
....
digraph Mini {
  // rankdir=LR;
  node [shape=Mrecord,style=filled,fillcolor="#00CC00",rank=same];

  doIt [label="doIt\n(DoIt)|{ <in> in| }"] ;

  node [shape=plaintext,style=plain,rank=same];

  "in" -> doIt:in ;
}
....

from my own plugin. Unfortunately the createBlock method isn't documented very good:
return createBlock(parent, "paragraph", content, attributes, new HashMap<>());

Is using
return createBlock(parent, "graphviz", content, attributes, new HashMap<>());
all I have to do?

Thanks in advance, Ole
Reply | Threaded
Open this post in threaded view
|

Re: How to generate block for diagram plugin in own plugin?

mojavelinux
Administrator

On Thu, Nov 6, 2014 at 5:44 AM, Ole [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Is using
return createBlock(parent, "graphviz", content, attributes, new HashMap<>());
all I have to do?

This step only puts a block node named graphviz into the tree, so the name only affects which convert handler is selected. If you want to trigger the Asciidoctor Diagram extension, you have to push the raw AsciiDoc lines onto the reader so that the parser reads them as though they were in the original document. Here's an example in Ruby: https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/master/lib/textql-block.rb#L26

An alternative solution is to delegate to the process method of the Asciidoctor Diagram API. To do that from Java, you'll need an interface to the Ruby code so that you can call its API, similar to how AsciidoctorJ works in general. It might be nice if we could provide this API wrapper out of the box in AsciidoctorJ Diagram. (Here's a rough example of how that looks: https://github.com/opendevise/jruby-embed-demo/blob/master/src/main/java/demo/AsciidoctorJLite.java)

(Another solution is to run a Ruby scriplet to invoke the Asciidoctor Diagram API).

I hope that helps a little ;)

Ole
Reply | Threaded
Open this post in threaded view
|

Re: How to generate block for diagram plugin in own plugin?

Ole

Sadly, its not so easy...


If you want to trigger the Asciidoctor Diagram extension, you have to push the raw AsciiDoc lines onto the reader so that the parser reads them as though they were in the original document. Here's an example in Ruby:  https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/master/lib/textql-block.rb#L26

I can't really read this Ruby example but I think I would need to access a reader via the given parent.

Unfortunately, the parent is an abstract class 'AbstractBlock' in AsciiDoctorJ that doesn't expose any reader. Otherwise this looks like an easy way to go. :-)


An alternative solution is to delegate to the process method of the Asciidoctor Diagram API. To do that from Java, you'll need an interface to the Ruby code so that you can call its API, similar to how AsciidoctorJ works in general. It might be nice if we could provide this API wrapper out of the box in AsciidoctorJ Diagram. (Here's a rough example of how that looks:  https://github.com/opendevise/jruby-embed-demo/blob/master/src/main/java/demo/AsciidoctorJLite.java)

I can read that example but it looks like an exploring expedition on the border between Java and Ruby will be necessary to get this running.

It will be the slightly more performant solution, though.


The first solution seems to be *much* easier to do, if the reader just has to be made accessible via the API.

Thanks for your help so far

Ole
--
Trettlachstr. 34
91301 Forchheim
Tel.: 09191/79 40 838
Mobil: 0171/10 7 90 23

Reply | Threaded
Open this post in threaded view
|

Re: How to generate block for diagram plugin in own plugin?

mojavelinux
Administrator

Ole,

I know this is a tough one, but it's an important use case, so we definitely want to find a way to make it happen.

I think you're right that we should focus on getting solution #1 working. It should definitely be possible if we figure out what modifications, if any, we need to the AsciidoctorJ API.

What would really help us here is if we added a test to AsciidoctorJ for this scenario. Then, we not only get it working, but we can verify it stays working. And that starts with filing an issue. Could you start one in asciidoctor/asciidoctorj?

It would also be a good opportunity to move the asciidoctorj-extensions-lab to the Asciidoctor organization and add this example (or something similar) to it.

Cheers,

-Dan

On Nov 10, 2014 8:44 AM, "Ole [via Asciidoctor :: Discussion]" <[hidden email]> wrote:

Sadly, its not so easy...


If you want to trigger the Asciidoctor Diagram extension, you have to push the raw AsciiDoc lines onto the reader so that the parser reads them as though they were in the original document. Here's an example in Ruby:  https://github.com/asciidoctor/asciidoctor-extensions-lab/blob/master/lib/textql-block.rb#L26

I can't really read this Ruby example but I think I would need to access a reader via the given parent.

Unfortunately, the parent is an abstract class 'AbstractBlock' in AsciiDoctorJ that doesn't expose any reader. Otherwise this looks like an easy way to go. :-)


An alternative solution is to delegate to the process method of the Asciidoctor Diagram API. To do that from Java, you'll need an interface to the Ruby code so that you can call its API, similar to how AsciidoctorJ works in general. It might be nice if we could provide this API wrapper out of the box in AsciidoctorJ Diagram. (Here's a rough example of how that looks:  https://github.com/opendevise/jruby-embed-demo/blob/master/src/main/java/demo/AsciidoctorJLite.java)

I can read that example but it looks like an exploring expedition on the border between Java and Ruby will be necessary to get this running.

It will be the slightly more performant solution, though.


The first solution seems to be *much* easier to do, if the reader just has to be made accessible via the API.

Thanks for your help so far

Ole
--
Trettlachstr. 34
91301 Forchheim
Tel.: 09191/79 40 838
Mobil: 0171/10 7 90 23




If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/How-to-generate-block-for-diagram-plugin-in-own-plugin-tp2439p2447.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML
Ole
Reply | Threaded
Open this post in threaded view
|

Re: How to generate block for diagram plugin in own plugin?

Ole
What would really help us here is if we added a test to AsciidoctorJ for this scenario. Then, we not only get it working, but we can verify it stays working. And that starts with filing an issue. Could you start one in asciidoctor/asciidoctorj?

OK. I opened this issue now:

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

Lets discuss details there.

Best regards,

Ole
--
Trettlachstr. 34
91301 Forchheim
Tel.: 09191/79 40 838
Mobil: 0171/10 7 90 23