layout

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EmbedDirectory is main embed directory with predefined templates.
	EmbedDirectory = `embed`

	// Extension is a common extension for all template files used for generation project.
	Extension = `gotmpl`
)

Variables

This section is empty.

Functions

func NewTemplate

func NewTemplate(name string, funcMap template.FuncMap) *template.Template

NewTemplate return built-in go *template.Template.

func ProvideEmbedFS added in v1.1.0

func ProvideEmbedFS(directory BoxDirectory) (fs.ReadFileFS, error)

ProvideEmbedFS return fs.ReadFileFS, which contains embed built-in template files.

Types

type Box added in v1.1.0

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

Box is a BoxInterface implementation. Contains information about embed and os filesystem.

func (*Box) ReadFile added in v1.1.0

func (b *Box) ReadFile(name string) ([]byte, error)

ReadFile implements BoxInterface method. Read from embed FS, then os FS.

type BoxDirectory added in v1.1.0

type BoxDirectory string

BoxDirectory is an alias for string type, determine where placed builtin layout templates.

type BoxInterface added in v1.1.0

type BoxInterface interface {
	ReadFile(string) ([]byte, error)
}

BoxInterface is a common interface for read file content of templates, builtin and passed by values/args.

func NewBox

func NewBox(embedFS fs.ReadFileFS, osFS afero.Fs) BoxInterface

NewBox return BoxInterface, which contains embed built-in template files.

type Generator

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

Generator is built-in generator.Generator implementation. Used to generate common/base layout for project.

func NewGenerator

func NewGenerator(renderer RendererInterface, filesystem afero.Fs, options ...Option) *Generator

NewGenerator return Generator

func (*Generator) Run

Run performs main process of generation. Current steps:

  • make cleanup working directory if called
  • prepare file list for generation
  • process each file/template

type Option

type Option func(options *Options)

Option allows setting optional Generator Options.

func WithCleanup

func WithCleanup(cleanup bool) Option

WithCleanup specifies Options.Cleanup value, allow cleanup working directory before generation start.

func WithTemplateDockerfile

func WithTemplateDockerfile(path *string) Option

WithTemplateDockerfile specifies custom Dockerfile template path.

func WithTemplateMakefile

func WithTemplateMakefile(path *string) Option

WithTemplateMakefile specifies custom Makefile template path.

type Options

type Options struct {
	Cleanup   bool
	Templates struct {
		Dockerfile *string
		Makefile   *string
	}
}

Options provides additional Generator settings, such as generator Cleanup or Templates.

type Renderer

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

Renderer is built-in RendererInterface implementation.

func (*Renderer) Render

func (r *Renderer) Render(source string, values generator.RunValues) ([]byte, error)

Render implements RendererInterface Steps for render: - try to find template in embed box or resolve in in os filesystem - open file - get template file content - parse template file content - execute template

type RendererInterface

type RendererInterface interface {
	Render(source string, values generator.RunValues) ([]byte, error)
}

RendererInterface define common interface for rendering templates.

func NewRenderer

NewRenderer return implementation of RendererInterface.

type TemplateInterface

type TemplateInterface interface {
	Parse(string) (*template.Template, error)
	Execute(io.Writer, interface{}) error
}

TemplateInterface define common interface for parsing and executing text/html templates.

Jump to

Keyboard shortcuts

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