Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to Documentation with Asciidoctor

Introduction to Documentation with Asciidoctor

Berlin Groovy User Group talk

jlstrater

June 15, 2017
Tweet

More Decks by jlstrater

Other Decks in Technology

Transcript

  1. @codeJENNerator Note For Those Viewing Slides Online • Bulleted text

    like this indicates the key points mentioned on a previous slide. They may not have been included in the official presentation. • If this view does not support links, the links will work in the pdf. Click the ‘download pdf’ button on the right.
  2. @codeJENNerator About Me - Working at Zenjob. - Just finished

    a Fulbright Grant to study and research Groovy in Denmark. - I was a senior consultant at Object Partners, Inc. in Minneapolis, MN, USA. - Co-founder of Gr8Ladies and talk about women in the Groovy Community all over the world - Passionate about bring new people into the Groovy community through free introductory workshops called Gr8Workshops.
  3. @codeJENNerator Background • Documentation • Static Sites • Google Docs

    • Github Wiki • Swagger • Asciidoctor • Who’s responsible? • Devs • Product/Project Manager • QA • Other
  4. @codeJENNerator Example AsciiDoc = Gr8Data API Guide
 Jenn Strater;
 :doctype:

    book
 :icons: font
 :source-highlighter: highlightjs
 :toc: left
 :toclevels: 4
 :sectlinks:
 
 [introduction]
 = Introduction
 
 The Gr8Data API is a RESTful web service for aggregating and displaying gender ratios from various companies across the world. This document outlines how to submit data from your company or team and
 how to access the aggregate data.
 
 [[overview-http-verbs]]
 == HTTP verbs
 
 The Gr8Data API tries to adhere as closely as possible to standard HTTP and REST conventions in its use of HTTP verbs.
  5. @codeJENNerator Install buildscript { repositories { jcenter() } dependencies {

    classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.11' } } plugins { id 'org.asciidoctor.convert' version '1.5.3' } 
 asciidoctor { sourceDir = file('src/docs') sources { include 'index.adoc' } backends = ['html','pdf'] outputDir file('build/docs') attributes \ 'source-highlighter': 'coderay', 'toc': '', 'idprefix': '', 'idseparator': '-', 'allow-uri-read': true }
  6. @codeJENNerator src/docs/index.adoc = Introduction to Documentation
 Jenn Strater;
 :doctype: book


    :icons: font
 :source-highlighter: highlightjs
 :toc: left
 :toclevels: 4
 :sectlinks:
 
 [introduction]
 = Introduction
 
 This is an example asciidoc for the purposes of this demo. [[subsection]] == Subsection In addition to main sections, you can have subsections
  7. @codeJENNerator index.adoc == Source Code You can also include source

    code examples like this `Hello World` script: [source,groovy] ---- println 'Hello, World!' ---- You can also reference source code within a project like this: [source,groovy, linenums] ---- include::{sourcedir}/App.groovy[lines=5..7] ----
  8. @codeJENNerator ➜ doc-example git:(master) ✗ ./gradlew asciidoctor -t Continuous build

    is an incubating feature. BUILD SUCCESSFUL in 0s 1 actionable task: 1 up-to-date Waiting for changes to input files of tasks... (ctrl-d to exit) <-------------> 0% WAITING
  9. @codeJENNerator modified: /Users/jstrater/Documents/dev/doc-example/src/docs/index.adoc Change detected, executing build... BUILD SUCCESSFUL in

    3s 1 actionable task: 1 executed Waiting for changes to input files of tasks... (ctrl-d to exit) <-------------> 0% WAITING > IDLE
  10. @codeJENNerator Spring REST Docs Talks • Documenting RESTful Apis -

    SpringOne2GX 2015 Andy Wilkinson • Writing comprehensive and guaranteed up-to-date REST API documentation - SpringOne Platform 2016 Anders Evers • Greach 2017 - A Test-Driven Approaches to Documenting RESTful APIs with Groovy - Greach 2017 Jenn Strater
  11. @codeJENNerator Gradle asciidoctor {
 dependsOn test
 sourceDir = file('src/docs')
 outputDir

    "$projectDir/src/main/resources/public"
 + inputs.dir snippetsDir
 backends 'html5'
 attributes 'source-highlighter' : 'prettify',
 'imagesdir':'images',
 'toc':'left',
 'icons': 'font',
 'setanchors':'true',
 'idprefix':'',
 'idseparator':'-',
 'docinfo1':'true',
 + 'snippets': snippetsDir
 }
  12. @codeJENNerator Add Snippets to AsciiDoc == Errors
 
 Whenever an

    error response (status code >= 400) is returned, the body will contain a JSON object
 that describes the problem. The error object has the following structure:
 
 include::{snippets}/error-example/response-fields.adoc[]
 
 For example, a request that attempts to apply a non-existent tag to a note will produce a
 `400 Bad Request` response:
 
 include::{snippets}/error-example/http-response.adoc[]
 
 [[resources]]
 = Resources
 
 include::resources/example.adoc[]
  13. @codeJENNerator Generated Snippets • curl-request.adoc • http-request.adoc • httpie-request.adoc •

    http-response.adoc • request body • response body • response-fields.adoc • request-parameters.adoc • request-parts.adoc
  14. @codeJENNerator Example Http Response [source,http,options="nowrap"]
 ----
 HTTP/1.1 200 OK
 Content-Type:

    application/json;charset=UTF-8
 Content-Length: 37
 
 {
 "id" : 1,
 "message" : "Hello"
 }
 ----
  15. @codeJENNerator Example Response Fields |===
 |Path|Type|Description
 
 |`id`
 |`Number`
 |The

    greeting's id
 
 |`message`
 |`String`
 |The greeting's message
 
 |===
  16. @codeJENNerator Strategies • Hook in asciidoctor with the gradle build

    task • Run the asciidoctor test separately (but make sure to run AFTER the tests)
  17. @codeJENNerator Publish Docs to Github Pages publish.gradle buildscript {
 repositories

    {
 jcenter()
 }
 
 dependencies {
 classpath 'org.ajoberstar:gradle-git:1.1.0'
 }
 }
 
 apply plugin: 'org.ajoberstar.github-pages'
 
 githubPages {
 repoUri = '[email protected]:jlstrater/groovy-spring-boot-restdocs-example.git'
 pages {
 from(file('build/resources/main/public/html5')) }
 }
  18. @codeJENNerator Publish Docs to Github Pages publish.gradle buildscript {
 repositories

    {
 jcenter()
 }
 
 dependencies {
 classpath 'org.ajoberstar:gradle-git:1.1.0'
 }
 }
 
 apply plugin: 'org.ajoberstar.github-pages'
 
 githubPages {
 repoUri = '[email protected]:jlstrater/groovy-spring-boot-restdocs-example.git'
 pages {
 from(file('build/resources/main/public/html5')) }
 } If you use this method, remember to deploy docs at the same time as the project!
  19. @codeJENNerator One Year Later • Made it to production! :)

    • Team still happy with Spring REST Docs • Other dev teams like to see the examples
  20. @codeJENNerator Read the docs for more on.. • Asciidoc formatting

    • Other Asciidoctor plugins and extensions • Spring REST Docs specifics
  21. @codeJENNerator • Adding Documentation to your Groovy project is easy

    with Asciidoctor and Gradle • Asciidoctor can include [live] code snippets in the docs.
  22. @codeJENNerator • Adding Documentation to your Groovy project is easy

    with Asciidoctor and Gradle • Asciidoctor can include [live] code snippets in the docs. • I still hate writing boilerplate documentation, but at least it’s a little less painful now.
  23. @codeJENNerator Next Steps • Join the Groovy Community on Slack

    groovycommunity.com • Contribute on Github • Join Zenjob!