pipeline

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCreateTargetDirectoryFailed = errors.New("failed to create target directory")
View Source
var ErrPipeDataNil = errors.New("PipeData is nil")
View Source
var ErrPlaceholderMissingInTargetPathTemplate = errors.New("{{KEY}} placeholder missing in target path template")
View Source
var ErrRepeatedDataNotFound = errors.New("repeated data key not found in data, must be map[string]any")

Functions

func ToMapStringAny

func ToMapStringAny[T any](input map[string]T) map[string]any

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 FileError

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

func (*FileError) Error

func (e *FileError) Error() string

func (*FileError) Unwrap

func (e *FileError) Unwrap() error

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

func NewHTML(functions template.FuncMap) *PipeData

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) AddError

func (pd *PipeData) AddError(err error) *PipeData

AddError appends an error to the data.

func (*PipeData) Clone

func (pd *PipeData) Clone() *PipeData

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) LoadGlob

func (pd *PipeData) LoadGlob(glob string) *PipeData

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

func (pd *PipeData) LoadRenderSingle(templatePath, targetPath string) *PipeData

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

func (pd *PipeData) MustWithClones(pipelines []func(pd *PipeData) *PipeData) *PipeData

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 (pd *PipeData) RenderSingle(templateName, targetPath string) *PipeData

func (*PipeData) SetData

func (pd *PipeData) SetData(key string, value any) *PipeData

SetData set provided value to provided data key.

func (*PipeData) SetDataYAML

func (pd *PipeData) SetDataYAML(key, path string) *PipeData

SetDataYAML loads a YAML file from given path and adds it to pd.Data on given key.

func (*PipeData) WithDataDir

func (pd *PipeData) WithDataDir(dataDir string) *PipeData

WithDataDir sets the default data directory.

func (*PipeData) WithOutputDir

func (pd *PipeData) WithOutputDir(outputDir string) *PipeData

WithOutputDir sets the output data directory.

func (*PipeData) WithTemplatesDir

func (pd *PipeData) WithTemplatesDir(templatesDir string) *PipeData

WithTemplatesDir sets the default templates directory.

Jump to

Keyboard shortcuts

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