render

package
v0.0.0-...-a52fffe Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetExt

func GetExt(s string) string

func HTML

func HTML(name string, data interface{}) ([]byte, error)

func IsDir

func IsDir(dir string) bool

IsDir returns true if given path is a directory, and returns false when it's a file or does not exist.

func IsExist

func IsExist(path string) bool

IsExist returns true if a file or directory exists.

func IsFile

func IsFile(path string) bool

IsFile returns true if given path exists as a file (i.e. not a directory).

func NewFile

func NewFile(name string, data []byte, ext string) *file

NewTplFile cerates new template file with given name and data.

func Renderer

func Renderer(opt Options)

Types

type CALLBACK

type CALLBACK func() []File

type Delims

type Delims struct {
	// Left delimiter, defaults to {{
	Left string
	// Right delimiter, defaults to }}
	Right string
}

Delims represents a set of Left and Right delimiters for HTML template rendering

type File

type File interface {
	Name() string
	Data() []byte
	Ext() string
}

File represents a interface of template file that has name and can be read.

type FileSystem

type FileSystem interface {
	Files() []File
	Get(string) (io.Reader, error)
}

FileSystem represents a interface of template file system that able to list all files.

func NewCbFS

func NewCbFS(cb CALLBACK, omitData bool) FileSystem

func NewFS

func NewFS(opt Options, omitData bool) FileSystem

NewTemplateFileSystem creates new template file system with given options.

type Options

type Options struct {
	// Directory to load templates. Default is "templates".
	Directory string
	// Addtional directories to overwite templates.
	AppendDirectories []string
	// Layout template name. Will not render a layout if "". Default is to "".
	Layout string
	// Extensions to parse template files from. Defaults are [".tmpl", ".html"].
	Extensions []string
	// Funcs is a slice of FuncMaps to apply to the template upon compilation. This is useful for helper functions. Default is [].
	Funcs []template.FuncMap
	// Delims sets the action delimiters to the specified strings in the Delims struct.
	Delims Delims
	// Appends the given charset to the Content-Type header. Default is "UTF-8".
	Charset string
	// Outputs human readable JSON.
	IndentJSON bool
	// Outputs human readable XML.
	IndentXML bool
	// Prefixes the JSON output with the given bytes.
	PrefixJSON []byte
	// Prefixes the XML output with the given bytes.
	PrefixXML []byte
	// Allows changing of output to XHTML instead of HTML. Default is "text/html"
	HTMLContentType string
	// FileSystem is the interface for supporting any implmentation of template file system.
	FileSystem
}

RenderOptions represents a struct for specifying configuration options for the Render middleware.

Jump to

Keyboard shortcuts

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