handlers

package
v0.0.0-...-c6e3130 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: Apache-2.0 Imports: 3 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Funcs = []template.FuncMap{
	template.FuncMap(map[string]interface{}{
		"Pluralize": func(num int, singular, plural string) string {
			if num == 1 {
				return singular
			}
			return plural
		},
	}),
}

Functions

func Candies

func Candies(ren Renderer) http.Handler

func Index

func Index(ren Renderer) http.Handler

Types

type RenderRenderer

type RenderRenderer struct {
	// contains filtered or unexported fields
}

RenderRenderer is a Renderer implementation that uses unrolled/render (https://godoc.org/github.com/unrolled/render#Render.HTML) to do template rendering

func NewRenderRenderer

func NewRenderRenderer(dir string, extensions []string, funcs []template.FuncMap, dev bool) *RenderRenderer

NewRenderRenderer returns a new RenderRenderer, where the underlying render.Render serves templates out of dir with the given func map. it's configured in dev mode according to the dev boolean

func (*RenderRenderer) Render

func (r *RenderRenderer) Render(w http.ResponseWriter, code int, templateName string, data interface{}, layout string)

Render is the interface implementation

type Renderer

type Renderer interface {
	// Render renders a template with data and passes the rendered result to w with the given code.
	// if layout is non-empty, this func renders the template with that name, and the templateName
	// is rendered under the {{yield}} block. otherwise this func renders the template called templateName
	Render(w http.ResponseWriter, code int, templateName string, data interface{}, layout string)
}

Renderer is the interface to rendering templates. This example repository has an unrolled/render (https://godoc.org/github.com/unrolled/render) implementation, but other implementations are certainly possible

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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