Documentation
¶
Overview ¶
Package multirender is a middleware for Martini that provides HTML templates through multitemplate, it like to imitate and build on the render package from martini-contrib.
package main
import (
"github.com/codegangsta/martini" "github.com/cooldude/cache" // contians the multirender package. "github.com/acsellers/multitemplate/martini" // import any languages you want to use _ "github.com/acsellers/multitemplate/terse"
)
func main() {
app := martini.Classic()
app.Use(multirender.Renderer())
app.Get("/", func (mr multirender.Render) {
mr.HTML(200, "app/index.html", nil)
})
app.Get("/admins", func(mr multirender.Render) {
ctx := mr.NewContext()
ctx.RenderArgs["Users"] = AdminUsers
mr.HTML(200, "app/user_list.html", ctx)
})
app.Run()
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Context ¶
type Context struct {
Status int
Layout string
NoLayout bool
Yields map[string]string
RenderArgs map[string]interface{}
// contains filtered or unexported fields
}
func (*Context) SetContent ¶
func (*Context) SetTemplate ¶
type Options ¶
type Options struct {
// Directories to search for template files
Directories []string
// Layout to render by default
DefaultLayout string
// Helper modules to load from multitemplate helpers
Helpers []string
// Additional functions to add
Funcs template.FuncMap
// JSON & XML indentation, an empty string disables indentation
IndentEncoding string
// Default is set to utf-8
Charset string
}
type Render ¶
type Render interface {
// JSON writes the status code and JSON version of the value to the
// http.ResponseWriter
JSON(status int, v interface{})
// XML writes the status code and XML version of the value to the
// http.ResponseWriter
XML(status int, v interface{})
// HTML render the template given by name, with the status and options
// given.
HTML(status int, name string, htmlOpt *Context)
// Create a Context with default options set
NewContext() *Context
// Render the text to the output
Text(status int, text string)
// Write the given status to the Response
Error(status int)
// Redirect to the location with an optional status, default status is
// 302.
Redirect(location string, status ...int)
// Return the Template by name
Template() *multitemplate.Template
// Sets the content type, will also append charset from Options
SetContentType(string)
}
Click to show internal directories.
Click to hide internal directories.