Calmdevelopment

Keep calm and code. Or do some other stuff.

Updated: 16.10.2016 // <1>

Since version 2.5.0 of jbake it is possible to use asciidoctor-diagram.

This is a little demonstration of how to use this feature with jbake 2.5.0 and an unofficial version of the jbake-gradle-plugin at my private bintray repository.

It’s inspired by a question on the jbake user list.

gradle project configuration

Here is an example of my current gradle build file. See source @github for the full example.

build.gradle used to build this blog
buildscript {
  repositories {
      maven { url "http://dl.bintray.com/calmdev/gradle-plugins" } (1)
      mavenLocal()
      jcenter()
  }

  dependencies {
    classpath 'me.champeau.gradle:jbake-gradle-plugin:0.3.0-alpha.1' (2)
    classpath 'org.asciidoctor:asciidoctorj-diagram:1.5.0' (3)
  }
}

plugins {
    id 'com.github.ben-manes.versions' version '0.14.0'
    id 'org.akhikhl.gretty' version '1.4.0' apply false
    id 'com.craigburke.bower-installer' version '2.5.1'
    id 'distribution'
}

apply plugin: 'me.champeau.jbake'
apply from: 'gradle/distribution.gradle'
apply from: 'gradle/environment.gradle'
apply from: 'gradle/webResources.gradle'

repositories {
  mavenLocal()
  jcenter()
}

if ( env == "local" ){
  apply plugin: 'war'
  apply plugin: 'org.akhikhl.gretty'

  gretty {
    httpPort = config.server.port
    contextPath = config.server.contextPath
    extraResourceBases = [bake.output]
  }
}
else {
  apply from: 'gradle/publish.gradle'
}

jbake{
  version = "2.5.1"
  asciidoctorjVersion = "1.5.4.1"
  configuration['blog.title'] = "calmdevelopment"
  configuration['blog.description'] = "'A personal Blog. Mostly about tech stuff. groovy, gradle, asciidoctor, jbake and other interesting stuff that crosses my path...'"
  configuration['db.store'] = "local"
  configuration['db.path']= "build/cache"
  configuration['site.host'] = config.server.url
  configuration['render.tags'] = true
  configuration['site.contextPath'] = config.server.contextPath
  configuration['foundation.version'] = foundationVersion
  configuration['twitter.user'] = "@knarfancho"
  configuration['asciidoctor.option.requires'] = "asciidoctor-diagram" (4)
  configuration['asciidoctor.attributes'] = [
    "sourceDir=${projectDir}", (5)
    "imagesdir=${config.server.contextPath}img", (6)
    "imagesoutdir=${bake.input}/assets/img", (7)
    "source-highlighter=highlight.js",
    "icons=font"
  ]
  configuration['feed.format'] = "yyyy-MM-dd\'T\'HH:mm:ss\'Z\'"
  configuration['sitemap.format'] = "yyyy-MM-dd"
  configuration['updated.format'] = "dd.MM.yyyy"
}
1 My personal repository at bintray for the jbake-gradle-plugin
2 Add the 0.3.0-alpha.1 version of the plugin to the classpath
3 Add asciidoctorj-diagram 1.5.0 to the classpath
4 Configure asciidoctor to require asciidoctor-diagram
5 Set attribute sourceDir to the projects directory to easyly include source files (like this one). e.g.: include::{sourceDir}/build.gradle
6 The location of the image dir referenced in rendered img-tags. e.g: <img src="/blog/img/asciidoctor-diagram-classes.png" alt="asciidoctor diagram classes" width="270" height="283">
7 The output location for the rendered diagram images

Add a diagram to your document

asciidoctor-diagram supports different diagram types. I use a plantuml block with an example copied from the README :)

A sample plantuml block
 [plantuml, "asciidoctor-diagram-classes", "png"]
 ----
 class BlockProcessor
 class DiagramBlock
 class DitaaBlock
 class PlantUmlBlock

 BlockProcessor <|-- DiagramBlock
 DiagramBlock <|-- DitaaBlock
 DiagramBlock <|-- PlantUmlBlock
 ----

The rendered example

asciidoctor diagram classes

That’s awesome!! :)

2014 - 2017 | Mixed with Foundation v6.2.3 | Baked with JBake v2.5.1