spring-io / spring-doc-resources

Asciidoctor theme for Spring reference documentations
https://spring.io/
Apache License 2.0
40 stars 20 forks source link

Update guide for use with Gradle Kotlin DSL #19

Open AlexCzar opened 5 years ago

AlexCzar commented 5 years ago

Currently only Groovy DSL configuration is present in the gradle-build-integration guide. Since Gradle Kotlin DSL has reached maturity some time ago, it would be beneficial to have configurations for that kind of setup in the guide.

bclozel commented 5 years ago

Which guide are you referring to? This project provides the static resources and theme for Spring référence documentations, not the actual content. If you’re referring to the spring.io getting started guides, there’s a dedicated org for that: https://github.com/spring-guides If you’re thinking about reference docs, this should be opened against the spring project itself.

AlexCzar commented 5 years ago

I'm referring to this: https://github.com/spring-io/spring-doc-resources#gradle-build-integration

AlexCzar commented 5 years ago

Something like this kinda worked for me, still have several problems, but at least something is generated:

tasks {
    register<Sync>("prepareAsciidocBuild") {
        dependsOn(configurations["docs"])

        // copy doc resources
        from(configurations["docs"].map(::zipTree))
        // and doc sources
        from("src/asciidoc/")

        into("$buildDir/asciidoc/assemble")
    }

    withType<AsciidoctorPdfTask> {
        dependsOn("prepareAsciidocBuild")
        // run asciidoctor from that directory
        setSourceDir("$buildDir/asciidoc/assemble")
        sources {
            include("*.adoc")
        }
        logDocuments = true
        options["doctype"] = "book"
        options["eruby"] = "erubis"
        // use provided stylesheet
        attributes["icons"] = "font"
    }

    named<AsciidoctorTask>("asciidoctor") {
        dependsOn("prepareAsciidocBuild")
        // run asciidoctor from that directory
        setSourceDir("$buildDir/asciidoc/assemble")
        sources {
            include("*.adoc")
        }
        resources {
            from(sourceDir) {
                include("images/*", "css/**", "js/**", "favicon.ico")
            }
        }
        logDocuments = true
        options = mapOf(
            "doctype" to "book",
            "eruby" to "erubis"
        )
        attributes = mapOf(
            "docinfo" to "shared",
            "toc2" to "",
            // use provided stylesheet
            "stylesdir" to "css/",
            "stylesheet" to "spring.css",
            "linkcss" to true,
            "icons" to "font",

            // use provided highlighter
            "source-highlighter=highlight.js" to "",
            "highlightjsdir=js/highlight" to "",
            "highlightjs-theme=atom-one-dark-reasonable" to ""
        )
    }
}
ChristianIvicevic commented 4 years ago

Both your sources and resources methods require a type closure since they can't deduce the appropriate types from the byte code. This is what I am using without any errors:

import org.asciidoctor.gradle.AsciidoctorTask

group = "com.reply.comsysto"
version = "1.0-SNAPSHOT"

val docs: Configuration by configurations.creating

plugins {
    id("org.asciidoctor.convert") version "1.5.9.2"
}

repositories {
    maven {
        url = uri("https://repo.spring.io/libs-release-local")
    }
}

dependencies {
    docs("io.spring.docresources:spring-doc-resources:0.1.3.RELEASE@zip")
}

tasks {
    register<Sync>("prepareAsciidocBuild") {
        dependsOn(configurations["docs"])

        // Set working directory
        into("$buildDir")

        into("asciidoc/build") {
            // Copy spring-doc-resources...
            from(configurations["docs"].map(::zipTree)) {
                // Ignore supplied highlight.js since we have our own
                exclude("**/highlight/**")
            }
            // ...and our source files
            from("src/main/asciidoc/")
        }

        into("asciidoc/build") {
            // Overwrite spring-doc-resources with our custom files
            from("src/resources/")
        }
    }

    named<AsciidoctorTask>("asciidoctor") {
        dependsOn("prepareAsciidocBuild")

        sourceDir = file("$buildDir/asciidoc/build")
        sources(delegateClosureOf<PatternSet> {
            include("*.adoc")
            exclude("attributes.adoc")
        })
        resources(delegateClosureOf<CopySpec> {
            from(sourceDir) {
                include("images/*", "css/**", "js/**")
            }
        })
        logDocuments = true
        options = mapOf("doctype" to "book", "eruby" to "erubis")
        attributes = mapOf(
                "docinfo" to "shared",
                "stylesdir" to "css/",
                "stylesheet" to "spring.css",
                "linkcss" to true,
                "icons" to "font",
                "source-highlighter" to "highlight.js",
                "highlightjsdir" to "js/highlight",
                "highlightjs-theme" to "github"
        )
    }
}