templates

package
v0.0.0-...-206e6e4 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2016 License: BSD-3-Clause Imports: 8 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTemplateNotExist = errors.New("template does not exist")
	ErrDirNotExist      = errors.New("directory does not exist")
)

Functions

func Compile

func Compile(path, base string) error

Compile a single template file, using the specified base directory. The base directory is used to set the name of the template (the part of the path relative to this base directory is used as the name of the template).

func CompileDir

func CompileDir(dir string) error

Compile all templates that have a matching compiler (based on their extension) in the specified directory.

func Execute

func Execute(tplName string, w io.Writer, data interface{}) error

Execute the template.

func Register

func Register(ext string, c TemplateCompiler)

Register a template compiler for the specified extension. Extensions are case-sensitive. The extension must start with a dot (it is compared to the result of path.Ext() on a given file name).

Registering is not thread-safe. Compilers should be registered before the http server is started. Compiling templates, on the other hand, is thread-safe.

func Render

func Render(tplName string, w http.ResponseWriter, data interface{}) (err error)

Render is the same as Execute, except that it takes a http.ResponseWriter instead of a generic io.Writer, and sets the Content-Type to text/html.

Types

type TemplateCompiler

type TemplateCompiler interface {
	Compile(fileName string) (Templater, error)
}

The interface that a template engine must implement to be used by Ghost.

type Templater

type Templater interface {
	Execute(wr io.Writer, data interface{}) error
}

Defines the interface that the template compiler must return. The Go native templates implement this interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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