asciidoctor / asciidoctor-gradle-plugin

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

Home Page:https://asciidoctor.github.io/asciidoctor-gradle-plugin/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Provide access to the sourceDir value as attribute

jmini opened this issue · comments

Similar to gradle-rootdir, it would be great if the gradle plugin could provide access to the configured sourceDir.

Use case:

Project
├── docs
│   ├── index.adoc
│   └── other
│       └── other.adoc
└── build.gradle

With this configuration in build.gradle:

asciidoctor {
    sourceDir = file('docs')
    outputDir = file('build/docs')
    backends = ['html5']
    //..
    attributes = ['source-highlighter': 'highlightjs',
                  'highlightjs-theme' : 'github-gist',
                  //
                  ]
}

When using highlightjs, the output looks like this:

build/docs/html5/
├── other
│   └── other.html
├── index.html
└── highlight
    ├── highlight.min.js
    └── styles
        └── github-gist.min.css

The value of highlightjsdir depends from the position of the file relatively to the sourceDir value.

The generated output should be:

For index.html:

<link rel="stylesheet" href="highlight/styles/github-gist.min.css">
<script src="highlight/highlight.min.js"></script>

For other/other.html it should be:

<link rel="stylesheet" href=“../highlight/styles/github-gist.min.css">
<script src=“../highlight/highlight.min.js"></script>

It the gradle plugin would provide a gradle-sourcedir attribute with following value (relative path of sourceDir for the docfile being converted):

  • empty string for docs/index.adoc
  • ../ for docs/other/other.adoc

It would be possible to use it like this:

:highlightjsdir: {gradle-sourcedir}highlight

In the mean time, I have solved it with a preprocessor: https://jmini.github.io/asciidoctorj-sourcedir/

Could you solve this with the includedir attribute?

Thank you for your feedback.

I am not sure what you mean with includedir, I just found a reference here:
https://asciidoctor.org/docs/user-manual/#include-resolution


I have something similar to the setup described here in this project: doc-as-code-demo.

Each files "knows" its location because I add following on top of each of my files:

// {root} shoud point to the `docs/` folder:
ifndef::root[]
:root: ../
endif::[]

The root value is equals to the gradle-sourcedir I am describing here in this case.


But my setup goes a little bit further, next to the docs/ folder I also have a publish/ folder that creates the final documents (they pick content from the files docs/ folder).

I run gradle either with sourceDir set to docs/ or to publish/.

Project
├── docs
│   ├── index.adoc
│   └── other
│       └── other.adoc
├── publish
│   ├── overview-guide.adoc
│   └── advanced
│       ├── topic1-guide.adoc
│       └── topic2-guide.adoc
└── build.gradle

And in this case, because of my definition of {root} pointing to the docs/ folder, the gradle-sourcedir value is not the same.

NB: this current approach has also some drawbacks, so I might change it in the future...

Will add this to 2.1.0. The attribute will be called gradle-relative-srcdir

Hi, is it possible to use gradle-relative-srcdir as part of the attributes declared in the asciidoctorj task? In the setup below it does not work but maybe there's some way to do it. Otherwise it imposes to define in all documents highlightjsdir and stylesdir.

attributes = [
        'snippets'          : snippetsDir,
        'source-highlighter': 'highlight.js',
        'highlightjs-theme' : 'gruvbox-dark',
        'highlightjsdir'    : '{gradle-relative-srcdir}/highlight',
        'stylesheet'        : 'asciidark.css',
        'stylesdir'         : '{gradle-relative-srcdir}',
        'linkcss'           : 'true',
        'encoding'          : 'utf-8'
]