Use a template engine to produce the documentation snippets
This commit introduces a new TemplateEngine abstraction that is used
to produce the documentation snippets. A default JMustache-based
implementation is provided. JMustache has been repackaged and embedded
to prevent unwanted conflicts and side-effects.
By default, snippet templates are loaded from the classpath in the
org.springframework.restdocs.templates package. Default snippet
templates are provided for all of the snippets that can be generated.
Each of these templates is named after the snippet that it will
produce – the snippet {name}.adoc is produced by the snippet template
default-{name}.snippet. A snippet named {name}.snippet, if present,
will be used in preference to the default snippet, thereby allowing
the default snippets to be overriden.
This commit is contained in:
12
docs/src/docs/asciidoc/customizing-snippets.adoc
Normal file
12
docs/src/docs/asciidoc/customizing-snippets.adoc
Normal file
@@ -0,0 +1,12 @@
|
||||
[[customizing-snippets]]
|
||||
== Customizing the generated snippets
|
||||
|
||||
Spring REST Docs uses https://mustache.github.io[Mustache] templates to produce the
|
||||
generated snippets. You can customize the generated snippets by overriding the
|
||||
{source}spring-restdocs/src/main/resources/org/springframework/restdocs/templates[default
|
||||
templates].
|
||||
|
||||
Templates are loaded from the classpath in the `org.springframework.restdocs.templates`
|
||||
package and each template is named after the snippet that it will produce. For example, to
|
||||
override the template for the `curl-request.adoc` snippet, create a template named
|
||||
`curl-request.snippet` in `src/test/resources/org/springframework/restdocs/templates`.
|
||||
@@ -9,7 +9,9 @@ Andy Wilkinson
|
||||
|
||||
:examples-dir: ../../test/java
|
||||
:github: https://github.com/spring-projects/spring-restdocs
|
||||
:samples: {github}/tree/{branch-or-tag}/samples
|
||||
:source: {github}/tree/{branch-or-tag}/
|
||||
:samples: {source}/samples
|
||||
:templates: {source}/spring-restdocs/src/main/resources/org/springframework/restdocs/templates
|
||||
:spring-boot-docs: http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle
|
||||
:spring-framework-docs: http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle
|
||||
|
||||
@@ -22,6 +24,7 @@ include::introduction.adoc[]
|
||||
include::getting-started.adoc[]
|
||||
include::documenting-your-api.adoc[]
|
||||
include::customizing-responses.adoc[]
|
||||
include::customizing-snippets.adoc[]
|
||||
include::configuration.adoc[]
|
||||
include::working-with-asciidoctor.adoc[]
|
||||
include::contributing.adoc[]
|
||||
@@ -33,8 +33,8 @@ can be used to reference the snippets output directory, for example:
|
||||
=== Customizing tables
|
||||
|
||||
Many of the snippets contain a table in its default configuration. The appearance of the
|
||||
table can be customized by providing some additional configuration when the snippet is
|
||||
included.
|
||||
table can be customized, either by providing some additional configuration when the
|
||||
snippet is included or by using a custom snippet template.
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user