multirender

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: May 2, 2014 License: BSD-2-Clause Imports: 13 Imported by: 0

README

Martini + Multitemplate

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()
}

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

func Renderer

func Renderer(opt Options) martini.Handler

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 (c *Context) SetContent(name, content string)

func (*Context) SetTemplate

func (c *Context) SetTemplate(blockName, templateName string)

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)
}

Directories

Path Synopsis
This example is converted from my redup package github.com/acsellers/redup
This example is converted from my redup package github.com/acsellers/redup

Jump to

Keyboard shortcuts

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