generator

package
v0.0.0-...-9f7fb72 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2023 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFileNotFound = errors.New("file not found")

Functions

func LoadCustomFunction

func LoadCustomFunction(g Generator)

func Marshal

func Marshal(envMap map[string]string) (string, error)

Marshal outputs the given environment as a dotenv-formatted environment file. Each line is in the format: KEY="VALUE" where VALUE is backslash-escaped.

func Parse

func Parse(r io.Reader) (envMap map[string]string, err error)

Parse reads an env file from io.Reader, returning a map of keys and values.

func ReadFile

func ReadFile(filename string) (fileBytes []byte, filePath string, err error)

ReadFile recursively reads a file for given path till user home directory and returns nearest file to given path given path must be relative to working directory

func ReadMakefileENV

func ReadMakefileENV(filenames ...string) (envMap map[string]string)

Read all env (with same file loading semantics as Load) but return values as a map rather than automatically writing values into env

func ReadPatch

func ReadPatch(tmplDir, tmpl string) ([]diffmatchpatch.Patch, error)

func ReadTemplate

func ReadTemplate(tmplDir, tmpl string) (fileBytes []byte, filePath string, err error)

func Unmarshal

func Unmarshal(str string) (envMap map[string]string, err error)

Unmarshal reads an env file from a string, returning a map of keys and values.

func Write

func Write(envMap map[string]string, filename string) error

Write serializes the given environment and writes it to a file

Types

type Bindings

type Bindings map[string]any

func (Bindings) LoadFromENV

func (o Bindings) LoadFromENV() Bindings

func (Bindings) LoadFromFile

func (o Bindings) LoadFromFile() Bindings

LoadFromFile load Makefile variables from Makefile and replace existing variables

func (Bindings) Set

func (o Bindings) Set(key string, value any) Bindings

type Config

type Config struct {
	// OnceFiles only generate once when creating new project
	OnceFiles []string `yaml:"once_files"`
	// SoftFiles will be generate every time when using generate command
	SoftFiles []string `yaml:"soft_files"`
	// HardFiles will be generate every time when using generate command with --hard flag
	HardFiles []string `yaml:"hard_files"`
	// DefaultENVs is default environment variables when creating new project.
	// on existing project, Makefile variables will replace these variables.
	DefaultENVs map[string]any `yaml:"default_envs"`

	WasmFuncs []custom_func.Libs `yaml:"wasm_funcs"`
	// contains filtered or unexported fields
}

Config represents the configuration

func Conf

func Conf() *Config

type Generator

type Generator interface {
	// SetOptions sets template engine binding
	SetOptions(bindings map[string]any)
	// Register a new template file to template engine
	Register(tmplDir, tmplFilePath string) error

	RegisterFunc(funcName string, function any)
	// Generate all templates
	Generate() error
}

func NewLiquidGenerator

func NewLiquidGenerator() Generator

func NewTextGenerator

func NewTextGenerator() Generator

type LiquidGenerator

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

func (*LiquidGenerator) Generate

func (l *LiquidGenerator) Generate() error

func (*LiquidGenerator) Register

func (l *LiquidGenerator) Register(tmplDir, tmpl string) error

func (*LiquidGenerator) RegisterFunc

func (l *LiquidGenerator) RegisterFunc(funcName string, function any)

func (*LiquidGenerator) SetOptions

func (l *LiquidGenerator) SetOptions(bindings map[string]any)

type Patch

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

func NewPatch

func NewPatch() *Patch

func (*Patch) Patch

func (p *Patch) Patch(tmpl string, text []byte) []byte

func (*Patch) Register

func (p *Patch) Register(tmplDir, tmpl string) error

type Template

type Template struct {
	// Path is the path of output file name
	Path string
	// Template is the raw template to be parsed by template engine
	Template []byte
}

type TextGeneraotr

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

func (*TextGeneraotr) Generate

func (l *TextGeneraotr) Generate() error

func (*TextGeneraotr) Register

func (l *TextGeneraotr) Register(tmplDir, tmpl string) error

func (*TextGeneraotr) RegisterFunc

func (l *TextGeneraotr) RegisterFunc(funcName string, function any)

func (*TextGeneraotr) SetOptions

func (l *TextGeneraotr) SetOptions(bindings map[string]any)

type TextTemplate

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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