render

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeBaseDirectory

func ComputeBaseDirectory(file string, allFiles []string, baseDirectory string) string

ComputeBaseDirectory computes the base directory for the given file. If baseDirectory is not empty, it is returned. Otherwise, the base directory is computed by finding the shortest common prefix of the given file and all files.

Input directories have to end with a slash, as they will otherwise be considered files and stripped of their last component.

The returned base directory won't have a / at the end.

Types

type Option

type Option func(r *Renderer)

func WithAllowProgramCreation

func WithAllowProgramCreation(allowProgramCreation bool) Option

func WithDelimiters

func WithDelimiters(leftDelimiter string, rightDelimiter string) Option

func WithGoTemplate

func WithGoTemplate(withGoTemplate bool) Option

func WithMasks

func WithMasks(masks ...string) Option

func WithPrograms

func WithPrograms(programs map[string]*cliopatra.Program) Option

func WithRenameOutputFiles

func WithRenameOutputFiles(renameOutputFiles map[string]string) Option

func WithRepositories

func WithRepositories(repositories ...Repository) Option

func WithVerbose

func WithVerbose(verbose bool) Option

func WithYamlMarkers

func WithYamlMarkers(withYamlMarkers bool) Option

type Renderer

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

Renderer renders recursive templates by exposing cliopatra specific template functions.

NOTE(manuel, 2023-03-19) This could actually be a generic component that can be used for arbitrary recursive watching and rendering of templates See https://github.com/go-go-golems/glazed/issues/223

func NewRenderer

func NewRenderer(options ...Option) *Renderer

func (*Renderer) CreateTemplate

func (r *Renderer) CreateTemplate(name string) (*template.Template, error)

CreateTemplate creates a standard glazed template (meaning, with all the sprig functions and co) and registers a set of custom functions to run and modify cliopatra programs.

These functions are

  • `lookup`: looks up a program by name and returns it

  • `program`: creates a new program. This will fail if program creation is not allowed.

  • `path`: sets the path of a program

  • `verbs`: sets the verbs of a program (a []string)

  • `env`: sets the env of a program (a map[string]string)

  • `add_raw_flag`: adds a raw flag to a program (a string)

  • `raw_flags`: sets the raw flags of a program (a []string)

  • `flag`: sets the value of a flag (a interface{})

  • `flag_raw`: sets the raw value of a flag (a string)

  • `arg`: sets the value of an arg (a interface{})

  • `arg_raw`: sets the raw value of an arg (a string)

  • `run`: runs a program and returns the output. It can take an arbitrary number of options.

    If the program to be run is a string, it will be looked up in the programs passed to the renderer. If it is a *pkg.Program, it will be run as is.

    If a string is passed as an option, it will be appended to the program as a raw flag.

    `run` clones the program before modifying it with the passed options.

func (*Renderer) Render

func (r *Renderer) Render(in io.Reader, out io.Writer) error

Render renders the template from the given reader and writes the result to the given writer.

func (*Renderer) RenderDirectory

func (r *Renderer) RenderDirectory(directory string, outputDirectory string) error

func (*Renderer) RenderFile

func (r *Renderer) RenderFile(file string, outputFile string) error

type Repository

type Repository interface {
	GetPrograms() map[string]*cliopatra.Program
}

Jump to

Keyboard shortcuts

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