gen

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package gen is the packeg of internal gen

Index

Constants

View Source
const (
	// ImportIdent is import directive identifier
	ImportIdent = "import"
	// Root is the List key for root, starting point of resolving
	Root = "_"
)

Variables

View Source
var (
	// ErrRootNotFound is returned when root is not found
	ErrRootNotFound = errors.New("Root is not found")
	// ErrVariableNotFound is returned when variable is not found
	ErrVariableNotFound = errors.New("No such variable ident")
)

Functions

func ExpandEach

func ExpandEach(list List, exp Expander, src string, dst string, file string, content []byte) (to string, w []byte, err error)

func Write

func Write(basePath string, out Out) error

Types

type Depth

type Depth struct {
	Nodes []*Node
}

Depth is nodes slice for the same depth.

type Expander

type Expander interface {
	Ext() (from, to string)
	Expand(p []byte, v Variables) ([]byte, error)
}

type File

type File struct {
	Content []byte
	Perm    os.FileMode
}

type Gen

type Gen struct {
	BasePath string // must be absolute
	SrcPath  string // must be relative
	DstPath  string // must be relative
}

Gen is the struct for gen cmd

func New

func New(base, src, dst string) *Gen

New returns new *Gen

func (*Gen) Set

func (gen *Gen) Set(basePath, srcPath, dstPath string) error

type List

type List map[string]Variables

List is all Variable list. map key is the key to access Variable

func GenList

func GenList(basePath string, loaders ...Loader) (List, error)

GenList makes list from given directory.

func (List) GenTree

func (list List) GenTree(root *Node) Tree

func (List) Get

func (list List) Get(key string) (Variables, error)

Get provides the way to access the list with key. On `map`, v, ok := map[xxx] is used, but error is needed for lib design. Get returns error when the key is not found.

func (List) String

func (list List) String() string

String implements fmt.Stringer

type Loader

type Loader interface {
	Ext() string
	Load(p []byte) (Variables, error)
}

Loader is the interface that provides the way to get Variables from document.

Ext returns file extension, e.g. md, html. If the given file is matched to this, then the loader will be used to resolve.

Load is the function to get Variables from document.

type Node

type Node struct {
	Key     string
	Content Variables
	Deps    []string
	// contains filtered or unexported fields
}

Node is the deps tree node.

type Out

type Out map[string]*File

func Expand

func Expand(basePath, srcPath, dstPath string, list List, expanders ...Expander) (Out, error)

func (Out) String

func (out Out) String() string

String implements fmt.Stringer

type Tree

type Tree []*Depth

Tree is tree of sum of depth.

func (Tree) Reduce

func (tree Tree) Reduce() Variables

type Variables

type Variables map[string]interface{}

Variables is the type expressing front matters

func MapToVariables

func MapToVariables(m map[string]interface{}) Variables

func Resolve

func Resolve(list List) (Variables, error)

Resolve resolves th given list into Variables aling with the key "_" Internally, this uses ResolveKey with key = Root

func ResolveKey

func ResolveKey(list List, key string) (Variables, error)

ResolveKey resolves the given list into Variables along with the given key as root.

func (Variables) ContainsImports

func (v Variables) ContainsImports() bool

ContainsImports checks Variable imports or not.

func (Variables) Copy

func (vs Variables) Copy() Variables

Copy copies and returns new Variables

func (Variables) String

func (vs Variables) String() string

String implements fmt.Stringer

func (Variables) ToImports

func (v Variables) ToImports() []string

ToImports resolve Variable into import keys. If no deps, empty string slice is returned.

func (Variables) ToNode

func (v Variables) ToNode(key string) *Node

ToNode converts Variable to Node.

Jump to

Keyboard shortcuts

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