Login  Register

Re: Maven plugin and extensions

Posted by mojavelinux on May 13, 2015; 12:20am
URL: https://discuss.asciidoctor.org/Maven-plugin-and-extensions-tp3149p3202.html

Sebastien,

You are now bumping into an intersection of several issues, so I'll try to explain it carefully and give you a rope to climb out to daylight.

First, it's important to understand that AsciidoctorJ bundles the necessary gems you need to use Asciidoctor, so you don't need any gems on your system. You don't even need Ruby. In fact, the gems on your system aren't used by default (though there is a way to request that they be used).

When the Maven plugin runs, it uses the gems bundled with AsciidoctorJ. The version of Slim that is bundled with AsciidoctorJ 1.5.2 is Slim 2.0.3. Out of the box, you _can_ use custom Slim templates with this version of Slim. However, you _cannot_ use the set of Slim templates provided at https://github.com/asciidoctor/asciidoctor-backends. Those templates require Slim 2.1.0 or above. The reason they require (and enforce) Slim 2.1.0 or above is because they are using the new "include" feature in Slim to keep the templates DRY.

You have two option to climb out of this hole.

1) You can write your own Slim 2.0-compatible templates. Basically, start from scratch and you'll know when you are using a feature you can't use. You don't need to change anything else, but obviously it is a lot of work to start from scratch :/

Keep in mind that you only need to provide templates for the nodes you are changing. If a template is missing, Asciidoctor will fallback to using the built-in convert handler for that node. This might be the right solution for you since you only need to customize ulist.html.slim.

2) You can force AsciidoctorJ to use a newer version of Slim. This is a more involved setup, but once it's setup, you'll be able to use any Slim templates you want.

To accomplish this, we have to configure Maven to fetch the Slim gem manually, then tell the Asciidoctor Maven plugin to use it. It's similar to what is done to use Asciidoctor Diagram. See <https://github.com/asciidoctor/asciidoctor-maven-examples/blob/master/asciidoctor-diagram-example/pom.xml>.

2a) Add the RubyGems proxy repository to your pom.xml (parent node: project)

<repositories>
    <repository>
        <id>rubygems-proxy-releases</id>
        <name>RubyGems.org Proxy (Releases)</name>
        <url>http://rubygems-proxy.torquebox.org/releases</url>
    </repository>
</repositories>

2b) Add a dependency on the Slim gem (any version you want) (parent node: project)

<dependencies>
    <dependency>
        <groupId>rubygems</groupId>
        <artifactId>slim</artifactId>
        <version>2.1.0</version>
        <scope>provided</scope>
        <type>gem</type>
        <exclusions>
            <exclusion>
                <groupId>rubygems</groupId> 
                <artifactId>tilt</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

2c) Add the gem-maven-plugin to download and extract the Slim gem and its dependencies (parent node: project > build > plugins)

<plugin>
    <groupId>de.saumya.mojo</groupId>
    <artifactId>gem-maven-plugin</artifactId>
    <version>1.0.10</version>
    <configuration>
        <jrubyVersion>1.7.16.1</jrubyVersion>
        <gemHome>${project.build.directory}/gems</gemHome>
        <gemPath>${project.build.directory}/gems</gemPath>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>initialize</goal>
            </goals>
        </execution>
    </executions>
</plugin>

2d) Configure the Asciidoctor Maven plugin to add the path to the extracted gems to the classpath (inside the <configuration> element)

<gemPath>${project.build.directory}/gems-provided</gemPath>

Now the Slim templates from https://github.com/asciidoctor/asciidoctor-backends will just work.

I hope that helps!

Abel, we may want to think about adding a dedicated tutorial to the Maven plugin repository that details how to use your own gems (which covers numerous use cases).

-Dan

p.s. I've filed an issue to upgrade Slim in AsciidoctorJ. See <https://github.com/asciidoctor/asciidoctorj/issues/307>.

On Tue, May 12, 2015 at 4:27 PM, torngat [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hi Dan and abelsromero,

First off, big thanks for such in-depth (and quick!) answers.  It will be my pleasure to contribute examples to the documentation once I get this working.  :)

Dan, I think you're right that playing around with a slim template might best fit my needs.  I've spent the past few hours researching the Slim syntax, putting something together along the lines of your suggestion (trying to add the necessary styles), and then mashing everything together.  However, I cannot manage to get the Asciidoctor plugin to render the document.  When building my project, I get an error saying that HTML5/Slim backend requires Slim > 2.1.0.

----
Failed to parse source, asciidoctor: FAILED: HTML5/Slim backend needs Slim >= 2.1.0!
----

I already have the gems installed, but I'm not sure that locally installed gems are automatically usable when building with maven and running the Asciidoctor plugin.   I tried adding the Slim gem as a runtime dependency to the plugin - no luck.  I also tried specifying a <gemPath> value in the plugin's configuration where I had placed the Slim gem - still no dice.

I feel like I'm this close, but the proverbial cigar is yet to be had.  Any suggestions?

Thanks again for the help!

Sebastien




If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Maven-plugin-and-extensions-tp3149p3201.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--