Movatterモバイル変換


[0]ホーム

URL:


template

package
v0.20.0Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2025 License:MITImports:11Imported by:2

Details

Repository

github.com/terraform-docs/terraform-docs

Links

Documentation

Overview

Package template provides templating functionality.

Usage

import (    "fmt"    gotemplate "text/template"    "github.com/terraform-docs/terraform-docs/print"    "github.com/terraform-docs/terraform-docs/template"    "github.com/terraform-docs/terraform-docs/terraform")const mainTpl =`{{- if .Config.Sections.Header -}}    {{- with .Module.Header -}}        {{ colorize "\033[90m" . }}    {{ end -}}    {{- printf "\n\n" -}}{{ end -}}`func render(config *print.Config, module *terraform.Module) (string, error) {    tt := template.New(config, &template.Item{        Name:      "main",        Text:      mainTpl,        TrimSpace: true,    })    tt := template.New(config, items...)    tt.CustomFunc(gotemplate.FuncMap{        "colorize": func(color string, s string) string {            reset := "\033[0m"            if !config.Settings.Color {                color = ""                reset = ""            }            return fmt.Sprintf("%s%s%s", color, s, reset)        },    })    return tt.Render("main", module)}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

funcConvertMultiLineText

func ConvertMultiLineText(sstring, isTablebool, isHeaderbool, showHTMLbool)string

ConvertMultiLineText converts a multi-line text into a suitable Markdown representation.

funcConvertOneLineCodeBlock

func ConvertOneLineCodeBlock(sstring)string

ConvertOneLineCodeBlock converts a multi-line code block into a one-liner.Line breaks are replaced with single space.

funcCreateAnchorAsciidoc

func CreateAnchorAsciidoc(prefixstring, valuestring, anchorbool, escapebool)string

CreateAnchorAsciidoc creates HTML anchor for AsciiDoc format.

funcCreateAnchorMarkdown

func CreateAnchorMarkdown(prefixstring, valuestring, anchorbool, escapebool)string

CreateAnchorMarkdown creates HTML anchor for Markdown format.

funcEscapeCharacters

func EscapeCharacters(sstring, escapebool, escapePipebool)string

EscapeCharacters escapes characters which have special meaning in Markdown intotheir corresponding literal.

funcGenerateIndentation

func GenerateIndentation(baseint, extraint, charstring)string

GenerateIndentation generates indentation of Markdown and AsciiDoc headerswith base level of provided 'settings.IndentLevel' plus any extra level neededfor subsection (e.g. 'Required Inputs' which is a subsection of 'Inputs' section)

funcNormalizeURLs

func NormalizeURLs(sstring, escapebool)string

NormalizeURLs runs after escape function and normalizes URL back to the originalstate. For example any underscore in the URL which got escaped by 'EscapeCharacters'will be reverted back.

funcSanitizeAsciidocTable

func SanitizeAsciidocTable(sstring, escapebool, htmlbool)string

SanitizeAsciidocTable converts passed 'string' to suitable AsciiDoc representationfor a table. (including line-break, illegal characters, code blocks etc).

funcSanitizeDocument

func SanitizeDocument(sstring, escapebool, htmlbool)string

SanitizeDocument converts passed 'string' to suitable Markdown or AsciiDocrepresentation for a document. (including line-break, illegal characters,code blocks etc).

funcSanitizeMarkdownTable

func SanitizeMarkdownTable(sstring, escapebool, htmlbool)string

SanitizeMarkdownTable converts passed 'string' to suitable Markdown representationfor a table. (including line-break, illegal characters, code blocks etc).

funcSanitizeName

func SanitizeName(namestring, escapebool)string

SanitizeName escapes underscore character which have special meaning inMarkdown.

funcSanitizeSection

func SanitizeSection(sstring, escapebool, htmlbool)string

SanitizeSection converts passed 'string' to suitable Markdown or AsciiDocrepresentation for a document. (including line-break, illegal characters,code blocks etc). This is in particular being used for header and footer.

IMPORTANT: SanitizeSection will never change the line-endings and preservethem as they are provided by the users.

Types

typeItem

type Item struct {NamestringTextstringTrimSpacebool}

Item represents a named templated which can reference other named templated too.

typeTemplate

type Template struct {// contains filtered or unexported fields}

Template represents a new Template with given name and content to be renderedwith provided settings with use of built-in and custom functions.

funcNew

func New(config *print.Config, items ...*Item) *Template

New returns new instance of Template.

func (*Template)CustomFunc

func (t *Template) CustomFunc(funcsgotemplate.FuncMap)

CustomFunc adds new custom functions to the template if functions with the samenames didn't exist.

func (Template)Funcs

func (tTemplate) Funcs()gotemplate.FuncMap

Funcs return available template out of the box and custom functions.

func (*Template)Render

func (t *Template) Render(namestring, module *terraform.Module) (string,error)

Render template with given Module struct.

func (*Template)RenderContent

func (t *Template) RenderContent(namestring, data interface{}) (string,error)

RenderContent template with given data. It can contain anything but mostprobably it will only contain terraform.Module and print.generator.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp