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
285 stars 120 forks source link

Question: Dynamic, source-specific attribute value #676

Open ap0llo opened 1 year ago

ap0llo commented 1 year ago

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:

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

ysb33r commented 1 year ago

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.

ap0llo commented 1 year ago

Thanks, I'll try that!