Documentation ¶
Overview ¶
Fazer provides a template caching and rendering solution.
Fazer provides a manifest file for all pages to be rendered.
Index ¶
- Constants
- Variables
- func AssetsPath(path string) func(*Manifest) error
- func BaseURL(base string) func() string
- func DateSimple(in time.Time) string
- func HasTrim(in string) bool
- func MRender(in string) template.HTML
- func Marshal(in interface{}) (template.JS, error)
- func PathEscape(value string) string
- func SafeHTML(input string) template.HTML
- func SetProduction(prod bool) func(*Manifest) error
- func Trim(in string) string
- func Truncate(in string, length int) string
- func XUrls(in string) template.HTML
- type Fazer
- func (f *Fazer) AddManifest(manifest *Manifest) error
- func (f *Fazer) GetFlashes(w http.ResponseWriter, r *http.Request) ([]interface{}, []interface{})
- func (f *Fazer) Partial(name string, payload interface{}) (template.HTML, error)
- func (f *Fazer) Redirect(w http.ResponseWriter, r *http.Request, url string)
- func (f *Fazer) RedirectCode(w http.ResponseWriter, r *http.Request, url string, code int)
- func (f *Fazer) RegisterMerge(merge Merge)
- func (f *Fazer) RegisterTemplate(key string, templates ...string) error
- func (f *Fazer) RegisterTemplateFunc(key string, fn interface{})
- func (f *Fazer) RenderJson(w http.ResponseWriter, r *http.Request, data interface{})
- func (f *Fazer) RenderTemplate(w http.ResponseWriter, r *http.Request, data map[string]interface{}, ...)
- func (f *Fazer) RenderTemplateWithCode(w http.ResponseWriter, r *http.Request, code int, data map[string]interface{}, ...)
- func (f *Fazer) SetErrorFlash(w http.ResponseWriter, r *http.Request, message string)
- func (f *Fazer) SetSuccessFlash(w http.ResponseWriter, r *http.Request, message string)
- type Item
- type Manifest
- func (m *Manifest) AddCSS(key string, css Item)
- func (m *Manifest) AddImg(key string, img Item)
- func (m *Manifest) AddJS(key string, js Item)
- func (m *Manifest) AddPage(sectionName, pageName string, page *Page) error
- func (m *Manifest) AddPartial(key, path string)
- func (m *Manifest) CreateSection(name, baseTpl string)
- func (m *Manifest) Finalize(opts ...func(*Manifest) error)
- func (m *Manifest) GetCssPath(key string) string
- func (m *Manifest) GetImgPath(key string) string
- func (m *Manifest) GetJsPath(key string) string
- func (m *Manifest) IteratePages() chan *Page
- func (m *Manifest) LookupPage(path string) (*Page, bool)
- func (m *Manifest) String() string
- type Merge
- type Message
- type MessageType
- type Messages
- type Messenger
- type Page
- func (p Page) GetDescription(def string) string
- func (p Page) GetFbAppId(def string) string
- func (p Page) GetOgDescription(def string) string
- func (p Page) GetOgImage(def string) string
- func (p Page) GetOgLocale() string
- func (p Page) GetOgTitle(def string) string
- func (p Page) GetOgType() string
- func (p Page) GetOgUrl() string
- func (p Page) GetTitle(def string) string
- func (p Page) GetTwitterCard(def string) string
- func (p Page) GetTwitterCreator(def string) string
- func (p Page) GetTwitterDescription(def string) string
- func (p Page) GetTwitterImage(def string) string
- func (p Page) GetTwitterSite(def string) string
- func (p Page) GetTwitterTitle(def string) string
- type Section
Constants ¶
const ( Flash = "flash" FlashError = "flasherror" FlashSuccess = "flashsuccess" )
Variables ¶
var ErrorNoTemplate = errors.New("no template found")
var ErrorPageNotExists = errors.New("page doesn't exist")
var ErrorSectionNotExists = errors.New("section doesn't exist")
Functions ¶
func AssetsPath ¶ added in v0.10.1
func DateSimple ¶
func PathEscape ¶
func SetProduction ¶ added in v0.10.1
Types ¶
type Fazer ¶
Fazer holds the information required to lookup, cache, and render html templates to be output in a web request.
func NewFazer ¶
NewFazer provides the fazer renderer with all required things initialized, including sane template functions. store: Gorilla sessions store. This is used for adding and displaying flash messages. tplDir: This is the directory in the filesystem that contains the templates. This directory can contain sub directories. config: This is any struct that you want to contain config values needed for rendering templates prod: Tells the system if you're running in production. This affects the caching and loading.
func (*Fazer) AddManifest ¶
AddManifest registers a manifest with the fazer renderer. This automatically registers the js, css, and img functions with the template.
func (*Fazer) GetFlashes ¶
func (f *Fazer) GetFlashes(w http.ResponseWriter, r *http.Request) ([]interface{}, []interface{})
GetFlashes returns any error or success flashes that are on the session. Usually only to be used internally
func (*Fazer) Partial ¶
Partial allows a partial to be loaded within the template. Use: {{ partial "key" . }}
func (*Fazer) RedirectCode ¶
RedirectCode returns a redirect with given http status
func (*Fazer) RegisterMerge ¶ added in v0.6.5
RegisterMerge adds a merge function to the renderer. This will be called previous to rendering a template.
func (*Fazer) RegisterTemplate ¶
RegisterTemplate adds a template list to the renderer.
func (*Fazer) RegisterTemplateFunc ¶
func (*Fazer) RenderJson ¶
func (f *Fazer) RenderJson(w http.ResponseWriter, r *http.Request, data interface{})
RenderJson is a shortcut method for rendering json to the response
func (*Fazer) RenderTemplate ¶
func (f *Fazer) RenderTemplate(w http.ResponseWriter, r *http.Request, data map[string]interface{}, key string)
RenderTemplate renders a registered html template with an http.StatusOk data: is a map that will be passed to the template rendering. key: this is the key used to register the template group. Will be of form section.page if registered from the manifest, see above. Calls RenderTemplateWithCode internally
func (*Fazer) RenderTemplateWithCode ¶
func (f *Fazer) RenderTemplateWithCode(w http.ResponseWriter, r *http.Request, code int, data map[string]interface{}, key string)
RenderTemplateWithCode renders a registered html template with the given http status code. data: is a map that will be passed to the template rendering. key: this is the key used to register the template group. Will be of form section.page if registered from the manifest, see above. This creates a new map[string]interface{} if the passed in data is nil. The fazer.config interface{} is added under Config The *http.Request is added under Request If a page exists from the manifest with the given key, then it is added under Page FlashError is added for any errors on the flash session FlashSuccess is added for any success on the flash session
func (*Fazer) SetErrorFlash ¶
SetErrorFlash sets a flash error message if the fazer.store is not nil
func (*Fazer) SetSuccessFlash ¶
SetSuccessFlash sets a flash success message if the fazer.store is not nil
type Item ¶
type Item struct { Path string `toml:"path"` Min string `toml:"min"` NoMin bool `toml:"no-min" json:"no-min"` Version int64 }
Item store paths for static assets [js|css|images]
type Manifest ¶
type Manifest struct { WorkingDir string AssetDir string Production bool Sections map[string]Section `toml:"sections"` Partials map[string]string `toml:"partials"` Js map[string]Item `toml:"js"` Css map[string]Item `toml:"css"` Img map[string]Item `toml:"img"` }
Manifest is a collection of templates, broken up into sections, javascript, css, and images. Assets are versioned based upon the timestamp of the asset.
func MustDecodeManifestFile ¶
MustDecodeManifest decodes the toml representation of a manifest.
[sections]
[sections.front] base="front/base.tpl" [sections.front.pages.index] tpls=[":base", "front/index.tpl"] title="Page Title" description="Page description" canonical="http://page.url" [js] [js.vue] path="https://cdn.jsdelivr.net/npm/vue/dist/vue.js" min="https://cdn.jsdelivr.net/npm/vue"
[css]
[css.bulma] path="" min=""
func MustDecodeManifestJson ¶ added in v0.8.0
MustDecodeManifestJson decodes the json representation of a manifest.
{ "sections": { "front": { "base": "front/base.tpl", "pages": { "index": { "tpls": [ ":base", "front/index.tpl" ], "title": "Page Title", "description": "Page description", "canonical": "http://page.url" } } }, "js": { "vue": { "path": "https://cdn.jsdelivr.net/npm/vue/dist/vue.js", "min": "https://cdn.jsdelivr.net/npm/vue" } }, "css": { "bulma": { "path": "/css/bulma.css", "no-min": true } } }
func (*Manifest) AddPartial ¶ added in v0.11.1
Add a partial to the manifest
func (*Manifest) CreateSection ¶ added in v0.11.0
CreateSection adds a section to this manifest
func (*Manifest) Finalize ¶ added in v0.11.0
Finalize finishes setting up the manifest. The woringdir and assetdir is set. The sections setup the templates for the pages. Also the asset items are setup to use minified versions and appends the timestamp for caching purposes.
func (*Manifest) GetCssPath ¶
GetCssPath is intended to be registered with the fazer template rendering. This will return the path for the keyed item. This reflects the environment prod or not, returning a minified or regular path.
func (*Manifest) GetImgPath ¶
GetImgPath is intended to be registered with the fazer template rendering. This will return the path for the keyed item. This reflects the environment prod or not, returning a minified or regular path.
func (*Manifest) GetJsPath ¶
GetJsPath is intended to be registered with the fazer template rendering. This will return the path for the keyed item. This reflects the environment prod or not, returning a minified or regular path.
func (*Manifest) IteratePages ¶ added in v0.6.3
IteratePages runs over every page, Fazer uses this to register templates.
func (*Manifest) LookupPage ¶ added in v0.6.3
LookupPage gets the page from a section.page key. This key is added in the fazer renderer, based upon the IteratePages path creation
type Merge ¶ added in v0.6.5
Merge is a function that allows the user to register a method that will be called previous to rendering. This is useful if you want to inspect the path and add data to the rendering context.
type Messenger ¶ added in v0.8.0
type Messenger struct {
// contains filtered or unexported fields
}
func MustDecodeMessageManifest ¶ added in v0.8.0
func MustDecodeMessageManifestFile ¶ added in v0.8.0
func (*Messenger) RegisterTemplateFunc ¶ added in v0.8.0
func (*Messenger) RenderTemplate ¶ added in v0.8.0
type Page ¶
type Page struct { ID string `toml:"id"` Title string `toml:"title"` Description string `toml:"description"` Tpls []string `toml:"tpls"` Canonical string `toml:"canonical"` OgURL string `toml:"ogurl"` OgTitle string `toml:"ogtitle"` OgDescription string `toml:"ogdescription"` OgImage string `toml:"ogimage"` OgImageType string `toml:"ogimagetype"` OgImageWidth string `toml:"ogimagewidth"` OgImageHeight string `toml:"ogimageheight"` FbAppID string `toml:"fbappid"` OgType string `toml:"ogtype"` OgLocale string `toml:"oglocale"` TwitterCard string `toml:"twittercard"` TwitterSite string `toml:"twittersite"` TwitterTitle string `toml:"twittertitle"` TwitterDescription string `toml:"twitterdescription"` TwitterCreator string `toml:"twittercreator"` TwitterImage string `toml:"twitterimage"` // contains filtered or unexported fields }
Page provides a representation of a renderedable or an output html file. Title: this is the html meta title Description: this is the html meta description Tpls: this is an array of templates required to render this page. Canonical: this is the html canonical meta
func (Page) GetDescription ¶
GetDescription returns page description, intended to be called from the template with a default value
func (Page) GetFbAppId ¶ added in v0.9.1
GetFbAppId returns the fb app id or the default value passed in
func (Page) GetOgDescription ¶ added in v0.9.1
GetOgDescription returns the open graph description, the regular description, or the default value passed in
func (Page) GetOgImage ¶ added in v0.9.1
GetOgImage returns the open graph image or the default value passed in
func (Page) GetOgLocale ¶ added in v0.9.1
GetOgLocale returns the open graph locale or the default locale
func (Page) GetOgTitle ¶ added in v0.9.1
GetOgTitle returns the open graph title for the page, or the regular title, or the default value passed in
func (Page) GetOgType ¶ added in v0.9.1
GetOgType returns the open graph type or the default website
func (Page) GetTitle ¶
GetTitle returns the page title, intended to be called from the template with a default value
func (Page) GetTwitterCard ¶ added in v0.10.1
GetTwitterCard returns the twitter card summary
func (Page) GetTwitterCreator ¶ added in v0.10.1
GetTwitterCreator returns the twitter creator or default
func (Page) GetTwitterDescription ¶ added in v0.10.1
GetTwitterDescription returns the twitter description or the page description or the default
func (Page) GetTwitterImage ¶ added in v0.10.1
GetTwitterImage returns the twitter image or default
func (Page) GetTwitterSite ¶ added in v0.10.1
GetTwitterSite returns the twitter site or default. i.e. @KendellFab
func (Page) GetTwitterTitle ¶ added in v0.10.1
GetTwitterTitle returns the twitter title or the page title or the default
type Section ¶
Section provides a logical grouping of templates, i.e. front and admin. The base property, is encoded in the manifest file as :base. This way you can specify a base template for the section, without constantly duplicating the string. Pages is a map of all of the pages registered in the section.