buffalo: github.com/gobuffalo/buffalo/render Index | Files

package render

import "github.com/gobuffalo/buffalo/render"

Index

Package Files

auto.go download.go func.go helpers.go html.go js.go json.go options.go plain.go render.go renderer.go sse.go string.go string_map.go template.go template_engine.go template_helpers.go xml.go

func GoTemplateEngine Uses

func GoTemplateEngine(input string, data map[string]interface{}, helpers map[string]interface{}) (string, error)

GoTemplateEngine implements the TemplateEngine interface for using standard Go templates

func MDTemplateEngine Uses

func MDTemplateEngine(input string, data map[string]interface{}, helpers map[string]interface{}) (string, error)

MDTemplateEngine runs the input through github flavored markdown before sending it to the Plush engine.

type Data Uses

type Data map[string]interface{}

Data type to be provided to the Render function on the Renderer interface.

type Engine Uses

type Engine struct {
    Options
}

Engine used to power all defined renderers. This allows you to configure the system to your preferred settings, instead of just getting the defaults.

func New Uses

func New(opts Options) *Engine

New render.Engine ready to go with your Options and some defaults we think you might like.

func (*Engine) Auto Uses

func (e *Engine) Auto(ctx context.Context, i interface{}) Renderer

Auto figures out how to render the model based information about the request and the name of the model. Auto supports automatic rendering of HTML, JSON, and XML. Any status code give to Context#Render between 300 - 400 will be respected by Auto. Other status codes are not.

# Rules for HTML template lookup: GET /users - users/index.html GET /users/id - users/show.html GET /users/new - users/new.html GET /users/id/edit - users/edit.html POST /users - (redirect to /users/id or render user/new.html) PUT /users/edit - (redirect to /users/id or render user/edit.html) DELETE /users/id - redirect to /users

func (*Engine) Download Uses

func (e *Engine) Download(ctx context.Context, name string, r io.Reader) Renderer

Download renders a file attachment automatically setting following headers:

Content-Type
Content-Length
Content-Disposition

Content-Type is set using mime#TypeByExtension with the filename's extension. Content-Type will default to application/octet-stream if using a filename with an unknown extension.

func (*Engine) Func Uses

func (e *Engine) Func(s string, fn RendererFunc) Renderer

Func renderer allows for easily building one of renderers using just a RendererFunc and not having to build a whole implementation of the Render interface.

func (*Engine) HTML Uses

func (e *Engine) HTML(names ...string) Renderer

HTML renders the named files using the 'text/html' content type and the github.com/gobuffalo/plush package for templating. If more than 1 file is provided the second file will be considered a "layout" file and the first file will be the "content" file which will be placed into the "layout" using "<%= yield %>". If no second file is provided and an `HTMLLayout` is specified in the options, then that layout file will be used automatically.

func (*Engine) JSON Uses

func (e *Engine) JSON(v interface{}) Renderer

JSON renders the value using the "application/json" content type.

func (*Engine) JavaScript Uses

func (e *Engine) JavaScript(names ...string) Renderer

JavaScript renders the named files using the 'application/javascript' content type and the github.com/gobuffalo/plush package for templating. If more than 1 file is provided the second file will be considered a "layout" file and the first file will be the "content" file which will be placed into the "layout" using "<%= yield %>". If no second file is provided and an `JavaScriptLayout` is specified in the options, then that layout file will be used automatically.

func (*Engine) Plain Uses

func (e *Engine) Plain(names ...string) Renderer

Plain renders the named files using the 'text/plain' content type and the github.com/gobuffalo/plush package for templating. If more than 1 file is provided the second file will be considered a "layout" file and the first file will be the "content" file which will be placed into the "layout" using "<%= yield %>".

func (*Engine) String Uses

func (e *Engine) String(s string, args ...interface{}) Renderer

String renderer that will run the string through the github.com/gobuffalo/plush package and return "text/plain" as the content type.

func (*Engine) Template Uses

func (e *Engine) Template(c string, names ...string) Renderer

Template renders the named files using the specified content type and the github.com/gobuffalo/plush package for templating. If more than 1 file is provided the second file will be considered a "layout" file and the first file will be the "content" file which will be placed into the "layout" using "{{yield}}".

func (*Engine) XML Uses

func (e *Engine) XML(v interface{}) Renderer

XML renders the value using the "application/xml" content type.

type ErrRedirect Uses

type ErrRedirect struct {
    Status int
    URL    string
}

ErrRedirect indicates to Context#Render that this is a redirect and a template shouldn't be rendered.

func (ErrRedirect) Error Uses

func (ErrRedirect) Error() string

type EventSource Uses

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

EventSource is designed to work with JavaScript EventSource objects. see https://developer.mozilla.org/en-US/docs/Web/API/EventSource for more details

