djinn

package module
v0.0.0-...-174ff8a Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2017 License: MIT Imports: 11 Imported by: 0

README

Djinn

Build Status GoDoc Coverage Status license

html templating tools with nesting, caching and multiple loaders using the Go html/template library

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	NilTemplateError   = Drror("nil template named %s").Out
	NoTemplateError    = Drror("no template named %s").Out
	EmptyTemplateError = Drror("empty template named %s").Out
	ConfigurationError = Drror("Could not configure: %s").Out
)
View Source
var NoLoadMethod = Drror("load method not implemented")
View Source
var PathError = Drror("path: %s returned error").Out

Functions

func Drror

func Drror(err string) *xrror

func TLRUCache

func TLRUCache(maxentries int, on bool) *tlruCache

Returns a TLRU cache interface

Types

type BaseLoader

type BaseLoader struct {
	Errors         []error
	FileExtensions []string
}

func (*BaseLoader) ListTemplates

func (b *BaseLoader) ListTemplates() []string

func (*BaseLoader) Load

func (b *BaseLoader) Load(name string) (string, error)

func (*BaseLoader) ValidExtension

func (b *BaseLoader) ValidExtension(ext string) bool

type Cache

type Cache interface {
	Add(string, *template.Template)
	Get(string) (*template.Template, bool)
	Remove(string)
	Clear()
	On() bool
	SetCaching(bool)
}

Cache is an interface to template caching.

type Config

type Config interface {
	Order() int
	Configure(*Djinn) error
}

func DefaultConfig

func DefaultConfig(fn ConfigFn) Config

func NewConfig

func NewConfig(order int, fn ConfigFn) Config

func SetCache

func SetCache(c Cache) Config

func SetLoaders

func SetLoaders(l ...Loader) Config

func SetTemplateFunctions

func SetTemplateFunctions(f ...map[string]interface{}) Config

type ConfigFn

type ConfigFn func(*Djinn) error

type Configuration

type Configuration interface {
	AddConfig(...Config)
	AddFn(...ConfigFn)
	Configure() error
	Configured() bool
}

type Djinn

type Djinn struct {
	Configuration
	*LoaderSet
	*FuncSet
	Cache
}

The primary renderer, containing loaders, template functions, cache, & configuration.

func Empty

func Empty(cnf ...Config) *Djinn

Empty returns an empty Djinn with provided Config applied immediately.

func New

func New(cnf ...Config) *Djinn

New provides a Djinn with default configuration.

func (*Djinn) Fetch

func (d *Djinn) Fetch(name string) (*template.Template, error)

Given a string name, Fetch attempts to get a *template.Template from cache or loaders, returning any error.

func (*Djinn) Render

func (d *Djinn) Render(w io.Writer, name string, data interface{}) error

Render excutes the template specified by name, with the supplied writer and data. Template is searched for in the cache, if enabled, then from assembling the from the tempalte Djinn loaders. Returns any ocurring errors.

type FuncSet

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

func NewFuncSet

func NewFuncSet() *FuncSet

func (*FuncSet) AddFuncs

func (f *FuncSet) AddFuncs(fns map[string]interface{})

func (*FuncSet) GetFuncs

func (f *FuncSet) GetFuncs() map[string]interface{}

type Loader

type Loader interface {
	Load(string) (string, error)
	ListTemplates() []string
}

func DirLoader

func DirLoader(paths ...string) Loader

func MapLoader

func MapLoader(tm ...map[string]string) Loader

type LoaderSet

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

func NewLoaderSet

func NewLoaderSet() *LoaderSet

func (*LoaderSet) AddLoaders

func (l *LoaderSet) AddLoaders(ls ...Loader)

func (*LoaderSet) GetLoaders

func (l *LoaderSet) GetLoaders(ls ...Loader) []Loader

type Node

type Node struct {
	Name string
	Src  string
}

Jump to

Keyboard shortcuts

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