shelf

package module
v0.0.0-...-d6af850 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2021 License: MIT Imports: 3 Imported by: 0

README

介绍

通过搭积木的方式来生成代码、文本的工具(如流程图、积木转代码)

案例

type Package struct {
	shelf.VirtualShelf
	Name string
}

func NewPackage(name string) shelf.Shelf {
	slf := &Package{Name: name}
	return slf.SetWrite(func() string {
		return fmt.Sprintf("package %s", slf.Name)
	})
}
func Test(t *testing.T) {
	var draw []shelf.Shelf

	draw = append(draw,
		NewPackage("shelf"),
		NewLine(1),
		NewImportStart().
			Add(NewImport("github.com/kercylan/shelf/test_line1")).
			Add(NewImport("github.com/kercylan/shelf/test_line2")).
			Add(NewImport("github.com/kercylan/shelf/test_line3")),
		NewImportEnd(),
		NewLine(1),
		NewFuncStart("main", []FuncParameter{}, []FuncParameter{
				{Name: "err", Type: "error"},
		}).
			Add(NewAnnotation("TODO: ...")),
		NewFuncEnd(),
		NewLine(1),
	)

	for _, s := range draw {
		fmt.Print(s.Render())
	}

}

输出

package shelf

import (
    "github.com/kercylan/shelf/test_line1"
    "github.com/kercylan/shelf/test_line2"
    "github.com/kercylan/shelf/test_line3"
)

func main() (err error) {
    // TODO: ...
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

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

func (*Group) Bind

func (slf *Group) Bind(shelf ...Shelf) *Group

Bind 绑定架子到该组,如果架子已存在组则会将对应绑定转移到该组

func (*Group) Del

func (slf *Group) Del(shelf Shelf)

Del 从该组内删除某架子

func (*Group) Move

func (slf *Group) Move(shelf Shelf, index int) error

Move 设置该组内特定架子的位置

func (*Group) Render

func (slf *Group) Render() string

Render 渲染该组

type Shelf

type Shelf interface {
	// GetID 获取ID
	GetID() string
	// GetVirtual 获取虚拟架子
	GetVirtual() *VirtualShelf
	// GetParent 获取壳子
	GetParent() Shelf
	// GetGroup 获取所在的组
	GetGroup() *Group
	// GetAllChildren 获取所有子架子
	GetAllChildren() []Shelf
	// IsRoot 是否是根架子
	IsRoot() bool
	// SetWrite 设置输出内容
	SetWrite(func() string) Shelf
	// Contains 检查子架子是否存在某架子并返回其壳子
	Contains(shelf Shelf) (Shelf, bool)

	// Bind 绑定某架子到该架子到末尾,并返回支持继续添加到相同架子的架子
	Bind(shelf ...Shelf) Shelf
	// BindC 绑定架子到该架子末尾,并返回子架子
	BindC(shelf Shelf) Shelf
	// Del 删除特定架子
	Del(shelf Shelf)
	// Move 移动子架子位置
	Move(shelf Shelf, index int) error

	// SetParent 设置壳子
	SetParent(shelf Shelf)
	// SetGroup 设置所在的组
	SetGroup(group *Group)

	// Render 渲染该架子
	Render(level int) string
}

type VirtualShelf

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

func (*VirtualShelf) Bind

func (slf *VirtualShelf) Bind(shelf ...Shelf) Shelf

func (*VirtualShelf) BindC

func (slf *VirtualShelf) BindC(shelf Shelf) Shelf

func (*VirtualShelf) Contains

func (slf *VirtualShelf) Contains(shelf Shelf) (Shelf, bool)

func (*VirtualShelf) Del

func (slf *VirtualShelf) Del(shelf Shelf)

func (*VirtualShelf) GetAllChildren

func (slf *VirtualShelf) GetAllChildren() []Shelf

func (*VirtualShelf) GetGroup

func (slf *VirtualShelf) GetGroup() *Group

func (*VirtualShelf) GetID

func (slf *VirtualShelf) GetID() string

func (*VirtualShelf) GetParent

func (slf *VirtualShelf) GetParent() Shelf

func (*VirtualShelf) GetVirtual

func (slf *VirtualShelf) GetVirtual() *VirtualShelf

func (*VirtualShelf) IsRoot

func (slf *VirtualShelf) IsRoot() bool

func (*VirtualShelf) Move

func (slf *VirtualShelf) Move(shelf Shelf, index int) error

func (*VirtualShelf) Render

func (slf *VirtualShelf) Render(level int) string

func (*VirtualShelf) SetGroup

func (slf *VirtualShelf) SetGroup(group *Group)

func (*VirtualShelf) SetParent

func (slf *VirtualShelf) SetParent(parent Shelf)

func (*VirtualShelf) SetWrite

func (slf *VirtualShelf) SetWrite(f func() string) Shelf

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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