tpl

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: MIT Imports: 36 Imported by: 0

README

GoDoc

Template engine for Go

This is a legacy template engine system, made to be compatible with an older version initially written in PHP.

It has reached end of line and as such release under MIT license has been decided.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BBCodeCompiler = bbcode.NewCompiler(true, true)
View Source
var (
	ErrTplNotFound = errors.New("tpl: Template not found")
)

Functions

func AsOutValue

func AsOutValue(ctx context.Context, v interface{}) *interfaceValue

func CallFunction

func CallFunction(ctx context.Context, funcName string, params Values, target WritableValue) error

func CompareValues

func CompareValues(ctx context.Context, o1, o2 interface{}) (bool, error)

func FormatSize

func FormatSize(v uint64) string

func LogWarn

func LogWarn(ctx context.Context, msg string, arg ...interface{})

func QueryEscapeAny

func QueryEscapeAny(ctx context.Context, val interface{}) string

func RegisterFilter

func RegisterFilter(name string, f TplFiltCallback)

func RegisterFunction

func RegisterFunction(name string, f *TplFunction)

func ResetServerCtx

func ResetServerCtx(ctx context.Context)

func ResolveValueIndex

func ResolveValueIndex(ctx context.Context, v any, s string) (any, error)

func ServerCtx

func ServerCtx(request *http.Request) context.Context

func ValuesCtx

func ValuesCtx(parent context.Context, values map[string]interface{}) context.Context

func ValuesCtxAlways

func ValuesCtxAlways(parent context.Context, values map[string]interface{}) context.Context

Types

type ArrayAccessGet

type ArrayAccessGet interface {
	OffsetGet(context.Context, string) (Value, error)
}

type ArrayAccessGetAny added in v1.0.5

type ArrayAccessGetAny interface {
	OffsetGet(context.Context, string) (any, error)
}

type CtxLog

type CtxLog interface {
	LogWarn(msg string, arg ...interface{})
}

type Error

type Error struct {
	Message    string
	Template   string
	Line, Char int
	Stack      []byte
	Parent     error
}

Error is a template error, containing details such as where an error occured in the template source and details on the actual error.

func (*Error) Error

func (e *Error) Error() string

func (*Error) String

func (e *Error) String() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Page

type Page struct {
	Version int // will be populated on compile
	Raw     RawData

	MaxProcess int // when running parallel compile (0=unlimited)
	// contains filtered or unexported fields
}

func New

func New() *Page

func (*Page) Compile

func (e *Page) Compile(ctx context.Context) error

func (*Page) Dump

func (e *Page) Dump(o io.Writer, lvl int)

func (*Page) GetMime

func (e *Page) GetMime() string

func (*Page) GetProperty

func (e *Page) GetProperty(p string) string

func (*Page) HasTpl

func (e *Page) HasTpl(tpl string) bool

func (*Page) Parse

func (e *Page) Parse(ctx context.Context, tpl string, out *interfaceValue) error

func (*Page) ParseAndReturn

func (e *Page) ParseAndReturn(ctx context.Context, tpl string) (string, error)

func (*Page) ParseAndWrite

func (e *Page) ParseAndWrite(ctx context.Context, tpl string, out io.Writer) error

type RawData

type RawData struct {
	PageProperties map[string]string // typically Charset=UTF-8 Content_Type=text/html
	TemplateData   map[string]string // actual contents for templates, at least "main" should be there
}

RawData contains the raw (uncompiled) data for current template

func (*RawData) FromDir

func (res *RawData) FromDir(d ...string) error

func (*RawData) FromVfs

func (res *RawData) FromVfs(fs vfs.FileSystem, d ...string) error

func (*RawData) FromZip

func (res *RawData) FromZip(z *zip.Reader, d ...string) error

func (*RawData) IsValid

func (r *RawData) IsValid() bool

type TplCtxValue

type TplCtxValue int
const (
	TplCtxLog TplCtxValue = iota + 1
)

type TplFiltCallback

type TplFiltCallback func(ctx context.Context, params Values, in Value, out WritableValue) error

type TplFuncCallback

type TplFuncCallback func(ctx context.Context, params Values, out WritableValue) error

type TplFunction

type TplFunction struct {
	Method     TplFuncCallback
	CanCompile bool
}

type Value

type Value interface {
	ReadValue(ctx context.Context) (interface{}, error)
	WithCtx(ctx context.Context) *ValueCtx
}

func NewValue

func NewValue(v interface{}) Value

type ValueCtx

type ValueCtx struct {
	Value
	// contains filtered or unexported fields
}

func NewValueCtx

func NewValueCtx(ctx context.Context, v Value) *ValueCtx

func (*ValueCtx) Bytes

func (v *ValueCtx) Bytes() []byte

func (*ValueCtx) BytesErr

func (v *ValueCtx) BytesErr() ([]byte, error)

func (*ValueCtx) IsString

func (v *ValueCtx) IsString() bool

IsString checks if the raw value is either a string, or an interface made to return a string

func (*ValueCtx) MarshalJSON

func (v *ValueCtx) MarshalJSON() ([]byte, error)

func (*ValueCtx) MatchValueType

func (v *ValueCtx) MatchValueType(t interface{}) (interface{}, error)

func (*ValueCtx) Raw

func (v *ValueCtx) Raw() (interface{}, error)

func (*ValueCtx) String

func (v *ValueCtx) String() string

func (*ValueCtx) StringErr

func (v *ValueCtx) StringErr() (string, error)

func (*ValueCtx) ToBool

func (v *ValueCtx) ToBool() bool

func (*ValueCtx) ToFloat

func (v *ValueCtx) ToFloat() (float64, bool)

func (*ValueCtx) ToInt

func (v *ValueCtx) ToInt() (int64, bool)

type ValueReader added in v1.0.2

type ValueReader interface {
	ReadValue(ctx context.Context) (interface{}, error)
}

type Values

type Values []Value

type WritableValue

type WritableValue interface {
	Value
	Printf(fmt string, arg ...interface{}) (int, error)
	Write([]byte) (int, error)
	WriteValue(context.Context, interface{}) error
}

func NewEmptyValue

func NewEmptyValue() WritableValue

Jump to

Keyboard shortcuts

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