https://github.com/restcomm/asciidoctor-code-samples
https://github.com/restcomm/asciidoctor-code-samples
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/restcomm/asciidoctor-code-samples
- Owner: RestComm
- License: agpl-3.0
- Created: 2019-03-04T07:49:16.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T17:16:30.000Z (over 3 years ago)
- Last Synced: 2025-03-07T01:22:34.636Z (over 1 year ago)
- Language: JavaScript
- Size: 901 KB
- Stars: 0
- Watchers: 20
- Forks: 1
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# asciidoctor-code-samples
[Asciidoctor.js](https://asciidoctor.org/docs/asciidoctor.js/) extension that allows to easily add tabbed source code samples in various programming languages for API documentation written in Asciidoctor (this means it also works with [Antora](https://antora.org/)). The extension exposes a new block macro that allows usages like the following:
##### 1. Asciidoctor code for HTTP GET API example:
```
samplecode::sms[httpMethod="GET",urlSuffix="Accounts/#(account_sid)/SMS/Messages.json"]
```
Rendered HTML:

##### 2. Asciidoctor code for HTTP POST API example:
```
samplecode::sms[httpMethod="POST",urlSuffix="Accounts/#(account_sid)/SMS/Messages.json",bodyParameters="From=19876543212&To=13216549878&Body=Test SMS from Restcomm&StatusCallback=http://status.callback.url"]
```
Rendered HTML:

## Quick start
TODO:
## Use from Antora
TODO:
## How to extend the extension to handle more languages
Say for example that you want to support ruby additionally. What you need to do is:
* Create `ruby-template.txt` for GET requests and `nodejs-template-post` for POST requests in src/resources/lang-templates/
* Add normalization logic for the new language in `asciidoctor-code-samples.js:generateSample()`, before template is 'compiled' from es6-template-strings
* Add interpolation logic for the new language in `asciidoctor-code-samples.js:generateSample()` after template is 'compiled' so that any replacements are made before we have additional interpolation
* Add nodejs generated HTML in asciidoctor-code-samples.js:generateSamplesDiv()
* Add test cases to check both GET and POST conversion scenarios in `test/test/js`