Move format package from internal to public

Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
This commit is contained in:
Khosrow Moossavi
2021-09-28 14:18:20 -04:00
parent ca8f8333d4
commit 90942f73b8
248 changed files with 62 additions and 17 deletions

View File

@@ -37,7 +37,7 @@ func NewAsciidocDocument(settings *print.Settings) print.Engine {
tt := template.New(settings, items...) tt := template.New(settings, items...)
tt.CustomFunc(gotemplate.FuncMap{ tt.CustomFunc(gotemplate.FuncMap{
"type": func(t string) string { "type": func(t string) string {
result, extraline := printFencedAsciidocCodeBlock(t, "hcl") result, extraline := PrintFencedAsciidocCodeBlock(t, "hcl")
if !extraline { if !extraline {
result += "\n" result += "\n"
} }
@@ -47,7 +47,7 @@ func NewAsciidocDocument(settings *print.Settings) print.Engine {
if v == "n/a" { if v == "n/a" {
return v return v
} }
result, extraline := printFencedAsciidocCodeBlock(v, "json") result, extraline := PrintFencedAsciidocCodeBlock(v, "json")
if !extraline { if !extraline {
result += "\n" result += "\n"
} }

View File

@@ -37,13 +37,13 @@ func NewAsciidocTable(settings *print.Settings) print.Engine {
tt := template.New(settings, items...) tt := template.New(settings, items...)
tt.CustomFunc(gotemplate.FuncMap{ tt.CustomFunc(gotemplate.FuncMap{
"type": func(t string) string { "type": func(t string) string {
inputType, _ := printFencedCodeBlock(t, "") inputType, _ := PrintFencedCodeBlock(t, "")
return inputType return inputType
}, },
"value": func(v string) string { "value": func(v string) string {
var result = "n/a" var result = "n/a"
if v != "" { if v != "" {
result, _ = printFencedCodeBlock(v, "") result, _ = PrintFencedCodeBlock(v, "")
} }
return result return result
}, },

47
format/doc.go Normal file
View File

@@ -0,0 +1,47 @@
/*
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 provides different, out of the box supported, output formats.
//
// Usage
//
// A specific format can be instantiated either for `format.Factory()` function or
// directly calling its function (e.g. `NewMarkdownTable`, etc)
//
// formatter, err := format.Factory("markdown table", settings)
// if err != nil {
// return err
// }
//
// generator, err := formatter.Generate(tfmodule)
// if err != nil {
// return err
// }
//
// output, err := generator.ExecuteTemplate("")
// if err != nil {
// return err
// }
//
// Supported formats are:
//
// • `NewAsciidocDocument`
// • `NewAsciidocTable`
// • `NewJSON`
// • `NewMarkdownDocument`
// • `NewMarkdownTable`
// • `NewPretty`
// • `NewTfvarsHCL`
// • `NewTfvarsJSON`
// • `NewTOML`
// • `NewXML`
// • `NewYAML`
//
package format

View File

@@ -35,7 +35,7 @@ func NewMarkdownDocument(settings *print.Settings) print.Engine {
tt := template.New(settings, items...) tt := template.New(settings, items...)
tt.CustomFunc(gotemplate.FuncMap{ tt.CustomFunc(gotemplate.FuncMap{
"type": func(t string) string { "type": func(t string) string {
result, extraline := printFencedCodeBlock(t, "hcl") result, extraline := PrintFencedCodeBlock(t, "hcl")
if !extraline { if !extraline {
result += "\n" result += "\n"
} }
@@ -45,7 +45,7 @@ func NewMarkdownDocument(settings *print.Settings) print.Engine {
if v == "n/a" { if v == "n/a" {
return v return v
} }
result, extraline := printFencedCodeBlock(v, "json") result, extraline := PrintFencedCodeBlock(v, "json")
if !extraline { if !extraline {
result += "\n" result += "\n"
} }

View File

@@ -35,13 +35,13 @@ func NewMarkdownTable(settings *print.Settings) print.Engine {
tt := template.New(settings, items...) tt := template.New(settings, items...)
tt.CustomFunc(gotemplate.FuncMap{ tt.CustomFunc(gotemplate.FuncMap{
"type": func(t string) string { "type": func(t string) string {
inputType, _ := printFencedCodeBlock(t, "") inputType, _ := PrintFencedCodeBlock(t, "")
return inputType return inputType
}, },
"value": func(v string) string { "value": func(v string) string {
var result = "n/a" var result = "n/a"
if v != "" { if v != "" {
result, _ = printFencedCodeBlock(v, "") result, _ = PrintFencedCodeBlock(v, "")
} }
return result return result
}, },

Some files were not shown because too many files have changed in this diff Show More