et

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

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

Go to latest
Published: Feb 15, 2024 License: MIT Imports: 16 Imported by: 3

README

Extends Template

Build Status codecov License

"Extends Template" is a library that enhances template functionality by introducing an "extends" directive and automatically loading dependent HTML templates.

Installation

go get github.com/gowool/extends-template

License

Distributed under MIT License, please see license file within the code for more details.

Documentation

Index

Constants

View Source
const (
	ErrNotDefinedFormat   = "template \"%s\" is not defined"
	ErrDirNotExistsFormat = "the \"%s\" directory does not exist"
)
View Source
const BaseNamespace = "base"

Variables

This section is empty.

Functions

This section is empty.

Types

type ChainLoader

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

func NewChainLoader

func NewChainLoader(loaders ...Loader) *ChainLoader

func (*ChainLoader) Add

func (l *ChainLoader) Add(loader Loader) *ChainLoader

func (*ChainLoader) Exists

func (l *ChainLoader) Exists(ctx context.Context, name string) (bool, error)

func (*ChainLoader) Get

func (l *ChainLoader) Get(ctx context.Context, name string) (*Source, error)

func (*ChainLoader) IsFresh

func (l *ChainLoader) IsFresh(ctx context.Context, name string, t int64) (bool, error)

func (*ChainLoader) Loaders

func (l *ChainLoader) Loaders() (loaders []Loader)

type Environment

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

func NewEnvironment

func NewEnvironment(loader Loader, handlers ...Handler) *Environment

func (*Environment) Debug

func (e *Environment) Debug(debug bool) *Environment

func (*Environment) Delims

func (e *Environment) Delims(left, right string) *Environment

func (*Environment) Funcs

func (e *Environment) Funcs(funcMap template.FuncMap) *Environment

func (*Environment) Global

func (e *Environment) Global(global ...string) *Environment

func (*Environment) Load

func (e *Environment) Load(ctx context.Context, name string) (*TemplateWrapper, error)

func (*Environment) NewHTMLTemplate

func (e *Environment) NewHTMLTemplate(name string) *template.Template

func (*Environment) NewTemplateWrapper

func (e *Environment) NewTemplateWrapper(name string) *TemplateWrapper

type FilesystemLoader

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

func NewFilesystemLoader

func NewFilesystemLoader(fsys fs.FS) *FilesystemLoader

func (*FilesystemLoader) Append

func (l *FilesystemLoader) Append(namespace, p string) error

func (*FilesystemLoader) BaseAppend

func (l *FilesystemLoader) BaseAppend(path string) error

func (*FilesystemLoader) BasePrepend

func (l *FilesystemLoader) BasePrepend(path string) error

func (*FilesystemLoader) Exists

func (l *FilesystemLoader) Exists(_ context.Context, name string) (bool, error)

func (*FilesystemLoader) Get

func (l *FilesystemLoader) Get(_ context.Context, name string) (*Source, error)

func (*FilesystemLoader) IsFresh

func (l *FilesystemLoader) IsFresh(_ context.Context, name string, t int64) (bool, error)

func (*FilesystemLoader) Namespaces

func (l *FilesystemLoader) Namespaces() (namespaces []string)

func (*FilesystemLoader) Paths

func (l *FilesystemLoader) Paths(namespace string) (paths []string)

func (*FilesystemLoader) Prepend

func (l *FilesystemLoader) Prepend(namespace, p string) (err error)

func (*FilesystemLoader) SetPaths

func (l *FilesystemLoader) SetPaths(namespace string, paths ...string) error

type Handler

type Handler func(ctx context.Context, node *Node, namespace string) error

type Loader

type Loader interface {
	// Get returns a Source for a given template name
	Get(ctx context.Context, name string) (*Source, error)

	// IsFresh check if template is fresh
	IsFresh(ctx context.Context, name string, t int64) (bool, error)

	// Exists check if template exists
	Exists(ctx context.Context, name string) (bool, error)
}

type MemoryLoader

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

func NewMemoryLoader

func NewMemoryLoader(templates map[string][]byte) *MemoryLoader

func (*MemoryLoader) Add

func (l *MemoryLoader) Add(name string, code []byte) *MemoryLoader

func (*MemoryLoader) Exists

func (l *MemoryLoader) Exists(_ context.Context, name string) (bool, error)

func (*MemoryLoader) Get

func (l *MemoryLoader) Get(_ context.Context, name string) (*Source, error)

func (*MemoryLoader) IsFresh

func (l *MemoryLoader) IsFresh(ctx context.Context, name string, _ int64) (bool, error)

type Node

type Node struct {
	Source    *Source
	Extends   *Node
	Successor *Node
	Includes  []*Node
	// contains filtered or unexported fields
}

func NewNode

func NewNode(name string, w *TemplateWrapper, successor *Node) *Node

func (*Node) Init

func (n *Node) Init(ctx context.Context) (err error)

func (*Node) Parse

func (n *Node) Parse(t *template.Template) error

func (*Node) SelfParent

func (n *Node) SelfParent() *Node

type Source

type Source struct {
	Code []byte
	Name string
	File string
}

type TemplateWrapper

type TemplateWrapper struct {
	HTML *template.Template
	// contains filtered or unexported fields
}

func NewTemplateWrapper

func NewTemplateWrapper(
	html *template.Template,
	loader Loader,
	handlers []Handler,
	reExtends *regexp.Regexp,
	reTemplate *regexp.Regexp,
	global ...string,
) *TemplateWrapper

func (*TemplateWrapper) IsFresh

func (w *TemplateWrapper) IsFresh(ctx context.Context) (ok bool)

func (*TemplateWrapper) Parse

func (w *TemplateWrapper) Parse(ctx context.Context) (err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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