Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option for tabulating variables #693

Merged
merged 8 commits into from
Jun 1, 2024
Merged

feat: add option for tabulating variables #693

merged 8 commits into from
Jun 1, 2024

Conversation

chipselden
Copy link
Contributor

@chipselden chipselden commented May 9, 2024

Description

Adding an configuration option which will render the Default Variables in a Markdown table rather than in separate sub-headings.

Usage

# .ansibledoctor.yml
template: readme
tabulate_variables: true

Notes

  • The generated table dynamically determines which columns to include (i.e. if there are no variable "types" defined, there will be no Types column.
  • | characters are escaped
  • \n characters are converted into <br> characters
  • The Table of Contents will not contain the list of variables if tabulate_variables is set to true
  • This functionality was not added to the hugo-book template, but can be done so easily

Example

Defaults/main.yml

# defaults/main.yml
# @var join_the_dark_side:description: >
# Join the dark side, we have cookies
# @end
# @var join_the_dark_side:type: boolean
join_the_dark_side: true

# @var lighsaber_color:description: >
# The color of your lightsaber
# Options:
#   * red
#   * blue
#   * green
#   * purple
# @end
# @var lighsaber_color:type: string
lighsaber_color: red

# @var padawans:description: >
# List of padawans to train
# @end
# @var padawans:type: list(string)
padawans: []

Output

Text

| Variable | Default | Description | Type |
| -------- | ------- | ----------- | ---- |
| join_the_dark_side | True | Join the dark side, we have cookies | boolean |
| lighsaber_color | red | The color of your lightsaber<br>Options:<br> * red<br> * blue<br> * green<br> * purple | string |
| padawans | [] | List of padawans to train | list(string) |

Rendered

Variable Default Description Type
join_the_dark_side True Join the dark side, we have cookies boolean
lighsaber_color red The color of your lightsaber
Options:
* red
* blue
* green
* purple
string
padawans [] List of padawans to train list(string)

@chipselden chipselden marked this pull request as draft May 9, 2024 23:34
@chipselden chipselden marked this pull request as ready for review May 9, 2024 23:57
@rottj006
Copy link

rottj006 commented May 10, 2024

Oh that's very compact, and easy to read, @xoxys will you be ok to make that output the default ?

@xoxys
Copy link
Member

xoxys commented May 10, 2024

will you be ok to make that output the default ?

Mhm, I don't think so. That would be an (unnecessary) breaking change for users and quickly become difficult to read (e.g. long var names, descriptions, especially on small screens).

@xoxys
Copy link
Member

xoxys commented May 10, 2024

@chipselden Thanks for your contribution! I'll need some time to look into it.

@chipselden
Copy link
Contributor Author

@xoxys - Thanks, much appreciated!

Copy link
Member

@xoxys xoxys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few small findings so far. Would be cool if we can add it to the hugo-book template as well. We should also add documentation for the new config option.

@chipselden chipselden requested a review from xoxys May 30, 2024 20:25
Copy link
Member

@xoxys xoxys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay, I was on vacation. LGTM

@xoxys xoxys merged commit 4051d29 into thegeeklab:main Jun 1, 2024
5 checks passed
@xoxys
Copy link
Member

xoxys commented Jun 1, 2024

After some more tests, this approach IMO has some real disadvantages, especially if it comes to multiline strings and code blocks e.g. from more complex usage examples. I'll add a hint to the docs.

@chipselden
Copy link
Contributor Author

Much appreciated, and I agree, it's not going to be the cleanest for every case, but could be nice in others. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants