pages

package
v0.0.0-...-e7b361f Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2018 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package pages provides template loading and rendering.

Index

Constants

This section is empty.

Variables

View Source
var ReloadTemplates = false

ReloadTemplates is a flag for whether NewPage should reload templates on every request. Reloading templates is useful to see changes without recompiling. In production, reloading should be disabled.

Functions

This section is empty.

Types

type Breadcrumb struct {
	Title string
	URL   *url.URL
}

Breadcrumb represents a navigation breadcrumb.

type Breadcrumbs []*Breadcrumb

Breadcrumbs manages navigation breadcrumbs.

func (b *Breadcrumbs) Add(breadcrumbs ...*Breadcrumb)

Add adds breadcrumbs.

func (b *Breadcrumbs) AddNew(title string, url *url.URL) *Breadcrumb

AddNew creates a new breadcrumb and adds it.

func (b *Breadcrumbs) GetAll() []*Breadcrumb

GetAll returns all breadcrumbs.

func (b *Breadcrumbs) Remove(breadcrumbs ...*Breadcrumb)

Remove removes breadcrumbs.

func (b *Breadcrumbs) RemoveAll()

RemoveAll removes all breadcrumbs.

type Page

type Page struct {
	// BaseURL to prepend to redirect URL.
	BaseURL string

	// Breadcrumbs represent a hierarchical navigation.
	Breadcrumbs *Breadcrumbs

	// Data for populating the template.
	Data map[string]interface{}

	// Form helper for creating HTML input elements in the template.
	Form *forms.Form

	// Language to use for displaying text.
	Language *languages.Language

	// Name of the page. Useful for styling links to the current page
	// differently.
	Name string

	// Session associated with the request.
	Session sessions.Session

	// Template to render when calling Serve.
	Template *Template

	// Title of the page. Useful for populating the HTML title element.
	Title string
	// contains filtered or unexported fields
}

Page represents an HTML page.

func NewPage

func NewPage(writer http.ResponseWriter, request *http.Request, tpl *Template) *Page

NewPage returns a new Page.

func (*Page) FlashAll

func (p *Page) FlashAll() ([]sessions.Flash, error)

FlashAll returns all flashes, removes them from session and saves the session if necessary.

func (*Page) Redirect

func (p *Page) Redirect(code int, destination string, args ...interface{}) error

Redirect redirects the client to destination, using code as HTTP status code. If args is provided, destination is formatted with fmt.Sprintf, to which args is passed. destination is automatically prefixed with p.BaseURL.

func (*Page) Serve

func (p *Page) Serve() error

Serve serves the page.

func (*Page) T

func (p *Page) T(translationID string, templateData ...map[string]interface{}) string

T returns the translation associated with translationID. If none is associated, it returns translationID.

type Template

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

Template is a collection of (nested) template files.

func MustNewTemplate

func MustNewTemplate(funcMap template.FuncMap, paths ...string) *Template

MustNewTemplate calls NewTemplate. It panics on error.

func NewTemplate

func NewTemplate(funcMap template.FuncMap, paths ...string) (*Template, error)

NewTemplate creates a template from template files specified by paths. If the template files are supposed to use functions other than the built-in Go functions, these functions must be provided through funcMap.

func (*Template) Reload

func (t *Template) Reload() error

Reload parses the template files again.

Jump to

Keyboard shortcuts

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