Calmdevelopment

Keep calm and code. Or do some other stuff.

Updated: 21.04.2017

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.1.

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 {
      mavenLocal()
      jcenter()
  }

  dependencies {
    classpath 'org.asciidoctor:asciidoctorj-diagram:1.5.0' (2)
  }
}

plugins {
    id 'org.jbake.site' version '1.0.0' (1)
    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 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'
}

afterEvaluate {
println bake.output
}


jbake{
  version = "2.5.1"
  asciidoctorjVersion = "1.5.5"
  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" (3)
  configuration['asciidoctor.attributes'] = [
    "sourceDir=${projectDir}", (4)
    "imagesdir=${config.server.contextPath}img", (5)
    "imagesoutdir=${bake.input}/assets/img", (6)
    "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 Add asciidoctorj-diagram 1.5.0 to the classpath
2 Add the jbake gradle plugin
3 Configure asciidoctor to require asciidoctor-diagram
4 Set attribute sourceDir to the projects directory to easyly include source files (like this one). e.g.: include::{sourceDir}/build.gradle
5 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">
6 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