view: github.com/fragmenta/view Index | Files | Directories

package view

import "github.com/fragmenta/view"

Package view provides methods for rendering templates, and helper functions for golang views

Index

Package Files

deprecated.go render.go view.go

Variables

var AuthenticityContext = &ctxKey{authenticityKey}

AuthenticityContext is used as a key to save request authenticity tokens for consumption by the view

var Helpers parser.FuncMap

Helpers is a list of functions available in templates

var Production bool

Production is true if this server is running in production mode

func DefaultHelpers Uses

func DefaultHelpers() parser.FuncMap

DefaultHelpers returns a default set of helpers for the app, which can then be extended/replaced. Helper functions may not be changed after LoadTemplates is called, as reloading is required if they change.

func LoadTemplates Uses

func LoadTemplates() error

LoadTemplates loads our templates from ./src, and assigns them to the package variable Templates This function is deprecated and will be removed, use LoadTemplatesAtPaths instead

func LoadTemplatesAtPaths Uses

func LoadTemplatesAtPaths(paths []string, helpers parser.FuncMap) error

LoadTemplatesAtPaths loads our templates given the paths provided

func PrintTemplates Uses

func PrintTemplates()

PrintTemplates prints out our list of templates for debug

func ReloadTemplates Uses

func ReloadTemplates() error

ReloadTemplates reloads the templates for our scanner

type RenderContext Uses

type RenderContext interface {
    Path() string
    RenderContext() map[string]interface{}
    Writer() http.ResponseWriter
}

RenderContext is the type passed in to New, which helps construct the rendering view Alternatively, you can use NewWithPath, which doesn't require a RenderContext

type Renderer Uses

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

Renderer is a view which is set up on each request and renders the response to its writer

func New Uses

func New(c RenderContext) *Renderer

New creates a new Renderer

func NewRenderer Uses

func NewRenderer(w http.ResponseWriter, r *http.Request) *Renderer

NewRenderer returns a new renderer for this request.

func NewWithPath Uses

func NewWithPath(p string, w http.ResponseWriter) *Renderer

NewWithPath creates a new Renderer with a path and an http.ResponseWriter

func (*Renderer) AddKey Uses

func (r *Renderer) AddKey(key string, value interface{}) *Renderer

AddKey adds a key/value pair to context

func (*Renderer) CacheKey Uses

func (r *Renderer) CacheKey(key string)

CacheKey sets the Cache-Control and Etag headers on the response using the CacheKey() from the Cacher passed in

func (*Renderer) Context Uses

func (r *Renderer) Context(c map[string]interface{}) *Renderer

Context sets the entire context for rendering

func (*Renderer) Format Uses

func (r *Renderer) Format(format string) *Renderer

Format sets the format used, e.g. text/html,

func (*Renderer) HTML Uses

func (r *Renderer) HTML(content string) *Renderer

HTML sets the view content as html (use with caution)

func (*Renderer) Header Uses

func (r *Renderer) Header(k, v string) *Renderer

Header sets a header on the Renderer's Writer (if set)

func (*Renderer) Layout Uses

func (r *Renderer) Layout(layout string) *Renderer

Layout sets the layout used

func (*Renderer) Path Uses

func (r *Renderer) Path(p string) *Renderer

Path sets the request path on the renderer (used for choosing a default template)

func (*Renderer) Render Uses

func (r *Renderer) Render() error

Render our template into layout using our context and write out to writer

func (*Renderer) RenderToString Uses

func (r *Renderer) RenderToString() (string, error)

RenderToString renders our template into layout using our context and return a string

func (*Renderer) RenderToStringWithLayout Uses

func (r *Renderer) RenderToStringWithLayout() (string, error)

RenderToStringWithLayout renders our template into layout using our context and return a string

func (*Renderer) Response Uses

func (r *Renderer) Response() error

Response renders our template into layout using our context and write out to writer Response is an alternative name for Render so that we can call render.Response(), it may replace it eventually.

func (*Renderer) SendFile Uses

func (r *Renderer) SendFile(p string) error

SendFile writes the file at the given path out to our writer it assumes the appropriate headers have been set first (Content-Type, Content-Disposition) e.g.:

	view.Header("Content-type", "application/pdf")
	view.Header("Content-Disposition", "attachment; filename='myfile.pdf'")
 view.SendFile(mypath)

func (*Renderer) Status Uses

func (r *Renderer) Status(status int) *Renderer

Status sets the Renderer status

func (*Renderer) Template Uses

func (r *Renderer) Template(template string) *Renderer

Template sets the template used

func (*Renderer) Text Uses

func (r *Renderer) Text(content string) *Renderer

Text sets the view content as text

Directories

PathSynopsis
helpers
parserPackage parser defines an interface for parsers which the base template conforms to
translationPackage translation provides a simple in-memory translation service - it may soon be renamed translate

Package view imports 12 packages (graph) and is imported by 25 packages. Updated 2018-04-09. Refresh now. Tools for package owners.