abcrender

package
v3.0.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2018 License: BSD-3-Clause, BSD-3-Clause Imports: 10 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppHelpers

func AppHelpers(manifest map[string]string) template.FuncMap

AppHelpers takes in the assets manifest and returns a map of the template helper functions.

func GetManifest

func GetManifest(publicPath string) (map[string]string, error)

GetManifest reads the manifest.json file in the public assets folder and returns a map of its mappings. Returns error if manifest.json not found.

Types

type Render

type Render struct {
	*render.Render
	// contains filtered or unexported fields
}

Render implements the HTML and HTMLWithLayout functions on the Renderer interface and imbeds the unrolled Render type to satisfy the rest of the interface. The custom HTML/HTMLWithLayout implementation is required due to the Render HTML function having a package-specific type for the layout string (Render.HTMLOptions). It's also required to wrap the AssetsManifest for the template function helpers.

func (*Render) HTML

func (r *Render) HTML(w io.Writer, status int, name string, binding interface{}) error

HTML renders a HTML template by calling unrolled Render package's HTML function

func (*Render) HTMLWithLayout

func (r *Render) HTMLWithLayout(w io.Writer, status int, name string, binding interface{}, layout string) error

HTMLWithLayout renders a HTML template using a specified layout file by calling unrolled Render package's HTML function with a HTMLOptions argument

type Renderer

type Renderer interface {
	Data(w io.Writer, status int, v []byte) error
	JSON(w io.Writer, status int, v interface{}) error
	Text(w io.Writer, status int, v string) error
	// HTML renders a HTML template. Example:
	// Assumes you have a template in ./templates called "home.tmpl"
	// $ mkdir -p templates && echo "<h1>Hello {{.}}</h1>" > templates/home.tmpl
	// HTML(w, http.StatusOK, "home", "World")
	HTML(w io.Writer, status int, name string, binding interface{}) error
	// HTMLWithLayout renders a HTML template using a different layout to the
	// one specified in your renderer's configuration. Example:
	// Example: HTMLWithLayout(w, http.StatusOK, "home", "World", "layout")
	HTMLWithLayout(w io.Writer, status int, name string, binding interface{}, layout string) error
}

Renderer implements template rendering methods. If you'd like to create a renderer that uses a different rendering engine opposed to standard text/templates or html/templates you can do so by implementing this interface.

func New

func New(opts render.Options, manifest map[string]string) Renderer

New returns a new Render with AssetsManifest and Render set

Jump to

Keyboard shortcuts

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