asciidoctor / asciidoctor-maven-plugin

A Maven plugin that uses Asciidoctor via JRuby to process AsciiDoc source files within the project.
http://asciidoctor.org
Apache License 2.0
311 stars 124 forks source link

How to use ditaa blocks with maven #207

Open indigo423 opened 8 years ago

indigo423 commented 8 years ago

When I add a [ditaa] block I get the following warning:

asciidoctor: WARNING: index.adoc: line 17: invalid style for listing block: ditaa

I use the asciidoctor maven plugin, asciidoctorj and asciidoctorjpdf in the following versions:

<asciidoctorVersion>1.5.3</asciidoctorVersion>
<asciidoctorjVersion>1.5.4</asciidoctorjVersion>
<asciidoctorjPdfVersion>1.5.0-alpha.11</asciidoctorjPdfVersion>

Do I miss something to be able to use the asciidoctor-diagram functionality with maven?

Thank you in advance

abelsromero commented 8 years ago

First of all, integration between asciidoctor-diagram and asciidoctor-pdf is in WIP status. It can be done, but requires some hacking. If you want to see the details check https://github.com/asciidoctor/asciidoctor-maven-plugin/issues/196, if not, this is the summary:

  1. You need to add the asciidoctor diagram as extension to the plugins dependency. Here you'll find an example: https://github.com/asciidoctor/asciidoctor-maven-examples/blob/master/asciidoctor-diagram-example/pom.xml#L39-L43
  2. You need to set the imagesdir attribute to the path to witch asciidoctor-diagram generates the images so that the pdf extension can read them. If you are using default values for path settings, you can add this into your attributes section
    <imagesdir>${project.build.directory}/generated-docs/images</imagesdir>

The problem of this is that you cannot integrate other images :% I created an example here https://gist.github.com/abelsromero/bc0b0e1e4b2353de986c

There's a second alternative to solve this limitation, and I think it should work. You can set asciidoctor-diagram to generate the diagrams in the images folder inside the sources directory with this:

<imagesoutdir>${project.basedir}/src/docs/asciidoc/images</imagesoutdir>

Again, this assumes the default paths are used. In this scenario you don't need to set imagesdir. The problem with this is that you will be mixing generated and static resources together. If you are using git, I'd recommend using some naming convention for the diagrams to add them to .gitignore.

indigo423 commented 8 years ago

I'll give it a try in a testing branch. Thank you very much for detailed explanation.

dashorst commented 8 years ago

The problem with the provided answer is that it fails to fix the error. The error message states that ditaa is an invalid style. This means that Asciidoctor doesn't know about how to process the ditaa format.

For this to work you'll need to add the required asciidoctor-diagram gem to the dependency list of the asciidoctor maven plugin:

<plugin>
  <groupId>org.asciidoctor</groupId>
  <artifactId>asciidoctor-maven-plugin</artifactId>
  <version>1.5.3</version>
  <configuration>
    <attributes>
      <graphvizdot>${dot.location}</graphvizdot>
      <imagesdir>${project.build.directory}/generated-docs/images</imagesdir>
    </attributes>
    <doctype>book</doctype>
    <gemPath>${project.build.directory}/gems-provided</gemPath>
    <icons>font</icons>
    <requires>
      <require>asciidoctor-diagram</require>
    </requires>
    <sourceHighlighter>coderay</sourceHighlighter>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>org.asciidoctor</groupId>
      <artifactId>asciidoctorj-pdf</artifactId>
      <version>1.5.0-alpha.11</version>
    </dependency>
    <dependency>
      <groupId>org.asciidoctor</groupId>
      <artifactId>asciidoctorj-diagram</artifactId>
      <version>1.3.1</version>
    </dependency>
    <dependency>
      <groupId>org.jruby</groupId>
      <artifactId>jruby-complete</artifactId>
      <version>${jruby.version}</version>
    </dependency>
  </dependencies>
</plugin>

As for the previously provided answer, that is also correct. You have to point the asciidoctor plugin to the generated images folder (as is done using the <imagesdir> attribute in the example above.

If you also want to use static images from src/main/asciidoc/images folder, you need to copy them prior to running the asciidoctor plugin. This can be done with the maven-resources-plugin:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-resources-plugin</artifactId>
  <version>2.7</version>
  <executions>
    <execution>
      <id>copy-resources</id>
      <phase>initialize</phase>
      <goals>
        <goal>copy-resources</goal>
      </goals>
      <configuration>
        <outputDirectory>${project.build.directory}/generated-docs/images</outputDirectory>
        <resources>
          <resource>
            <directory>src/main/asciidoc/images</directory>
            <filtering>false</filtering>
          </resource>
        </resources>
      </configuration>
    </execution>
  </executions>
</plugin>

With this setup you can use both static images, and generated images using asciidoctor-diagram.