Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing parameters to template files in asciidoc

Tags:

asciidoc

I'm generating asciidoc snippets using spring rest docs.

I can include the generated snippets in my doc page. However, I want to define the structure of each secion once in a seperate adoc file, and have a single line for each of those in my index file.

Currently my index.adoc file looks like this:

= My Http Api Docs

= GET /units/:id

== Path Parameters
include::{snippets}/units/get/path-parameters.adoc[]

== Response Fields
include::{snippets}/units/get/response-fields.adoc[]

I want it to be like this instead

index.adoc

= My Http Api Docs

usemytemplates::mytemplate.adoc[method='get', url='units', desc='/units/:id']

mytemplate.adoc

= {method} {desc}

== Path Parameters
include::{snippets}/{url}/{method}/path-parameters.adoc[]

== Response Fields
include::{snippets}/{url}/{method}/response-fields.adoc[]

Anyone know how something like this can be done?

like image 815
ddouglascarr Avatar asked May 18 '16 23:05

ddouglascarr


People also ask

Is AsciiDoc better than Markdown?

The AsciiDoc syntax is more concise than (or at least as concise as) Markdown. At the same time, AsciiDoc offers power and flexibility without requiring the use of HTML or “flavors” for essential syntax such as tables, description lists, admonitions (tips, notes, warnings, etc.) and table of contents.

What is the difference between AsciiDoc and Asciidoctor?

The original processor, named AsciiDoc, is written in Python. A more modern implementation, named Asciidoctor, is written in Ruby.

What is AsciiDoc format?

AsciiDoc is a text document format that was explicitly designed with the needs of publishing in mind, both print and web. It supports all the structural elements necessary for writing notes, documentation, articles, books, ebooks, slideshows, web pages, technical manuals and blogs.

Can GitHub render AsciiDoc?

GitHub uses Asciidoctor in safe mode to render files with the extension . adoc , . ad , and . asciidoc .


1 Answers

I was able to solve this by using the substitution syntax before each include statement.

My index.adoc file looks like this and it works:

:method: get
:url: units
:desc: /utils/:id
include::mytemplate.adoc[]

:method: get
:url: members
:desc: /members/:id
include::mytemplate.adoc[]
like image 150
ddouglascarr Avatar answered Sep 24 '22 05:09

ddouglascarr