et

package module
v0.0.0-...-3ead36b Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2024 License: MIT Imports: 16 Imported by: 4 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 NewFSLoaderWithNS

func NewFSLoaderWithNS(fsys fs.FS) (*FileSystemLoader, error)

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
⌂ 换网址