scaffold

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2025 License: Apache-2.0 Imports: 11 Imported by: 2

README

Form and Scaffold Utilities for Golang

This project contains 2 main components:

  • scaffold generates files or entire directory hierarchies from complex data
  • forms is a guided input form system for the terminal that can generate arbitrarily nested complex data

Together they allow building Wizard-style file generators.

See App Builder for these projects in use in an end-user product.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// TargetDirectory is where to place the resulting rendered files, must not exist
	TargetDirectory string `yaml:"target"`
	// SourceDirectory reads templates from a directory, mutually exclusive with Source
	SourceDirectory string `yaml:"source_directory"`
	// Source reads templates from in-process memory
	Source map[string]any `yaml:"source"`
	// Post configures post-processing of files using filepath globs
	Post []map[string]string `yaml:"post"`
	// SkipEmpty skips files that are 0 bytes after rendering
	SkipEmpty bool `yaml:"skip_empty"`
	// Sets a custom template delimiter, useful for generating templates from templates
	CustomLeftDelimiter string `yaml:"left_delimiter"`
	// Sets a custom template delimiter, useful for generating templates from templates
	CustomRightDelimiter string `yaml:"right_delimiter"`
}

Config configures a scaffolding operation

type Logger

type Logger interface {
	Debugf(format string, v ...any)
	Infof(format string, v ...any)
}

type Scaffold

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

func New

func New(cfg Config, funcs template.FuncMap) (*Scaffold, error)

New creates a new scaffold instance

func (*Scaffold) Logger

func (s *Scaffold) Logger(log Logger)

Logger configures a logger to use, no logging is done without this

func (*Scaffold) Render

func (s *Scaffold) Render(data any) error

Render creates the target directory and place all files into it after template processing and post-processing

func (*Scaffold) RenderString added in v0.0.2

func (s *Scaffold) RenderString(str string, data any) (string, error)

RenderString renders a string using the same functions and behavior as the scaffold, including custom delimiters

Directories

Path Synopsis
internal
sprig
Package sprig provides template functions for Go.
Package sprig provides template functions for Go.

Jump to

Keyboard shortcuts

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