ctemplate

package module
v0.0.0-...-3dbd443 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DefaultTemplateFile = ".contxt.yml"
	DefaultIncludeFile  = ".inc.contxt.yml"
)

Variables

This section is empty.

Functions

func MergeVariableMap

func MergeVariableMap(mapin map[string]interface{}, maporigin map[string]interface{}) (map[string]interface{}, error)

MergeVariableMap merges two maps this is a global function that is used in different places

Types

type CtxTemplate

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

func NewCtxTemplate

func NewCtxTemplate() *CtxTemplate

func (*CtxTemplate) AddDataMap

func (c *CtxTemplate) AddDataMap(m map[string]interface{})

func (*CtxTemplate) AddDataValue

func (c *CtxTemplate) AddDataValue(key string, value interface{})

func (*CtxTemplate) ParseTemplate

func (c *CtxTemplate) ParseTemplate(tmpl *template.Template) (string, error)

func (*CtxTemplate) ParseTemplateString

func (c *CtxTemplate) ParseTemplateString(tmpl string) (string, error)

func (*CtxTemplate) SetData

func (c *CtxTemplate) SetData(data map[string]interface{})

func (*CtxTemplate) SetLogger

func (c *CtxTemplate) SetLogger(logger mimiclog.Logger)

type Template

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

func New

func New() *Template

create a new Template struct

func (*Template) FindIncludeFileName

func (t *Template) FindIncludeFileName(path string) (string, bool)

FindIncludeFileName returns the full path to the include file if it exists the bool value indicates if the file exists or not the default include file name is .inc.contxt.yml in the current directory

func (*Template) FindTemplateFileName

func (t *Template) FindTemplateFileName() (string, bool)

FindTemplateFileName searchs for Template files in the current directory the bool value indicates if the file exists or not the default template file name is .contxt.yml in the current directory

func (*Template) GetIncludeFile

func (t *Template) GetIncludeFile() string

func (*Template) GetLinter

func (t *Template) GetLinter() (*yaclint.Linter, error)

GetLinter returns the linter interface

func (*Template) GetOriginMap

func (t *Template) GetOriginMap() map[string]interface{}

func (*Template) HandleContxtTemplate

func (t *Template) HandleContxtTemplate(path string) (string, error)

HandleContxtTemplate parses a template file and returns the parsed content by using all the the include files. the usage is the same as the go template parser. so you can use {{ .var }} to access the variables in this case it is expected, we have a .inc.contxt.yml file in the same directory, that defines the include files. if no include file is found, the template file will be parsed as go/template these definition is required, because all these files containing the values, they are used for parsing by using go/template

func (*Template) ImportFolder

func (t *Template) ImportFolder(startPath string) (map[string]interface{}, error)

func (*Template) Init

func (t *Template) Init() error

Init initializes the Template struct this is ment to be called before any other function

func (*Template) Load

func (t *Template) Load() (configure.RunConfig, bool, error)

Load loads the template file and returns the parsed content. this is ment for loading the default template file. so anything here is depending the default template file name, and the current directory.

func (*Template) LoadInclude

func (t *Template) LoadInclude(path string) (configure.IncludePaths, bool, error)

LoadInclude loads the include files and returns the parsed content. these files are defined in the default include file named .inc.contxt.yml any of these files can have template placeholders, they will processed

func (*Template) LoadV2

func (t *Template) LoadV2() (configure.RunConfig, error)

LoadV2 loads the template file and returns the parsed content. this is ment for loading the default template file. if you like to load a template file from a different location use LoadV2ByAbsolutePath

func (*Template) LoadV2ByAbsolutePath

func (t *Template) LoadV2ByAbsolutePath(absolutePath string) (configure.RunConfig, error)

LoadV2ByAbsolutePath loads the template file and returns the parsed content. this is ment for loading a template file from a different location.

func (*Template) ParseGoTemplate

func (t *Template) ParseGoTemplate(data string) (string, error)

func (*Template) SetIncludeFile

func (t *Template) SetIncludeFile(file string)

func (*Template) SetLinting

func (t *Template) SetLinting(linting bool)

SetLinting enables or disables the linting process

func (*Template) SetLogger

func (t *Template) SetLogger(logger mimiclog.Logger)

SetLogger sets the logger interface

func (*Template) SetOnLoad

func (t *Template) SetOnLoad(fn func(*configure.RunConfig) error)

set the callback function that is called after the template file is loaded

func (*Template) TryHandleTemplate

func (t *Template) TryHandleTemplate(path string) (string, error)

Different to HandleContxtTemplate, here we do not expect the include definition file .inc.contxt.yml. We just try to parse the template file togehter with the current data map

func (*Template) UpdateOriginMap

func (t *Template) UpdateOriginMap(mapData map[string]interface{})

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL