ntemplate

package
v0.6.17 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2024 License: AGPL-3.0 Imports: 30 Imported by: 3

Documentation

Overview

模板文件和路径处理包

模板文件系统、模板文件路径修正器、模板主题配置

Index

Constants

View Source
const (
	KindBackend  = `backend`
	KindFrontend = `frontend`
)

Variables

This section is empty.

Functions

func IsThemeName added in v0.3.0

func IsThemeName(s string) bool

func NewFileSystemTrimPrefix added in v0.3.0

func NewFileSystemTrimPrefix(trimPrefix string, fs http.FileSystem) http.FileSystem

func NewManager

func NewManager(mgr driver.Manager, pa PathAliases) driver.Manager

NewManager 新建模板文件系统管理驱动实例

func NewMultiManager added in v0.3.0

func NewMultiManager(templateDir string, managers ...driver.Manager) driver.Manager

func NewStaticDir added in v0.3.0

func NewStaticDir(dir string, trimPrefix ...string) http.FileSystem

func RGB2Hex added in v0.3.0

func RGB2Hex(rgb string) string

Types

type FileInfo added in v0.3.0

type FileInfo struct {
	fs.FileInfo
	Embed bool
}

type FileSystems added in v0.3.0

type FileSystems []http.FileSystem

func NewFileSystems added in v0.3.0

func NewFileSystems() FileSystems

func (FileSystems) IsEmpty added in v0.3.0

func (f FileSystems) IsEmpty() bool

func (FileSystems) Open added in v0.3.0

func (f FileSystems) Open(name string) (file http.File, err error)

func (FileSystems) ReadDir added in v0.3.0

func (f FileSystems) ReadDir(name string) (dirs []fs.FileInfo, err error)

func (FileSystems) ReadFile added in v0.3.0

func (f FileSystems) ReadFile(name string) (content []byte, err error)

func (*FileSystems) Register added in v0.3.0

func (f *FileSystems) Register(fileSystem http.FileSystem)

func (FileSystems) Size added in v0.3.0

func (f FileSystems) Size() int

func (FileSystems) Stat added in v0.3.0

func (f FileSystems) Stat(name string) (fi fs.FileInfo, err error)

type MultiManager added in v0.3.0

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

func (*MultiManager) AddAllow added in v0.3.0

func (b *MultiManager) AddAllow(allows ...string)

func (*MultiManager) AddCallback added in v0.3.0

func (b *MultiManager) AddCallback(rootDir string, callback func(name, typ, event string))

func (*MultiManager) AddIgnore added in v0.3.0

func (b *MultiManager) AddIgnore(ignores ...string)

func (*MultiManager) AddWatchDir added in v0.3.0

func (b *MultiManager) AddWatchDir(ppath string) (err error)

func (*MultiManager) CancelWatchDir added in v0.3.0

func (b *MultiManager) CancelWatchDir(oldDir string) (err error)

func (*MultiManager) ChangeWatchDir added in v0.3.0

func (b *MultiManager) ChangeWatchDir(oldDir string, newDir string) (err error)

func (*MultiManager) ClearAllows added in v0.3.0

func (b *MultiManager) ClearAllows()

func (*MultiManager) ClearCache added in v0.3.0

func (b *MultiManager) ClearCache()

func (*MultiManager) ClearCallback added in v0.3.0

func (b *MultiManager) ClearCallback()

func (*MultiManager) ClearIgnores added in v0.3.0

func (b *MultiManager) ClearIgnores()

func (*MultiManager) Close added in v0.3.0

func (b *MultiManager) Close()

func (*MultiManager) DelAllow added in v0.3.0

func (b *MultiManager) DelAllow(allow string)

func (*MultiManager) DelCallback added in v0.3.0

func (b *MultiManager) DelCallback(rootDir string)

func (*MultiManager) DelIgnore added in v0.3.0

func (b *MultiManager) DelIgnore(ignore string)

func (*MultiManager) GetManagers added in v0.3.0

func (b *MultiManager) GetManagers() []driver.Manager

func (*MultiManager) GetTemplate added in v0.3.0

