Skip to content

Commit

Permalink
'terraform-docs#643 - change asciidoc, markdown and pretty template f…
Browse files Browse the repository at this point in the history
…ormats to show the source of the requirements'

Signed-off-by: Edgar R. Sandi <[email protected]>
  • Loading branch information
edgarsandi committed Jul 20, 2023
1 parent 90b9bb9 commit a63b7b7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion format/templates/asciidoc_document_requirements.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

The following requirements are needed by this module:
{{- range .Module.Requirements }}
{{ $source := ternary (tostring .Source) (printf " - %s" .Source) "" }}
{{ $version := ternary (tostring .Version) (printf " (%s)" .Version) "" }}
- {{ anchorNameAsciidoc "requirement" .Name }}{{ $version }}
- {{ anchorNameAsciidoc "requirement" .Name }}{{ $source }}{{ $version }}
{{- end }}
{{ end }}
{{ end -}}
6 changes: 3 additions & 3 deletions format/templates/asciidoc_table_requirements.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
{{ else }}
{{- indent 0 "=" }} Requirements

[cols="a,a",options="header,autowidth"]
[cols="a,a,a",options="header,autowidth"]
|===
|Name |Version
|Name |Source |Version
{{- range .Module.Requirements }}
|{{ anchorNameAsciidoc "requirement" .Name }} |{{ tostring .Version | default "n/a" }}
|{{ anchorNameAsciidoc "requirement" .Name }} |{{ tostring .Source | default "" }} |{{ tostring .Version | default "n/a" }}
{{- end }}
|===
{{ end }}
Expand Down
3 changes: 2 additions & 1 deletion format/templates/markdown_document_requirements.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

The following requirements are needed by this module:
{{- range .Module.Requirements }}
{{ $source := ternary (tostring .Source) (printf " - %s" .Source) "" }}
{{ $version := ternary (tostring .Version) (printf " (%s)" .Version) "" }}
- {{ anchorNameMarkdown "requirement" .Name }}{{ $version }}
- {{ anchorNameMarkdown "requirement" .Name }}{{ $source }}{{ $version }}
{{- end }}
{{ end }}
{{ end -}}
6 changes: 3 additions & 3 deletions format/templates/markdown_table_requirements.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
{{ else }}
{{- indent 0 "#" }} Requirements

| Name | Version |
|------|---------|
| Name | Source | Version |
|------|--------|---------|
{{- range .Module.Requirements }}
| {{ anchorNameMarkdown "requirement" .Name }} | {{ tostring .Version | default "n/a" }} |
| {{ anchorNameMarkdown "requirement" .Name }} | {{ tostring .Source | default "" }} | {{ tostring .Version | default "n/a" }} |
{{- end }}
{{ end }}
{{ end -}}
3 changes: 2 additions & 1 deletion format/templates/pretty.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
{{- if .Config.Sections.Requirements -}}
{{- with .Module.Requirements }}
{{- range . }}
{{- $source := ternary (tostring .Source) (printf " - %s" .Source) "" }}
{{- $version := ternary (tostring .Version) (printf " (%s)" .Version) "" }}
{{- printf "requirement.%s" .Name | colorize "\033[36m" }}{{ $version }}
{{- printf "requirement.%s" .Name | colorize "\033[36m" }}{{ $source }}{{ $version }}
{{ end -}}
{{ end -}}
{{- printf "\n\n" -}}
Expand Down

0 comments on commit a63b7b7

Please sign in to comment.