README.adoc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. = Asciidoctor Spring Backends
  2. Alternative HTML conversion for Asciidoctor with a Spring "look and feel".
  3. == Maven build integration
  4. You can use the https://github.com/asciidoctor/asciidoctor-maven-plugin[Asciidoctor Maven plugin] to generate your documentation.
  5. [source,xml]
  6. ----
  7. <plugin>
  8. <groupId>org.asciidoctor</groupId>
  9. <artifactId>asciidoctor-maven-plugin</artifactId>
  10. <version>2.1.0</version>
  11. <executions>
  12. <execution>
  13. <id>generate-html-documentation</id>
  14. <phase>prepare-package</phase>
  15. <goals>
  16. <goal>process-asciidoc</goal>
  17. </goals>
  18. <configuration>
  19. <backend>spring-html</backend>
  20. </configuration>
  21. </execution>
  22. </executions>
  23. <dependencies>
  24. <dependency>
  25. <groupId>io.spring.asciidoctor.backends</groupId>
  26. <artifactId>spring-asciidoctor-backends</artifactId>
  27. <version>${spring-asciidoctor-backends.version}</version>
  28. </dependency>
  29. </dependencies>
  30. </plugin>
  31. ----
  32. You will probably also need to add the Spring Maven repository:
  33. [source,xml]
  34. ----
  35. <repositories>
  36. <repository>
  37. <id>spring-release</id>
  38. <name>Spring Releases</name>
  39. <url>https://repo.spring.io/release</url>
  40. <snapshots>
  41. <enabled>false</enabled>
  42. </snapshots>
  43. </repository>
  44. </repositories>
  45. ----
  46. or for milestones:
  47. [source,xml]
  48. ----
  49. <repositories>
  50. <repository>
  51. <id>spring-milestones</id>
  52. <name>Spring Milestones</name>
  53. <url>https://repo.spring.io/milestone</url>
  54. <snapshots>
  55. <enabled>false</enabled>
  56. </snapshots>
  57. </repository>
  58. </repositories>
  59. ----
  60. == Gradle build integration
  61. You can use the https://asciidoctor.org/docs/asciidoctor-gradle-plugin/[Asciidoctor Gradle plugin] to generate your documentation.
  62. [source,gradle]
  63. ----
  64. plugins {
  65. id 'org.asciidoctor.jvm.convert' version '3.1.0'
  66. }
  67. configurations {
  68. asciidoctorExtensions
  69. }
  70. dependencies {
  71. asciidoctorExtensions "io.spring.asciidoctor.backends:spring-asciidoctor-backends:${spring-asciidoctor-backends.version}"
  72. }
  73. asciidoctor {
  74. configurations "asciidoctorExtensions"
  75. sourceDir "src/asciidoc"
  76. outputOptions {
  77. backends "spring-html"
  78. }
  79. }
  80. ----
  81. You will probably also need to add the Spring Maven repository:
  82. [source,gradle]
  83. ----
  84. repositories {
  85. mavenCentral()
  86. maven {
  87. url "https://repo.spring.io/release"
  88. }
  89. }
  90. ----
  91. or for milestones:
  92. [source,gradle]
  93. ----
  94. repositories {
  95. mavenCentral()
  96. maven {
  97. url "https://repo.spring.io/milestone"
  98. }
  99. }
  100. ----
  101. == Features
  102. === Spring Look and Feel
  103. Spring specific stylesheets and javascript are produced with each HTML file that provides a Spring "look and feel".
  104. As much as possible, styling mirrors the look of https://spring.io[spring.io].
  105. One minor difference between the documentation output and https://spring.io[spring.io] is the choice of fonts.
  106. Since documentation tends to contain more content, we use system default fonts rather than "Metropolis" or "Open Sans".
  107. This aligns with https://markdotto.com/2018/02/07/github-system-fonts/[GitHub's font choice] and tends to produce better results then using a custom font.
  108. === Responsive Design
  109. Generated HTML includes responsive selectors that mean it should work well across a range of devices.
  110. We specifically optimize for desktop, tablet (both horizontal and vertical orientation) and smartphone.
  111. === Graceful Javascript Degradation
  112. Documentation pages generated by this backend should render correctly even if Javascript has been disabled.
  113. Some features will not appear if the user has disabled Javascript.
  114. === "Back to Index" Link
  115. For HTML output, if the current page is not `index.html`, you automatically get a link to `index.html`.
  116. This link appears above the table of contents.
  117. For many projects, this link never appears, because that project's build renders the documentation as `index.html`.
  118. You can customize the destination of the "Back to Index" link by specifying a `index-link` attribute in your document.
  119. For example, the following attribute would link to `https://spring.io`:
  120. [source, asciidoctor]
  121. ----
  122. :index-link: https://spring.io
  123. ----
  124. NOTE: Please do use a link that readers might reasonably think would be an index page.
  125. (The canonical case is the project's page on spring.io.)
  126. === Dark Mode
  127. A "dark mode" switcher is included at the top of each page.
  128. By default the theme will match the users system preferences, but it can be switched easily.
  129. Dark mode settings are saved using local storage so that the user doesn't need to change them on each reload.
  130. === Copy to Clipboard
  131. Code blocks have an additional "Copy to clipboard" button that appears when the user hovers over the block.
  132. The unfolded (see below) version of the code text is always used when copying to the clipboard.
  133. === Tabs
  134. Tab support is included in the site Javascript and can be used without needing the `spring-asciidoctor-extensions-block-switch` extension.
  135. The Javascript post-processes Asciidoctor's HTML output to collapse multiple blocks into one and provides tabs that can be used to switch between them.
  136. To use tabs, one block must have the `role="primary"` attribute, and one or more blocks must have a `role="secondary"` attribute.
  137. The tabs are named using the block titles.
  138. For example:
  139. [source,subs="verbatim,attributes"]
  140. ....
  141. [source,xml,indent=0,role="primary"]
  142. .Maven
  143. ----
  144. <dependency>
  145. <groupId>com.example</groupId>
  146. <artifactId>some-library</artifactId>
  147. <version>1.2.3</version>
  148. </dependency>
  149. ----
  150. [source,indent=0,role="secondary"]
  151. .Gradle
  152. ----
  153. compile 'com.example:some-library:1.2.3'
  154. ----
  155. ....
  156. You can also use blocks for more complex markup:
  157. [source,subs="verbatim,attributes"]
  158. ....
  159. [primary]
  160. .Maven
  161. --
  162. [source,xml,indent=0]
  163. ----
  164. <dependency>
  165. <groupId>com.example</groupId>
  166. <artifactId>some-library</artifactId>
  167. <version>1.2.3</version>
  168. </dependency>
  169. ----
  170. TIP: XML uses angle brackets.
  171. --
  172. [secondary]
  173. .Gradle
  174. --
  175. I can write things here.
  176. [source,indent=0]
  177. ----
  178. compile 'com.example:some-library:1.2.3'
  179. ----
  180. --
  181. ....
  182. === Code Folding
  183. Code folding allows non-pertinent sections of code to be hidden away for the majority of the time.
  184. The user can click on an "unfold code" button if they want to see the full code.
  185. Code folding is particularly useful when code samples have been externalized.
  186. There's often details needed to make the compiler happy that aren't all that relevant to the documentation.
  187. By default, all java imports will be automatically folded.
  188. Additional "fold" sections can also be defined using special `@fold:on` and `@fold:off` comments.
  189. For example, the following Java file will fold-away the fields:
  190. [source,subs="verbatim,attributes"]
  191. ....
  192. [source,java]
  193. ----
  194. public class Example {
  195. // @fold:on
  196. private final String first;
  197. private final String second;
  198. // @fold:off
  199. public Example(String first, String second) {
  200. this.first = first;
  201. this.second = second;
  202. }
  203. }
  204. ----
  205. ....
  206. You can also include replacement text that will be displayed when the code is folded.
  207. For example, the following Java file will show a `+++// getters / setters...+++` comment when the code is folded:
  208. [source,subs="verbatim,attributes"]
  209. ....
  210. [source,java]
  211. ----
  212. public class Example {
  213. private String first;
  214. private String second;
  215. // @fold:on // getters / setters...
  216. public String getFirst() {
  217. return this.first;
  218. }
  219. public void setFirst(String first) {
  220. this.first = first;
  221. }
  222. public String getSecond() {
  223. return this.second;
  224. }
  225. public void setSecond(String second) {
  226. this.second = second;
  227. }
  228. // @fold:off
  229. }
  230. ----
  231. ....
  232. You can use the `fold` attribute if you want change the default settings.
  233. The attribute can be used on the document or the block.
  234. The attribute value is a space delimited list containing one or more of the following flags:
  235. |===
  236. | Flag | Description
  237. | `default`
  238. | `imports` `tags`
  239. | `all`
  240. | Enable all folding
  241. | `none`
  242. | Disable all folding
  243. | `imports`
  244. | Fold import statements
  245. | `tags`
  246. | Fold `@fold:on` / `@fold:off` tags
  247. |===
  248. You can prefix the flag with `+` or `-` at the block level if you want to override a document setting.
  249. === Code Chomping
  250. Code chomping allows specific parts of a Java code block to be removed.
  251. It's mainly useful if you have externalized code files with details that are only required to make the compiler happy.
  252. By default, chomping will remove parts of the code that match specific comments as well as `@formatter:on`/`@formatter:off` comments.
  253. You can also turn on addition chomping for `headers`, `packages`
  254. The following chomp comments are supported:
  255. |===
  256. | Comment | Description
  257. | `/* @chomp:line <replacement> */`
  258. | Chomps the rest of the line and adds the replacement
  259. | `// @chomp:file`
  260. | Chomps the remainder of the file
  261. | `/**/`
  262. | Chomps the rest of the line and adds `+++...+++`
  263. |===
  264. For example, the following file:
  265. [source,subs="verbatim,attributes"]
  266. ....
  267. [source,java]
  268. ----
  269. public class Example {
  270. private final Something something;
  271. private final Other other;
  272. public Example() {
  273. this.something = /**/ new MockSomething();
  274. this.other = /* @chomp:line ... your thing */ new MyThing();
  275. }
  276. }
  277. ----
  278. ....
  279. Will be rendered as:
  280. [source,subs="verbatim,attributes"]
  281. ....
  282. public class Example {
  283. private final Something something;
  284. private final Other other;
  285. public Example() {
  286. this.something = ...
  287. this.other = ... your thing
  288. }
  289. }
  290. ....
  291. You can use the `chomp` attribute if you want change the default settings.
  292. The attribute can be used on the document or the block.
  293. The attribute value is a space delimited list containing one or more of the following flags:
  294. |===
  295. | Flag | Description
  296. | `default`
  297. | `tags` `formatters` `suppresswarnings`
  298. | `all`
  299. | Enable all chomping
  300. | `none`
  301. | Disable all chomping
  302. | `headers`
  303. | Chomp any file headers (up to `package`)
  304. | `packages`
  305. | Chomp the package declaration or replaces it with `chomp_package_replacement`
  306. | `tags`
  307. | Chomp on the comment tags listed above
  308. | `formatters`
  309. | Chomp any `@formatter:on`/`@formatter:off` comments
  310. | `suppresswarnings`
  311. | Chomp any `@SuppressWarnings` annotations
  312. |===
  313. You can prefix the flag with `+` or `-` at the block level if you want to override a document setting.
  314. The `chomp_package_replacement` attribute can be set on the block or the document if you want to replace the package rather than remove it.
  315. For example, the following document will replace all package declarations with `package com.example;`:
  316. [source,subs="verbatim,attributes"]
  317. ....
  318. = My Document
  319. :chomp_package_replacement: com.example
  320. ....
  321. === Anchor Rewriting
  322. Anchor rewriting can be used if you need to evolve a document and change previously published anchor links.
  323. For example, say you publish a document with the following typo:
  324. [source,asciidoctor]
  325. ----
  326. [[initializzzing]]
  327. == Initializing
  328. This is how to do it.
  329. ----
  330. You then fix the typo and publish a new revision:
  331. [source,asciidoctor]
  332. ----
  333. [[initializing]]
  334. == Initializing
  335. This is how to do it.
  336. ----
  337. You can add a rewrite rule so that any links to `+++https://example.com/doc#initializzzing+++` will be automatically changed to `+++https://example.com/doc#initializing+++`.
  338. To define the rewrite rules, add a `anchor-rewrite.properties` file to your `base_dir` (usually the same directory as your `index.adoc` file).
  339. For example, the following file would be used in the example above:
  340. [source,properties]
  341. .anchor-rewrite.properties
  342. ----
  343. initializzzing=initializing
  344. ----
  345. === Convention Based Code Import
  346. Convention based code imports allows you to quickly import code snippets from package names that are constructed using the section ID.
  347. For example, the following `.adoc` file will try to import the Java file `{docs-java}/my/exampleproject/SomeCode.java`.
  348. [source,subs="verbatim,attributes"]
  349. ....
  350. [[my.example-project]]
  351. == My Example Project
  352. import::code:SomeCode[]
  353. ....
  354. The following languages are supported by convention based imports:
  355. |===
  356. | Language | Root Directory Property | Extension
  357. | Java
  358. | `{docs-java}`
  359. | `.java`
  360. | Kotlin
  361. | `{docs-kotlin}`
  362. | `.kt`
  363. | Groovy
  364. | `{docs-groovy}`
  365. | `.grovy`
  366. |===
  367. If more than one language file is found then tabs will automatically be created to allow the user to see all the examples.
  368. An exception will be raised if no files are found.
  369. The package name is constructed by removing all `-` characters from the section ID and replacing all `.`'s with `/`.
  370. == Contributing
  371. If you're looking to contribute to this project, or you're just trying to navigate the code please take a look at the link:CONTRIBUTING.adoc[CONTRIBUTING] file.
  372. == License
  373. With the exception of link:src/main/css/asciidoctor.css[`asciidoctor.css`], use of this software is granted under the terms of the https://www.apache.org/licenses/LICENSE-2.0[Apache License, Version 2.0] (Apache-2.0).
  374. See link:LICENSE.txt[] to find the full license text.
  375. The contents of link:src/main/css/asciidoctor.css[`src/main/css/asciidoctor.css`] have been derived from https://gitlab.com/antora/antora-ui-default/-/blob/8751b86b76d6779fbbcf0fccd58fafcf73c49260/src/css/doc.css[gitlab.com/antora/antora-ui-default CSS] and as such use of this file alone is granted under the terms of the https://www.mozilla.org/en-US/MPL/2.0/[Mozilla Public License Version 2.0] (MPL-2.0).