func (b *MultiManager) GetTemplate(filename string) (content []byte, err error)

func (*MultiManager) HasBindata added in v0.3.0

func (b *MultiManager) HasBindata() bool

func (*MultiManager) SetLogger added in v0.3.0

func (b *MultiManager) SetLogger(logger logger.Logger)

func (*MultiManager) SetTemplate added in v0.3.0

func (b *MultiManager) SetTemplate(filename string, content []byte) error

func (*MultiManager) Start added in v0.3.0

func (b *MultiManager) Start() error

func (*MultiManager) TemplateDir added in v0.3.0

func (b *MultiManager) TemplateDir() string

type PathAliases

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

PathAliases 模板路径别名分组设置

func NewPathAliases

func NewPathAliases() *PathAliases

NewPathAliases 新建模板路径别名分组设置实例

func (*PathAliases) Add

func (p *PathAliases) Add(alias, absPath string) *PathAliases

Add 添加别名和路径

func (*PathAliases) AddAllSubdir

func (p *PathAliases) AddAllSubdir(absPath string) error

AddAllSubdir 添加某个路径下以子文件夹为别名的路径(用于添加各个子文件夹为不同主题模板的情况)

func (*PathAliases) Aliases

func (p *PathAliases) Aliases() []string

Aliases 获取全部别名

func (*PathAliases) Parse

func (p *PathAliases) Parse(withAliasTagPath string) string

Parse 根据中括号别名前缀解析模板路径为实际存在的真实路径

func (*PathAliases) ParseOk

func (p *PathAliases) ParseOk(withAliasTagPath string) (string, bool)

ParseOk 根据中括号别名前缀解析模板路径为实际存在的真实路径

func (*PathAliases) ParsePrefix

func (p *PathAliases) ParsePrefix(withAliasPrefixPath string) string

ParsePrefix 根据模板路径子文件夹为别名解析模板路径为实际存在的真实路径

func (*PathAliases) ParsePrefixOk

func (p *PathAliases) ParsePrefixOk(withAliasPrefixPath string) (string, bool)

ParsePrefixOk 根据模板路径子文件夹为别名解析模板路径为实际存在的真实路径

func (*PathAliases) Range

func (p *PathAliases) Range(fn func(string, string) error) (err error)

Range 遍历全部别名及其模板文件夹路径

func (*PathAliases) Restore

func (p *PathAliases) Restore(fullpath string) string

Restore 还原真实路径为带中括号别名前缀的模板初始路径

func (*PathAliases) RestoreOk

func (p *PathAliases) RestoreOk(fullpath string) (string, bool)

RestoreOk 还原真实路径为带中括号别名前缀的模板初始路径

func (*PathAliases) RestorePrefix

func (p *PathAliases) RestorePrefix(fullpath string) string

RestorePrefix 还原真实路径为模板初始路径

func (*PathAliases) RestorePrefixOk

func (p *PathAliases) RestorePrefixOk(fullpath string) (string, bool)

RestorePrefixOk 还原真实路径为模板初始路径

func (*PathAliases) TmplDirs

func (p *PathAliases) TmplDirs() []string

TmplDirs 所有模板文件夹路径

type PathFixer added in v0.3.0

type PathFixer func(subdir, tmpl string) string

type PathFixers added in v0.3.0

type PathFixers map[string][]PathFixer //模版路径 {subdir:func}

func (*PathFixers) Add added in v0.3.0

func (p *PathFixers) Add(dirName string, fixer PathFixer) *PathFixers

func (*PathFixers) AddDir added in v0.3.0

func (p *PathFixers) AddDir(dirName string, parentPath string) *PathFixers

func (*PathFixers) Delete added in v0.3.0

func (p *PathFixers) Delete(names ...string) *PathFixers

func (*PathFixers) Fix added in v0.3.0

func (p *PathFixers) Fix(ctx echo.Context, t *Template, theme string, tmpl string) (string, bool)

Fix 模版路径修复

func (*PathFixers) Keys added in v0.3.0

func (p *PathFixers) Keys() []string

