Skip to content

Commit

Permalink
feat: asyncapi-asciidoctor-template initial conversion from markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
michalmela committed Sep 22, 2020
1 parent d4da349 commit 6b7f6a3
Show file tree
Hide file tree
Showing 26 changed files with 279 additions and 383 deletions.
59 changes: 0 additions & 59 deletions .all-contributorsrc

This file was deleted.

34 changes: 8 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# Markdown template for the AsyncAPI Generator
# Asciidoctor template for the AsyncAPI Generator
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-4-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

Based on https://github.com/asyncapi/markdown-template

## Usage

```
ag asyncapi.yaml @asyncapi/markdown-template -o output
ag asyncapi.yaml @michalmela/asyncapi-asciidoctor-template -o output
```

If you don't have the AsyncAPI Generator installed, you can install it like this:
Expand All @@ -19,31 +21,11 @@ npm install -g @asyncapi/generator
|Name|Description|Required|Default|Example|
|---|---|---|---|---|
|outFilename|The filename of the output file.|No|`asyncapi.md`|`index.md`|
|channelLabel|How you want to call _Channels_ in your output|No|`Channel`|`Topic`|

## Development

1. Make sure you have the latest generator installed `npm install -g @asyncapi/generator`.
1. Modify the template or it's helper functions. Adjust `test/spec/asyncapi.yml` to have more features if needed.
1. Generate output with watcher enables `npm run dev`.
1. Check generated markdown file located in `./test/output/asyncapi.md`.
## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tr>
<td align="center"><a href="http://www.fmvilas.com"><img src="https://avatars3.githubusercontent.com/u/242119?v=4" width="100px;" alt=""/><br /><sub><b>Fran Méndez</b></sub></a><br /><a href="https://github.com/asyncapi/markdown-template/commits?author=fmvilas" title="Code">💻</a> <a href="https://github.com/asyncapi/markdown-template/commits?author=fmvilas" title="Documentation">📖</a> <a href="https://github.com/asyncapi/markdown-template/pulls?q=is%3Apr+reviewed-by%3Afmvilas" title="Reviewed Pull Requests">👀</a> <a href="#ideas-fmvilas" title="Ideas, Planning, & Feedback">🤔</a></td>
<td align="center"><a href="https://resume.github.io/?derberg"><img src="https://avatars1.githubusercontent.com/u/6995927?v=4" width="100px;" alt=""/><br /><sub><b>Lukasz Gornicki</b></sub></a><br /><a href="https://github.com/asyncapi/markdown-template/commits?author=derberg" title="Code">💻</a> <a href="https://github.com/asyncapi/markdown-template/commits?author=derberg" title="Documentation">📖</a> <a href="https://github.com/asyncapi/markdown-template/pulls?q=is%3Apr+reviewed-by%3Aderberg" title="Reviewed Pull Requests">👀</a> <a href="#infra-derberg" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
<td align="center"><a href="https://github.com/ximyro"><img src="https://avatars0.githubusercontent.com/u/1026811?v=4" width="100px;" alt=""/><br /><sub><b>Ilya Buzlov</b></sub></a><br /><a href="https://github.com/asyncapi/markdown-template/commits?author=ximyro" title="Code">💻</a> <a href="https://github.com/asyncapi/markdown-template/issues?q=author%3Aximyro" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://deltaeight.de"><img src="https://avatars1.githubusercontent.com/u/19175262?v=4" width="100px;" alt=""/><br /><sub><b>Julian Rabe</b></sub></a><br /><a href="https://github.com/asyncapi/markdown-template/commits?author=schw4rzlicht" title="Code">💻</a></td>
</tr>
</table>