func NewEventSource Uses

func NewEventSource(w http.ResponseWriter) (*EventSource, error)

NewEventSource returns a new EventSource instance while ensuring that the http.ResponseWriter is able to handle EventSource messages. It also makes sure to set the proper response heads.

func (*EventSource) CloseNotify Uses

func (es *EventSource) CloseNotify() <-chan bool

CloseNotify return true across the channel when the connection in the browser has been severed.

func (*EventSource) Flush Uses

func (es *EventSource) Flush()

Flush messages down the pipe. If messages aren't flushed they won't be sent.

func (*EventSource) Write Uses

func (es *EventSource) Write(t string, d interface{}) error

type Helpers Uses

type Helpers hctx.Map

Helpers to be included in all templates

type Options Uses

type Options struct {
    // HTMLLayout is the default layout to be used with all HTML renders.
    HTMLLayout string

    // JavaScriptLayout is the default layout to be used with all JavaScript renders.
    JavaScriptLayout string

    // TemplatesBox is the location of the templates directory on disk.
    TemplatesBox packd.Box

    // AssetsBox is the location of the public assets the app will serve.
    AssetsBox packd.Box

    // Helpers to be rendered with the templates
    Helpers Helpers

    // TemplateEngine to be used for rendering HTML templates
    TemplateEngines map[string]TemplateEngine

    // DefaultContentType instructs the engine what it should fall back to if
    // the "content-type" is unknown
    DefaultContentType string
}

Options for render.Engine

type Renderer Uses

type Renderer interface {
    ContentType() string
    Render(io.Writer, Data) error
}

Renderer interface that must be satisfied to be used with buffalo.Context.Render

func Auto Uses

func Auto(ctx context.Context, i interface{}) Renderer

Auto figures out how to render the model based information about the request and the name of the model. Auto supports automatic rendering of HTML, JSON, and XML. Any status code give to Context#Render between 300 - 400 will be respected by Auto. Other status codes are not.

# Rules for HTML template lookup: GET /users - users/index.html GET /users/id - users/show.html GET /users/new - users/new.html GET /users/id/edit - users/edit.html POST /users - (redirect to /users/id or render user/new.html) PUT /users/edit - (redirect to /users/id or render user/edit.html) DELETE /users/id - redirect to /users

func Download Uses

func Download(ctx context.Context, name string, r io.Reader) Renderer

Download renders a file attachment automatically setting following headers:

Content-Type
Content-Length
Content-Disposition

Content-Type is set using mime#TypeByExtension with the filename's extension. Content-Type will default to application/octet-stream if using a filename with an unknown extension.

func Func Uses

func Func(s string, fn RendererFunc) Renderer

Func renderer allows for easily building one of renderers using just a RendererFunc and not having to build a whole implementation of the Render interface.

func HTML Uses

func HTML(names ...string) Renderer

HTML renders the named files using the 'text/html' content type and the github.com/gobuffalo/plush package for templating. If more than 1 file is provided the second file will be considered a "layout" file and the first file will be the "content" file which will be placed into the "layout" using "<%= yield %>".

func JSON Uses

func JSON(v interface{}) Renderer

JSON renders the value using the "application/json" content type.

func JavaScript Uses

func JavaScript(names ...string) Renderer

JavaScript renders the named files using the 'application/javascript' content type and the github.com/gobuffalo/plush package for templating. If more than 1 file is provided the second file will be considered a "layout" file and the first file will be the "content" file which will be placed into the "layout" using "<%= yield %>".

func Plain Uses

func Plain(names ...string) Renderer

Plain renders the named files using the 'text/html' content type and the github.com/gobuffalo/plush package for templating. If more than 1 file is provided the second file will be considered a "layout" file and the first file will be the "content" file which will be placed into the "layout" using "<%= yield %>".

func String Uses

func String(s string, args ...interface{}) Renderer

String renderer that will run the string through the github.com/gobuffalo/plush package and return "text/plain" as the content type.

func Template Uses

func Template(c string, names ...string) Renderer

Template renders the named files using the specified content type and the github.com/gobuffalo/plush package for templating. If more than 1 file is provided the second file will be considered a "layout" file and the first file will be the "content" file which will be placed into the "layout" using "{{yield}}".

func XML Uses

func XML(v interface{}) Renderer

XML renders the value using the "application/xml" content type.

type RendererFunc Uses

type RendererFunc func(io.Writer, Data) error

RendererFunc is the interface for the the function needed by the Func renderer.

type TemplateEngine Uses

type TemplateEngine func(input string, data map[string]interface{}, helpers map[string]interface{}) (string, error)

TemplateEngine needs to be implemented for a template system to be able to be used with Buffalo.

Package render imports 31 packages (graph) and is imported by 81 packages. Updated 2019-08-09. Refresh now. Tools for package owners.