Skip to content

tcollignon/asciidoctor-maven-plugin

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

asciidoctor-maven-plugin

Build Status

The asciidoctor-maven-plugin is the official means of using Asciidoctor to render all your AsciiDoc documentation using Apache Maven.

Installation

As this is a typical Maven plugin, there isn’t much to do to use it, simply add it to your plugins section in your pom:

Plugin declaration
...
<plugins>
  <plugin>
    <groupId>org.asciidoctor</groupId>
    <artifactId>asciidoctor-maven-plugin</artifactId>
    <version>${asciidoctor.version}</version>                   (1)
    ...
  </plugin>
</plugins>
...
  1. As this plugin tracks the version of asciidoctor, you can use which every version of asciidoctor you prefer

Usage

Execution setup
...
  <plugin>
    ...
    <executions>
      <execution>
        <id>output-html</id>                                    (1)
        <phase>generate-resources</phase>                       (2)
        <goals>
          <goal>process-asciidoc</goal>                         (3)
        </goals>
      </execution>
    </executions>
    ...
  </plugin>
...
  1. This is simply an unique id for the execution

  2. The asciidoctor-maven-plugin does not run in a specific phase, so one must be specified

  3. The (only for the moment) asciidoctor maven plugin goal

Configuration options

There are several configuration options that the asciidoctor-maven-plugin uses, which parallel the options in Asciidoctor:

sourceDirectory

defaults to ${basedir}/src/main/asciidoc

sourceDocumentName

an override to process a single source file; defaults to all files in ${sourceDirectory}

outputDirectory

defaults to ${project.build.directory}/generated-docs

imagesDir

defaults to images, which will be relative to the directory containing the source files

backend

defaults to docbook

doctype

defaults to article

eruby

defaults to erb, the version used in jruby

headerFooter

defaults to true

compact

defaults to false

templateDir

disabled by default, defaults to null

templateEngine

disabled by default

sourceHighlighter

enables and sets the source highlighter (currently coderay or highlightjs are supported)

attributes

a Map<String,Object> of attributes to pass to Asciidoctor, defaults to null

extensions

a List<String> of non-standard extensions to render. Currently ad, adoc, and asciidoc will be rendered by default.

embedAssets

Embedd the CSS file, etc into the output, defaults to false

Builtin attributes

There are various attributes Asciidoctor recognizes. Below is a list of them and what they do
title

An override for the title of the document.

Note
This one, for backwards compatibility, can still be used in the top level configuration options.

Many other attributes are possible. Until a canonical list is created for asciidoctor, you may find this list to be helpful.

More will be added in the future to take advantage of other options and attributes of Asciidoctor. Any setting in the attributes section that conflicts with an explicitly named attribute configuration will be overidden by the explicitly named attribute configuration. These settings can all be changed in the <configuration> section of the plugin section:

Plugin configuration options
<plugin>
  ...
    </executions>
    <configuration>
      <sourceDirectory>src/main/doc</sourceDirectory>
      <outputDirectory>target/docs</outputDirectory>
      <backend>html</backend>
      <doctype>book</doctype>
      <attributes>
        <stylesheet>my-theme.css</stylesheet>
      </attributes>
    </configuration>
    ...
</plugin>
...

Passing POM properties

It is possible to pass properties defined in the POM to the Asciidoctor processor. This is handy for example to include in the generated document the POM artifact version number.

This is done by creating a custom Asciidoc property in the attributes section of the configuration. The Asciidoc property value is defined in the usual Maven way: ${myMavenProperty}.

<attributes>
    <docVersion>${project.version}</docVersion>
</attributes>

The custom Asciidoc property then be used in the document like this Version: {docVersion}.

Setting boolean values

Boolean attributes in asciidoctor, such as numbered, toc, copycss or linkcss! can be set with a value of true or unset (in the case of linkcss vs linkcss!) with a value of false.

Multiple outputs for the same file

Maven has the ability to execute a Mojo multiple times. Instead of reinventing the wheel inside the Mojo, we’ll push this off to Maven to handle the multiple executions. An example of this setup is below:

Multiple configuration extract
<plugin>
    <groupId>org.asciidoctor</groupId>
    <artifactId>asciidoctor-maven-plugin</artifactId>
    <version>0.1.4</version>
    <executions>
        <execution>
            <id>output-html</id>
            <phase>generate-resources</phase>
            <goals>
                <goal>process-asciidoc</goal>
            </goals>
            <configuration>
                <sourceHighlighter>coderay</sourceHighlighter>
                <backend>html</backend>
                <attributes>
                    <toc/>
                    <linkcss>false</linkcss>
                </attributes>
            </configuration>
        </execution>
        <execution>
            <id>output-docbook</id>
            <phase>generate-resources</phase>
            <goals>
                <goal>process-asciidoc</goal>
            </goals>
            <configuration>
                <backend>docbook</backend>
                <doctype>book</doctype>
            </configuration>
        </execution>
    </executions>
    <configuration>
        <sourceDirectory>src/main/asciidoc</sourceDirectory>
        <headerFooter>true</headerFooter>
        <imagesDir>../resources/images</imagesDir>                  (1)
    </configuration>
</plugin>
  1. imagesDir should be relative to the source directory. It defaults to images but in this example the images used in the docs are also used elsewhere in the project.

Any configuration specified outside the executions section is inherited by each execution. This allows an easier way of defining common configuration options.

Maven Site Integration

To author your Maven-generated site in AsciiDoc, you must first add a dependency on the Asciidoctor plugin to your maven-site-plugin config:

Maven site integration
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-site-plugin</artifactId>
            <version>3.2</version>
            <dependencies>
                <dependency>
                    <groupId>org.asciidoctor</groupId>
                    <artifactId>asciidoctor-maven-plugin</artifactId>
                    <version>${asciidoctor.version}</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

All of your AsciiDoc-based files should be placed in src/site/asciidoc with an extension of .ad.

For example, the file src/site/asciidoc/usage.ad will be rendered into target/site/usage.html.

As always, make sure you add a menu item for each page:

<body>
...
    <menu name="User guide">
        <item href="usage.html" name="Usage" />
    </menu>
...
</body>

Hacking

Developer setup for hacking on this project isn’t very difficult. The requirements are very small:

  • Java

  • Maven 3

Everything else will be brought in by Maven. This is a typical Maven Java project, nothing special. You should be able to use IntelliJ, Eclipse, or Netbeans without any issue for hacking on the project.

Building

Standard Maven build:

mvn clean install

Testing

http://spockframework.org/(Spock) is used for testing the calling of the Mojo. This will be downloaded by Maven. Tests are run simply by:

mvn clean test

Or any of the other goals which run tests. If I can figure out a good way to setup a ruby testing environment I’ll do that as well, but none exists at this time.

About

A Maven plugin that uses Asciidoctor via JRuby to process AsciiDoc source files within the project

Resources

License

Stars

Watchers

Forks

Packages

No packages published