<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
2. Modify the template or it's helper functions. Adjust `test/spec/asyncapi.yml` to have more features if needed.
3. Generate output with watcher enables `npm run dev`.
4. Check generated markdown file located in `./test/output/asyncapi.md`.
4 changes: 2 additions & 2 deletions filters/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ function isRequired(obj, key) {
filter.isRequired = isRequired;

function acceptedValues(items) {
if (!items) return '<em>Any</em>';
if (!items) return '_Any_';

return items.map(i => `<code>${i}</code>`).join(', ');
return items.map(i => `\`\`\`${i}\`\`\``).join(', ');
};
filter.acceptedValues = acceptedValues;
4 changes: 2 additions & 2 deletions hooks/output-filename.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const fs = require('fs');

module.exports = {
'generate:after': generator => {
if(generator.templateParams.outFilename !== 'asyncapi.md') {
fs.renameSync(`${generator.targetDir}/asyncapi.md`,
if(generator.templateParams.outFilename !== 'asyncapi.adoc') {
fs.renameSync(`${generator.targetDir}/asyncapi.adoc`,
`${generator.targetDir}/${generator.templateParams.outFilename}`);
}
}
Expand Down
25 changes: 16 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
{
"name": "@asyncapi/markdown-template",
"version": "0.10.0",
"description": "Markdown template for the AsyncAPI generator.",
"name": "@michalmela/asyncapi-asciidoctor-template",
"version": "0.0.1",
"description": "Asciidoctor template for the AsyncAPI generator.",
"keywords": [
"asyncapi",
"generator",
"markdown",
"adoc",
"asciidoc",
"asciidoctor",
"template"
],
"author": "Fran Mendez <fmvilas@gmail.com> (fmvilas.com)",
"author": "Michal Mela",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "git+https://github.com/asyncapi/markdown-template.git"
"url": "git+https://github.com/michalmela/asyncapi-asciidoctor-template.git"
},
"bugs": {
"url": "https://github.com/asyncapi/markdown-template/issues"
"url": "https://github.com/michalmela/asyncapi-asciidoctor-template/issues"
},
"homepage": "https://github.com/asyncapi/markdown-template#readme",
"homepage": "https://github.com/michalmela/asyncapi-asciidoctor-template#readme",
"scripts": {
"test": "echo \"No test specified yet\"",
"release": "semantic-release",
Expand Down Expand Up @@ -67,7 +69,12 @@
"parameters": {
"outFilename": {
"description": "The name of the output markdown file",
"default": "asyncapi.md",
"default": "asyncapi.adoc",
"required": false
},
"channelLabel": {
"description": "How you want to label the _Channels_ section (e.g. _Topics_ may make sense for MQTT)",
"default": "Channel",
"required": false
}
}
Expand Down
7 changes: 4 additions & 3 deletions partials/channel.md → partials/channel.adoc
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{% from "./parameters.md" import parameters %}
{% from "./operation.md" import operation %}
{% from "./parameters.adoc" import parameters %}
{% from "./operation.adoc" import operation %}

{% macro channel(chan, channelName) %}

<a name="channel-{{channelName}}"></a>
=== `{{channelName}}`

{% if chan.description() -%}
{{ chan.description() | safe }}
Expand Down
13 changes: 13 additions & 0 deletions partials/channels.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% from "./channel.adoc" import channel %}

{%- if asyncapi.info().ext('x-channel-label') -%}
{%- set channelsLabel = asyncapi.info().ext('x-channel-label') + 's' -%}
{%- else -%}
{%- set channelsLabel = 'Channels' -%}
{%- endif -%}

== {{channelsLabel}}

{% for channelName, chan in asyncapi.channels() -%}
{{ channel(chan, channelName) }}
{% endfor -%}
7 changes: 0 additions & 7 deletions partials/channels.md

This file was deleted.

5 changes: 5 additions & 0 deletions partials/content.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% include "partials/info.adoc" %}

{% if asyncapi.hasChannels() -%}
{% include "partials/channels.adoc" %}
{% endif -%}
5 changes: 0 additions & 5 deletions partials/content.md

This file was deleted.

67 changes: 67 additions & 0 deletions partials/info.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//{% if asyncapi.info().termsOfService() %}
[#termsOfService]
== Terms of service
[{{asyncapi.info().termsOfService()}}]({{asyncapi.info().termsOfService()}})
//{% endif %}
//{% if asyncapi.hasServers() %}

[#servers]
== Servers

[cols=",,",options="header",separator="¦"]
|===
¦URL ¦Protocol ¦Description

//{% for serverName, server in asyncapi.servers() %}
¦{{server.url()}} ¦{{server.protocol()}}{% if server.protocolVersion() %}{{server.protocolVersion()}}{% endif %} ¦ {{server.description() | safe}}

// {% if server.variables() and server.variables()[0] is defined %}
3+a¦
.URL Variables
[%collapsible]
====
[cols=",,,",options="header",]
!===
!Name !Default value !Possible values !Description
// {% for varName, var in server.variables() %}
!{{varName}}
! {%- if var.hasDefaultValue() %}
{{var.defaultValue()}}
{% else %}
_None_
{% endif %}
a! {%- if var.hasAllowedValues() %}
{%- for value in var.allowedValues() -%}
* {{value}}
{%- endfor -%}
{% else %}
_Any_
{% endif -%}
!{{ var.description() | safe }}
// {% endfor %}
!===
====
// {% endif %}



// {% if server.security() %}
3+a¦
.Security Requirements
[%collapsible]
====
[cols=",,,,,",options="header",]
!===
!Type !In !Name !Scheme !Format !Description
// {%- for security in server.security() %}
// {% set def = asyncapi.components().securityScheme(security.json() | keys | head ) %}
!{{def.type()}} !{{def.in()}} !{{def.name()}} !{{def.scheme()}} !{{def.bearerFormat()}} !{{def.description() | markdown2html | safe }}

// {% endfor %}
!===
// {% endif %}
//{%- endfor %}


|===
//{% endif %}
Loading

0 comments on commit 6b7f6a3

Please sign in to comment.