templates

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2022 License: MIT Imports: 17 Imported by: 0

README

go-templates

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTemplate = errors.New("template can't be nil")
	ErrName     = errors.New("template must have a name")
)
View Source
var (
	FuncMap = types.Map{

		"html": func(v string) template.HTML {
			return template.HTML(v)
		},

		"js": func(v interface{}) template.JS {
			encoded, _ := json.Marshal(v)
			return template.JS(encoded)
		},

		"sub": func(y, x int) int {
			return x - y
		},

		"ToLower": strings.ToLower,
		"ToUpper": strings.ToUpper,

		"Int":    convert.Int,
		"String": convert.String,
	}
)

Functions

func Gin

func Gin(cfg Config)

Gin creates a new renderer for gin-gonic framework.

Types

type Config

type Config struct {
	Layout    string
	Extension string
	Debug     bool // Debug mode will enable files watcher.
	Directory string
	Funcs     types.Map
}

type EchoRenderer

type EchoRenderer interface {
	Render(io.Writer, string, interface{}, echo.Context) error
}

func Echo

func Echo(cfg Config) EchoRenderer

Echo creates a new renderer for echo framework.

type Engine

type Engine interface {
	// Parse(tpl string, v interface{})
	Load(string) *template.Template
}

func Create

func Create(config Config) Engine

Create

type RenderFunc

type RenderFunc func(code int, name string, data interface{}) error

RenderFunc

type Renderer

type Renderer interface {
	Set(key string, v interface{})
	Parse404() error
	Parse500() error
	Parse(code int, name string, values ...map[string]interface{}) error
	AddPostParsing(...func(data types.TSafeMap) error)
}

Renderer

func New

func New(rf RenderFunc) Renderer

New creates a new Renderer with the given callback.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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