Login  Register

Dynamically adding tables to a document using AsciidoctorJ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Dynamically adding tables to a document using AsciidoctorJ?

Dirk Mahler
3 posts
Hi,

I' like to render Asciidoc files to HTML from Java using AsciidoctorJ and I'd like to achieve to add content dynamically.

The concrete use case is that my adoc files contain Cypher (Neo4j) listings with queries and I'd like to add a table after each listing containing the result as tables. Is there any hint how I could achieve this?

Cheers,

Dirk
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Dynamically adding tables to a document using AsciidoctorJ?

Robert.Panzer
70 posts
Hi Dirk,

maybe this example from the AsciidoctorJ 1.6.0 test case can help.
It fetches information from a Rest endpoint and creates a table from it.
(AsciidoctorJ 1.6.0-alpha is a must for this)

The extension:
https://github.com/asciidoctor/asciidoctorj/blob/asciidoctorj-1.6.0/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/GithubContributorsBlockMacro.groovy
The corresponding test case:
https://github.com/asciidoctor/asciidoctorj/blob/asciidoctorj-1.6.0/asciidoctorj-core/src/test/groovy/org/asciidoctor/extension/WhenABlockMacroProcessorCreatesATable.groovy

Best
Robert
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Dynamically adding tables to a document using AsciidoctorJ?

Dirk Mahler
3 posts
Hi Robert,

looks good but I would like to go a bit further... ;-) The block macro requires that the author of the document explicitly needs to reference the macro:

[[myRule]]
[source,cypher,role=concept]
----
MATCH (n) RETURN n
----

jQA::ruleResult[myRule]

I'd like to add transparently a table directly the rule (i.e. listing).

In the meantime I used a Treeprocessor (https://github.com/jqassistant-contrib/jqassistant-asciidoc-report-plugin/blob/master/src/main/java/org/jqassistant/contrib/plugin/asciidocreport/ResultTreePreprocessor.java) which just adds a new block after such a listing. The result looks like this: https://twitter.com/dirkmahler/status/915318753017163778

It works quite well except for the problem that I need to create HTML, the solution is not portable. Do you see a way to solve this?

Cheers and keep up the great work!

Dirk
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Dynamically adding tables to a document using AsciidoctorJ?

Robert.Panzer
70 posts
Hi Dirk,

a Treeprocessor should also work, good idea!

Doesn't it work if you create the table datastructures like the GithubContributorsBlockMacro does?
As far as I can tell it should also render to PDF or DocBook then.

Cheers
Robert
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: Dynamically adding tables to a document using AsciidoctorJ?

Dirk Mahler
3 posts
Hi Robert,

just had a look at the 1.6 APIs and they provide exactly what I need! Any hint when it will be officially be available (just a rough idea)?

Cheers,

Dirk