mirror of
https://github.com/terraform-docs/terraform-docs.git
synced 2026-03-27 12:58:35 +07:00
Add one extra special variable the `content`:
- `{{ .Module }}`
As opposed to the other variables, which are generated sections based on
a selected formatter, the `{{ .Module }}` variable is just a `struct`
representing a Terraform module.
It can be used to build highly complex and highly customized content:
```yaml
content: |-
## Resources
{{ range .Module.Resources }}
- {{ .GetMode }}.{{ .Spec }} ({{ .Position.Filename }}#{{ .Position.Line }})
{{- end }}
```
Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
86 lines
2.0 KiB
Go
86 lines
2.0 KiB
Go
/*
|
|
Copyright 2021 The terraform-docs Authors.
|
|
|
|
Licensed under the MIT license (the "License"); you may not
|
|
use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at the LICENSE file in
|
|
the root directory of this source tree.
|
|
*/
|
|
|
|
package format
|
|
|
|
import (
|
|
"embed"
|
|
gotemplate "text/template"
|
|
|
|
"github.com/terraform-docs/terraform-docs/print"
|
|
"github.com/terraform-docs/terraform-docs/template"
|
|
"github.com/terraform-docs/terraform-docs/terraform"
|
|
)
|
|
|
|
//go:embed templates/asciidoc_table*.tmpl
|
|
var asciidocTableFS embed.FS
|
|
|
|
// asciidocTable represents AsciiDoc Table format.
|
|
type asciidocTable struct {
|
|
*generator
|
|
|
|
config *print.Config
|
|
template *template.Template
|
|
}
|
|
|
|
// NewAsciidocTable returns new instance of Asciidoc Table.
|
|
func NewAsciidocTable(config *print.Config) Type {
|
|
items := readTemplateItems(asciidocTableFS, "asciidoc_table")
|
|
|
|
config.Settings.Escape = false
|
|
|
|
tt := template.New(config, items...)
|
|
tt.CustomFunc(gotemplate.FuncMap{
|
|
"type": func(t string) string {
|
|
inputType, _ := PrintFencedCodeBlock(t, "")
|
|
return inputType
|
|
},
|
|
"value": func(v string) string {
|
|
var result = "n/a"
|
|
if v != "" {
|
|
result, _ = PrintFencedCodeBlock(v, "")
|
|
}
|
|
return result
|
|
},
|
|
})
|
|
|
|
return &asciidocTable{
|
|
generator: newGenerator(config, true),
|
|
config: config,
|
|
template: tt,
|
|
}
|
|
}
|
|
|
|
// Generate a Terraform module as AsciiDoc tables.
|
|
func (t *asciidocTable) Generate(module *terraform.Module) error {
|
|
err := t.generator.forEach(func(name string) (string, error) {
|
|
rendered, err := t.template.Render(name, module)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return sanitize(rendered), nil
|
|
})
|
|
|
|
t.generator.funcs(withModule(module))
|
|
|
|
return err
|
|
}
|
|
|
|
func init() {
|
|
register(map[string]initializerFn{
|
|
"asciidoc": NewAsciidocTable,
|
|
"asciidoc table": NewAsciidocTable,
|
|
"asciidoc tbl": NewAsciidocTable,
|
|
"adoc": NewAsciidocTable,
|
|
"adoc table": NewAsciidocTable,
|
|
"adoc tbl": NewAsciidocTable,
|
|
})
|
|
}
|