Documentation ¶
Index ¶
- Variables
- func ToMapStringAny[T any](input map[string]T) map[string]any
- type ExecuteTemplateError
- type FileAction
- type FileError
- type ParseHTMLError
- type PipeData
- func (pd *PipeData) AddError(err error) *PipeData
- func (pd *PipeData) Clone() *PipeData
- func (pd *PipeData) LoadGlob(glob string) *PipeData
- func (pd *PipeData) LoadRenderRepeated(templatePath, repeatedDataKey, targetPathTemplate string) *PipeData
- func (pd *PipeData) LoadRenderSingle(templatePath, targetPath string) *PipeData
- func (pd *PipeData) Must()
- func (pd *PipeData) MustTransformData(transform func(map[string]any) (map[string]any, error)) *PipeData
- func (pd *PipeData) MustWithClones(pipelines []func(pd *PipeData) *PipeData) *PipeData
- func (pd *PipeData) RenderRepeated(templateName, repeatedDataKey, targetPathTemplate string) *PipeData
- func (pd *PipeData) RenderSingle(templateName, targetPath string) *PipeData
- func (pd *PipeData) SetData(key string, value any) *PipeData
- func (pd *PipeData) SetDataYAML(key, path string) *PipeData
- func (pd *PipeData) WithDataDir(dataDir string) *PipeData
- func (pd *PipeData) WithOutputDir(outputDir string) *PipeData
- func (pd *PipeData) WithTemplatesDir(templatesDir string) *PipeData
Constants ¶
This section is empty.
Variables ¶
var ErrCreateTargetDirectoryFailed = errors.New("failed to create target directory")
var ErrPipeDataNil = errors.New("PipeData is nil")
var ErrPlaceholderMissingInTargetPathTemplate = errors.New("{{KEY}} placeholder missing in target path template")
var ErrRepeatedDataNotFound = errors.New("repeated data key not found in data, must be map[string]any")
Functions ¶
Types ¶
type ExecuteTemplateError ¶
type ExecuteTemplateError struct {
// contains filtered or unexported fields
}
func (*ExecuteTemplateError) Error ¶
func (e *ExecuteTemplateError) Error() string
func (*ExecuteTemplateError) Unwrap ¶
func (e *ExecuteTemplateError) Unwrap() error
type FileAction ¶
type FileAction string
const ( FileActionOpen FileAction = "OPEN" FileActionCreateTruncate FileAction = "CREATE_TRUNCATE" FileActionDecodeYAML FileAction = "DECODE_YAML" FileActionClose FileAction = "CLOSE" )
type ParseHTMLError ¶
type ParseHTMLError struct {
// contains filtered or unexported fields
}
func (*ParseHTMLError) Error ¶
func (e *ParseHTMLError) Error() string
func (*ParseHTMLError) Unwrap ¶
func (e *ParseHTMLError) Unwrap() error
type PipeData ¶
type PipeData struct { TemplatesDir string DataDir string OutputDir string Template *template.Template Data map[string]any Errors []error }
func NewHTML ¶
New creates a new PipeData object with initial values. Functions are taken as an argument as these should be populated before you parse any template. See https://pkg.go.dev/text/template#Template.Funcs for more info.
func (*PipeData) Clone ¶
Clone clones the PipeData for reuse of common steps. Note: For simplicity, Data and Errors are not cloned and keep the original pointer. So, updating Data and Errors in a cloned PipeData will also affect the original one.
func (*PipeData) LoadRenderRepeated ¶
func (pd *PipeData) LoadRenderRepeated(templatePath, repeatedDataKey, targetPathTemplate string) *PipeData
LoadRenderRepeated clones the PipeData, loads specified template and executes it. Original PipeData is returned. Make sure to check Clone() on effects of cloning!
func (*PipeData) LoadRenderSingle ¶
LoadRenderSingle clones the PipeData, loads specified template and executes it. Original PipeData is returned. Make sure to check Clone() on effects of cloning!
func (*PipeData) Must ¶
func (pd *PipeData) Must()
Must calls log.Fatal in case errors are provided.
func (*PipeData) MustTransformData ¶
func (pd *PipeData) MustTransformData(transform func(map[string]any) (map[string]any, error)) *PipeData
TransformData takes a function which receives pd.Data and should return the modified pd.Data. TransformData will panic if the given function returns an error to prevent an incorrectly generated website.
func (*PipeData) MustWithClones ¶
MustWithClones is a convenience wrapper which takes a slice of functions. Each function receives a cloned version of the PipeData. Must is called on the return value of each function. Note: For simplicity, Data and Errors are not cloned and keep the original pointer. So, updating Data and Errors in a cloned PipeData will also affect the original one.
func (*PipeData) RenderRepeated ¶
func (pd *PipeData) RenderRepeated(templateName, repeatedDataKey, targetPathTemplate string) *PipeData
RenderRepeated renders multiple pages. "repeatedDataKey" should point to a value of type map[string]any. "targetPathTemplate" should contain "{{KEY}}" which is replaced by the key of provided map.
func (*PipeData) RenderSingle ¶
func (*PipeData) SetDataYAML ¶
SetDataYAML loads a YAML file from given path and adds it to pd.Data on given key.
func (*PipeData) WithDataDir ¶
WithDataDir sets the default data directory.
func (*PipeData) WithOutputDir ¶
WithOutputDir sets the output data directory.
func (*PipeData) WithTemplatesDir ¶
WithTemplatesDir sets the default templates directory.