asciidoctor / asciidoctor-gradle-plugin

A Gradle plugin that uses Asciidoctor via JRuby to process AsciiDoc source files within the project.
https://asciidoctor.github.io/asciidoctor-gradle-plugin/
Apache License 2.0
286 stars 122 forks source link

PlantUML include puml files with diagram description #565

Open pdiefent opened 4 years ago

pdiefent commented 4 years ago

Hello, I'm editing a big assciidoc and I tried to include a PlantULM diagram from an external *.puml file. This is working fine within the IntelliJ-Plugin but the PDF generation doesn't render the diagram in the document. Instead, the souce code of the diagram description appears.

I tried both variants for includeing PlantULS-Descriptions:

plantuml::../puml/InSquence.puml[InSequence,png]

[plantuml, {plantUMLDir}OutOfSequence, png]
----
include::../puml/OutOfSequence.puml[]
----

Any ideas are appreciated, Peter

mojavelinux commented 4 years ago

It sounds to me like you have not enabled the extension. Are you passing the -r asciidoctor-diagram flag when invoking the asciidoctor-pdf command?

pdiefent commented 4 years ago

I'm using a gradle Build and yes, I do not use the flag you are mentioning. To be honest, I'm not sure where to place it in the build commands :(

// common settings for asciidoctor // this is needed for PDF generation with plantUML tasks.withType(AsciidoctorTask) { docTask -> backends = ['pdf']

options doctype: 'book',
        'source-highlighter': 'coderay'

attributes icons: 'font',
        'pdf-stylesdir': project.stylesDir.toString(),
        'pdf-fontsdir': project.fontsDir.toString(),
        'chapter-label': '',
        'docdate': getDate()

// good to see what the build is doing...
logDocuments = true

}

mojavelinux commented 4 years ago

You need two things:

See https://asciidoctor.github.io/asciidoctor-gradle-plugin/development-3.x/user-guide/#diagram

pdiefent commented 4 years ago

All required libraries are on the classpath and all inline plantuml code works well:

[plantuml, {plantUMLDir}CUP-D_Authentifizierung_1, svg]

@startuml actor Nutzer as User order 10 participant Browser order 15 User -> Browser : Log in with username and password @enduml

If I put the code in a external file with puml extension the above mentioned mechanisms do not work. The IntelliJ-AsciiDoc plugin works well also.

The task configuration

asciidoctorj { modules { diagram.use() diagram.version '1.5.16' } }

is not accepted by gradle and produces error messages:

A problem occurred evaluating root project 'Architekturkonzept'.

Could not find method modules() for arguments [build_6frr3tw0crxtpggzh4wo60a9e$_run_closure5$_closure17@35e74dd2] on object of type org.asciidoctor.gradle.AsciidoctorExtension.

ysb33r commented 4 years ago

You can set it globally

asciidoctorj {
    modules {
       diagram.use() 
    }
}

or on the task itself

asciidoctorPdf {
  asciidoctorj {
      modules {
         diagram.use() 
      }
  }
}
pdiefent commented 4 years ago

You can set it globally

asciidoctorj {
    modules {
       diagram.use() 
    }
}

or on the task itself

asciidoctorPdf {
  asciidoctorj {
      modules {
         diagram.use() 
      }
  }
}

that really doesn't help. I'm getting the same error message as before :(

Could not find method modules() for arguments [build_6frr3tw0crxtpggzh4wo60a9e$_run_closure5$_closure17@35e74dd2] on object of type org.asciidoctor.gradle.AsciidoctorExtension.

life888888 commented 2 years ago

My build.gradle

plugins {
  id "org.asciidoctor.jvm.pdf" version "3.3.0"
  id "org.asciidoctor.jvm.gems" version "3.3.0"
}

apply plugin: "java"

version = "0.1.0-SNAPSHOT"

repositories {
    ruby.gems()
    mavenCentral()
}

dependencies {
  asciidoctorGems "rubygems:rouge:3.15.0"
}

asciidoctorPdf {
  dependsOn asciidoctorGemsPrepare

  baseDirFollowsSourceFile()

  asciidoctorj {
     modules {
       asciidoctorj {
         version "2.5.6"
        }
       pdf {
         version "2.3.0"
       }
       diagram {
         version "2.2.3"
       }
     }

    requires "rouge"

    sources { include "project-ext-pml.adoc" }

    options safe: 'unsafe'

    attributes "build-gradle": file("build.gradle"),
        "jrubyVersion": "9.3.8.0",
        "safeMode": "UNSAFE",
        "showtitle": "true",
        "allow-uri-read": "true",
        "source-highlighter": "rouge",
        "icons": "font",
        "imagesdir": "images",
        "experimental": "true"
  }
}

// alias
task asciidoctor(dependsOn: asciidoctorPdf)

My project-ext-pml.adoc

= Plant UML Diagram Demo
:toc: left

== Plant UML Inside

REF https://docs.asciidoctor.org/diagram-extension/latest/ , `Anatomy of a diagram`

REF https://docs.asciidoctor.org/diagram-extension/latest/ ,  `PlantUML Diagram Syntax`

.Plant UML Inside
[plantuml, target=diagram-classes-AAA, format=png]   
....
class BlockProcessorAAA
class DiagramBlock
class DitaaBlock
class PlantUmlBlock

BlockProcessorAAA <|-- DiagramBlock
DiagramBlock <|-- DitaaBlock
DiagramBlock <|-- PlantUmlBlock
....

== Plant UML External File

REF https://docs.asciidoctor.org/diagram-extension/latest/#diagram-macros

**Anatomy of a diagram block macro**

`diagram-type::source-file-name[format=output-format]`

.Plant UML External File
plantuml::project1.pml[target=diagram-classes-ext-project1,format=png]   

My project1.pml

class BlockProcessor
class DiagramBlock
class DitaaBlock
class PlantUmlBlock

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

Run .gradlew clean asciidoctor

build/docs/asciidocPdf
├── images
│   ├── diagram-classes-AAA.png
│   └── diagram-classes-ext-project1.png
└── project-ext-pml.pdf

diagram-classes-AAA.png

diagram-classes-AAA

diagram-classes-ext-project1.png

diagram-classes-ext-project1

project-ext-pml.pdf Page 1

UML1

project-ext-pml.pdf Page 2 - External Plant UML File

UML2

Key point

FAIL project1.pml contains plantuml header , remove it.

[plantuml, target=diagram-classes-AAA, format=png]   
....
class BlockProcessorAAA
class DiagramBlock
class DitaaBlock
class PlantUmlBlock

BlockProcessorAAA <|-- DiagramBlock
DiagramBlock <|-- DitaaBlock
DiagramBlock <|-- PlantUmlBlock
....

TO My project1.pml

class BlockProcessor
class DiagramBlock
class DitaaBlock
class PlantUmlBlock

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

Test Passed.