press

package
v0.0.0-...-356750c Latest Latest
Warning

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

Go to latest
Published: May 18, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package press serves as the print head to press the template into a working output of the intended purpose of the designer. So if the designer design a template for an application the output will produce just that.

Index

Constants

View Source
const (
	FilePerm       = 0774
	ConfigFileName = "config.json"
)
View Source
const (
	TmplManifestFile = "template.json"
)

Variables

View Source
var FuncMap = template.FuncMap{
	"title":   cases.Title,
	"toLower": strings.ToLower,
	"toUpper": strings.ToUpper,
}

Functions

func BuildAppDataPath

func BuildAppDataPath(appName string) (string, error)

func FindTemplates

func FindTemplates(dir string) ([]string, error)

FindTemplates Recursively walk a directory looking for files along the way.

func GetPlaceholderInput

func GetPlaceholderInput(placeholders *TmplManifest, tmplValues map[string]string, r *os.File, defaultVal string) error

GetPlaceholderInput Checks for any missing placeholder values waits for their input from the CLI.

func InSkipArray

func InSkipArray(pathToFile string, skips []string) bool

Get to know glob before you question the correctness of my program: https://man7.org/linux/man-pages/man7/glob.7.html

func Print

func Print(tplDir, outDir string, vars map[string]string, tmplJson *TmplManifest) error

Print templates to the output directory.

func SaveConfig

func SaveConfig(filepath string, cfg *ConfigSaveData) error

SaveConfig Save any updates to the configuration file.

func ShowAllPlaceholderValues

func ShowAllPlaceholderValues(tm *TmplManifest, tmplValues map[string]string)

func Substitute

func Substitute(source, dest string) error

Substitute Looks for a special directory, can be specified in the template.json, then copies all files from that directory to the root of the TmplPath, overwriting any existing files. This is done before any templates are processed, to ensure they are run also through the template engine.

func ValidateManifest

func ValidateManifest(aFile string) error

ValidateManifest Read a template manifest and report any errors. This is a quality-of-life tool for template designers.

Types

type AnswersJson

type AnswersJson struct {
	Placeholders map[string]string `json:"placeholders"`
}

func LoadAnswers

func LoadAnswers(filename string) (*AnswersJson, error)

LoadAnswers Load key/value pairs from a JSON file to fill in placeholders (provides that data for the Go templates).

type AppData

type AppData struct {
	AnswersJson  *AnswersJson // data use for template processing
	CacheDir     string       // Directory to store app data.
	DataDir      string       // Directory to store app data.
	Path         string       // Path to configuration file.
	SubCmd       string       // sub-command to execute
	Tmpl         string       // Path to template, this will be the cached path.
	TmplLocation string       // Indicates local or remote location to downloaded

}

AppData runtime settings shared throughout the application.

func NewAppData

func NewAppData(sc *ConfigSaveData) (*AppData, error)

type ConfigSaveData

type ConfigSaveData struct {
	CacheDir string
}

func InitConfig

func InitConfig(filepath, appName string) (*ConfigSaveData, error)

InitConfig Save configuration file when it does not exist.

func LoadConfig

func LoadConfig(filepath string) (*ConfigSaveData, error)

LoadConfig Load to the configuration file.

type TmplManifest

type TmplManifest struct {
	// A list of files to exclude from processing through the template,
	// but still are output in the final output.
	CopyAsIs []string `json:"copyAsIs,omitempty"`

	// EmptyDirFile Name of a file that marks a directory as empty and has the
	// effect of "mkdir -p". This file allows you to add directories to Git but
	// have them made and empty when the template is pressed.
	EmptyDirFile string `json:"emptyDirFile"`

	// Values to supply to the template to fill in variables.
	Placeholders map[string]string `json:"placeholders,omitempty"`

	// Files that should not be processed through the template engine nor added
	// to the final output.
	Skip []string `json:"skip,omitempty"`

	// A path to a directory to overwrite other files/directories in the
	// template, before processing output.
	// Note that an empty directory can replace a directory with files.
	Substitute string `json:"substitute,omitempty"`

	// Optional validation to use when entering placeholder values from the CLI.
	Validation []*validator `json:"validation,omitempty"`
}

func NewTmplManifest

func NewTmplManifest(content []byte) (*TmplManifest, error)

func ReadTemplateJson

func ReadTemplateJson(filePath string) (*TmplManifest, error)

ReadTemplateJson read variables needed from the template.json file.

Jump to

Keyboard shortcuts

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