func (*PathFixers) MakeFixer added in v0.3.0

func (p *PathFixers) MakeFixer(parentPath string) PathFixer

type PathHandle added in v0.3.0

type PathHandle func(c echo.Context, theme string, tmpl string) string

type SortFileInfoByFileType added in v0.3.0

type SortFileInfoByFileType []FileInfo

func (SortFileInfoByFileType) Len added in v0.3.0

func (s SortFileInfoByFileType) Len() int

func (SortFileInfoByFileType) Less added in v0.3.0

func (s SortFileInfoByFileType) Less(i, j int) bool

func (SortFileInfoByFileType) Swap added in v0.3.0

func (s SortFileInfoByFileType) Swap(i, j int)

type StaticDir added in v0.3.0

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

func (*StaticDir) Open added in v0.3.0

func (s *StaticDir) Open(name string) (http.File, error)

type Storer added in v0.3.0

type Storer interface {
	Put(echo.Context, string, *ThemeInfo) error
	Get(echo.Context, string) (*ThemeInfo, error)
}

func NewFileStore added in v0.3.0

func NewFileStore(kind string) Storer

type Template added in v0.3.0

type Template struct {
	TmplDir     string
	Kind        string
	PathAliases *PathAliases

	*PathFixers
	// contains filtered or unexported fields
}

func New added in v0.3.0

func New(kind string, pa *PathAliases, registerToGroup ...bool) *Template

func (*Template) AddAlias added in v0.3.0

func (t *Template) AddAlias(alias, tmplDir string) *Template

func (*Template) AddAliasFromAllSubdir added in v0.3.0

func (t *Template) AddAliasFromAllSubdir(tmplDir string) *Template

func (*Template) Aliases added in v0.3.0

func (t *Template) Aliases() []string

func (*Template) ApplyAliases added in v0.3.0

func (t *Template) ApplyAliases() *Template

func (*Template) ClearCache added in v0.3.0

func (t *Template) ClearCache()

func (*Template) Fix added in v0.3.0

func (t *Template) Fix(ctx echo.Context, _ http.FileSystem, theme string, tmpl string) (string, bool)

func (*Template) Handle added in v0.3.0

func (t *Template) Handle(ctx echo.Context, theme string, tmpl string) string

func (*Template) Register added in v0.3.0

func (t *Template) Register(renderer driver.Driver, watchOtherDirs ...string)

func (*Template) SetCustomFS added in v0.3.0

func (t *Template) SetCustomFS(fs http.FileSystem) *Template

func (*Template) SetEnableTheme added in v0.3.0

func (t *Template) SetEnableTheme(enable bool) *Template

func (*Template) SetHandler added in v0.3.0

func (t *Template) SetHandler(h PathHandle) *Template

func (*Template) SetPathFixers added in v0.3.0

func (t *Template) SetPathFixers(h *PathFixers) *Template

func (*Template) SetStorer added in v0.3.0

func (t *Template) SetStorer(storer Storer) *Template

func (*Template) SetThemeInfo added in v0.3.0

func (t *Template) SetThemeInfo(c echo.Context, v *ThemeInfo)

func (*Template) SetTmplDir added in v0.3.0

func (t *Template) SetTmplDir(tmplDir string) *Template

func (*Template) Storer added in v0.3.0

func (t *Template) Storer() Storer

func (*Template) ThemeInfo added in v0.3.0

func (t *Template) ThemeInfo(c echo.Context) *ThemeInfo

func (*Template) TmplDirs added in v0.3.0

func (t *Template) TmplDirs() []string

type ThemeAuthor added in v0.3.0

type ThemeAuthor struct {
	Name        string `json:"name,omitempty"`        // 作者网名
	Email       string `json:"email,omitempty"`       // 作者E-mail地址
	URL         string `json:"url,omitempty"`         // 作者网址
	Description string `json:"description,omitempty"` // 作者简介
}

type ThemeColor added in v0.3.0

