asciidoctor-gradle-plugin icon indicating copy to clipboard operation
asciidoctor-gradle-plugin copied to clipboard

Question: Dynamic, source-specific attribute value

Open ap0llo opened this issue 1 year ago • 2 comments

Hi,

thanks for your great work on integrating AsciiDoctor with Gradle.

I'm fairly new to the Gradle and AsciiDoctor ecosystems, so please excuse me if this is a trivial question.

I have a repository with multiple .adoc documents which I would like to convert to HTML using Gradle. I would like to a attributes to the asciidcotor build, that is specific to the input document and computed by a different gradle task that runs before asciidoctor

I based my solution on the examples repository.

asciidoctor {
    baseDirFollowsSourceFile()
    sourceDir("docs")
    outputDir("artifacts")

    sources {
        include("document1.adoc")
        include("document2.adoc")
    }
    
    attributes(
        "build-gradle": file("build.gradle"),
        "data-uri": "",
        "my-custom-attribute": "<VALUE>"  // I'd like to calculate "<VALUE>" in a gradle task and the value should be specific to either "document1.adoc" or "document2.adoc"
    )
}

So I guess my question boils down to two aspects:

  • Can the attribute value be made dynamic and use the output of a previous gradle task?
  • Can the attribute value be calculated based on the current document being processed?

I'd be greatly appreciate any pointers on how to achieve this.

ap0llo avatar Jun 05 '23 09:06 ap0llo

If you use 4.x (the alpha versions), then you can use a closure or a provider as the value. It will only be evaluated when the task executes.

ysb33r avatar Jun 05 '23 19:06 ysb33r

Thanks, I'll try that!

ap0llo avatar Jun 06 '23 12:06 ap0llo