Documentation ¶
Overview ¶
Package rendergold provides a Martini middleware/handler for parsing Gold templates and rendering HTML.
package main import ( "github.com/go-martini/martini" "github.com/yosssi/rendergold" ) func main() { m := martini.Classic() m.Use(rendergold.Renderer()) // reads "templates" directory by default m.Get("/", func(r rendergold.Render) { r.HTML(200, "mytemplate", nil) }) m.Run() }
Index ¶
Constants ¶
const ( // NameContentDelim is a delimiter for a combination of // a template name and its content. NameContentDelim = "@@@@" )
Variables ¶
This section is empty.
Functions ¶
func Renderer ¶
Renderer is a Middleware that maps a render.Render service into the Martini handler chain. An single variadic rendergold.Options struct can be optionally provided to configure HTML rendering. The default directory for templates is "templates" and the default file extension is ".gold".
If MARTINI_ENV is set to "" or "development" then templates will be parsed every request. For more performance, set the MARTINI_ENV environment variable to "production"
Types ¶
type Options ¶
type Options struct { // Directory to load templates. Default is "templates" Directory string // Funcs is a slice of FuncMaps to apply to the template upon compilation. This is useful for helper functions. Defaults to []. Func template.FuncMap // Appends the given charset to the Content-Type header. Default is "UTF-8". Charset string // Allows changing of output to XHTML instead of HTML. Default is "text/html" HTMLContentType string // Asset loads and returns the asset for the given name. Asset func(string) ([]byte, error) }
Options is a struct for specifying configuration options for the render.Renderer middleware
type Render ¶
type Render interface { // HTML renders a html template specified by the name and writes the result and given status to the http.ResponseWriter. HTML(status int, name string, v interface{}, htmlOpt ...render.HTMLOptions) // Redirect redirects the request. Redirect(location string, status ...int) }
Render is a service that can be injected into a Martini handler. Render provides functions for easily writing HTML templates out to a http Response.