type ThemeColor struct {
	Name         string `json:"name,omitempty"`         // 颜色英文名(用于调用相应颜色的css文件)
	Title        string `json:"title,omitempty"`        // 颜色中文标题
	IsDefault    bool   `json:"isDefault,omitempty"`    // 是否为默认颜色
	Color        string `json:"color,omitempty"`        // 颜色值
	PreviewImage string `json:"previewImage,omitempty"` // 预览图
}

func (ThemeColor) HexColor added in v0.3.0

func (t ThemeColor) HexColor() string

type ThemeColors added in v0.3.0

type ThemeColors []ThemeColor

func (ThemeColors) HasName added in v0.3.0

func (t ThemeColors) HasName(colorName string, notDefault ...bool) bool

type ThemeInfo added in v0.3.0

type ThemeInfo struct {
	Author       ThemeAuthor                  `json:"author,omitempty"`       // 模板作者
	Colors       ThemeColors                  `json:"colors,omitempty"`       // 多种颜色主题时,所有支持的颜色信息
	Version      string                       `json:"version,omitempty"`      // 版本号(格式: 1.0.0)
	Name         string                       `json:"name"`                   // 主题英文名
	Title        string                       `json:"title"`                  // 主题中文标题
	UpdatedAt    string                       `json:"updatedAt,omitempty"`    // 更新时间(格式: 2006-01-02 15:04:05)
	Description  string                       `json:"description,omitempty"`  // 简介
	PreviewImage string                       `json:"previewImage,omitempty"` // 预览图
	PreviewURL   string                       `json:"previewURL,omitempty"`   // 预览网址
	CustomConfig echo.H                       `json:"customConfig,omitempty"` // 可自定义配置的数据
	FormConfig   map[string]formConfig.Config `json:"formConfig,omitempty"`   // 表单配置
	Fallback     []string                     `json:"fallback,omitempty"`     // 兜底主题
	// contains filtered or unexported fields
}

ThemeInfo 模板主题信息

func GetThemeInfoFromContext added in v0.3.0

func GetThemeInfoFromContext(ctx echo.Context) *ThemeInfo

func NewThemeInfo added in v0.3.0

func NewThemeInfo() *ThemeInfo

func (*ThemeInfo) AsLite added in v0.3.0

func (t *ThemeInfo) AsLite() ThemeInfoLite

func (*ThemeInfo) ColorName added in v0.3.0

func (t *ThemeInfo) ColorName() string

func (*ThemeInfo) Decode added in v0.3.0

func (t *ThemeInfo) Decode(b []byte) error

func (*ThemeInfo) DecodeFile added in v0.3.0

func (t *ThemeInfo) DecodeFile(file string) error

func (*ThemeInfo) Embed added in v0.3.0

func (t *ThemeInfo) Embed() bool

func (*ThemeInfo) Encode added in v0.3.0

func (t *ThemeInfo) Encode() []byte

func (*ThemeInfo) EncodeToFile added in v0.3.0

func (t *ThemeInfo) EncodeToFile(destFile string) error

func (*ThemeInfo) HasColorName added in v0.3.0

func (t *ThemeInfo) HasColorName(colorName string, notDefault ...bool) bool

func (*ThemeInfo) HasForm added in v0.3.0

func (t *ThemeInfo) HasForm(templateName string) bool

func (*ThemeInfo) IsColorName added in v0.3.0

func (t *ThemeInfo) IsColorName(colorName string) bool

func (*ThemeInfo) Render added in v0.3.0

func (t *ThemeInfo) Render(templateName string) template.HTML

func (*ThemeInfo) SaveForm added in v0.3.0

func (t *ThemeInfo) SaveForm(ctx echo.Context, templateName string, gets ...func(fieldName string, fieldValue string) error) error

func (*ThemeInfo) SetEmbed added in v0.3.0

func (t *ThemeInfo) SetEmbed() *ThemeInfo

type ThemeInfoLite added in v0.3.0

type ThemeInfoLite struct {
	Name         string `json:"name"`         // 主题英文名
	Title        string `json:"title"`        // 主题中文标题
	PreviewImage string `json:"previewImage"` // 预览图
}

Jump to

Keyboard shortcuts

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