Documentation ¶
Index ¶
- Constants
- Variables
- func MRender(in string) template.HTML
- func SafeHTML(input string) template.HTML
- func SetLayoutGlob(layoutGlob string) func(v *Vault)
- func SetPageGlob(pageGlob string) func(v *Vault)
- func SetPartialGlob(partialGlob string) func(v *Vault)
- type Asset
- type FlashAdapter
- type Merge
- type Message
- 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
- func (p *Page) SetOptions(opts ...PageOpts) *Page
- type PageOpts
- type Partial
- type Payload
- type Vault
- func (v *Vault) AddJsonManifest(input string) error
- func (v *Vault) AutoRegisterPages()
- func (v *Vault) GetCssPath(key string) string
- func (v *Vault) GetImgPath(key string) string
- func (v *Vault) GetJsPath(key string) string
- func (v *Vault) Partial(name string, payload interface{}) (template.HTML, error)
- func (v *Vault) Redirect(w http.ResponseWriter, r *http.Request, url string)
- func (v *Vault) RedirectCode(w http.ResponseWriter, r *http.Request, url string, code int)
- func (v *Vault) RegisterCSS(css Asset)
- func (v *Vault) RegisterImg(img Asset)
- func (v *Vault) RegisterJS(js Asset)
- func (v *Vault) RegisterMerge(merge Merge)
- func (v *Vault) RegisterMessage(message *Message)
- func (v *Vault) RegisterMessageFS(message fs.FS)
- func (v *Vault) RegisterPage(page *Page)
- func (v *Vault) RegisterPartial(partial *Partial)
- func (v *Vault) RegisterTemplateFunc(key string, fn any)
- func (v *Vault) Render(w http.ResponseWriter, r *http.Request, key string, data any)
- func (v *Vault) RenderJson(w http.ResponseWriter, data any)
- func (v *Vault) RenderJsonWithCode(code int, w http.ResponseWriter, data any)
- func (v *Vault) RenderMessageHtml(w io.Writer, key string, data map[string]interface{}) error
- func (v *Vault) RenderMessagePlain(w io.Writer, key string, data map[string]interface{}) error
- func (v *Vault) RenderPage(w http.ResponseWriter, r *http.Request, key string, ...)
- func (v *Vault) SetErrorFlash(w http.ResponseWriter, r *http.Request, message string)
- func (v *Vault) SetSuccessFlash(w http.ResponseWriter, r *http.Request, message string)
- type VaultConfig
Constants ¶
const ( DefaultPageGlob = "*.page.*" DefaultLayoutGlob = "*.layout.*" DefaultPartialGlob = "*.partial.*" )
Variables ¶
var ErrorMessageNotFound = errors.New("error message not found")
var ErrorNoTemplate = errors.New("error no template")
var ErrorNoTemplates = errors.New("error no templates")
var ErrorParsingMessage = errors.New("error parsing message")
var ErrorParsingPartial = errors.New("error parsing partial")
var ErrorPartialNotFound = errors.New("partial not found")
Functions ¶
func SetLayoutGlob ¶ added in v0.6.0
func SetPageGlob ¶ added in v0.6.0
func SetPartialGlob ¶ added in v0.6.0
Types ¶
type Asset ¶
type FlashAdapter ¶ added in v0.5.0
type Message ¶
type Message struct { Key string `json:"key"` PlainTPLS []string `json:"plainTpls"` CachedPlain *txttpl.Template HtmlTPLS []string `json:"htmlTpls"` CachedHtml *template.Template }
func NewHtmlMessage ¶ added in v0.4.2
func NewPlainMessage ¶ added in v0.4.2
type Page ¶
type Page struct { Key string `json:"key"` Tpls []string `json:"tpls"` Cached *template.Template Title string `json:"title"` Description string `json:"description"` Canonical string `json:"canonical"` OgURL string `json:"ogurl"` OgTitle string `json:"ogtitle"` OgDescription string `json:"ogdescription"` OgImage string `json:"ogimage"` OgImageType string `json:"ogimagetype"` OgImageWidth string `json:"ogimagewidth"` OgImageHeight string `json:"ogimageheight"` FbAppID string `json:"fbappid"` OgType string `json:"ogtype"` OgLocale string `json:"oglocale"` TwitterCard string `json:"twittercard"` TwitterSite string `json:"twittersite"` TwitterTitle string `json:"twittertitle"` TwitterDescription string `json:"twitterdescription"` TwitterCreator string `json:"twittercreator"` TwitterImage string `json:"twitterimage"` // contains filtered or unexported fields }
func (Page) GetDescription ¶
GetDescription returns page description, intended to be called from the template with a default value
func (Page) GetFbAppId ¶
GetFbAppId returns the fb app id or the default value passed in
func (Page) GetOgDescription ¶
GetOgDescription returns the open graph description, the regular description, or the default value passed in
func (Page) GetOgImage ¶
GetOgImage returns the open graph image or the default value passed in
func (Page) GetOgLocale ¶
GetOgLocale returns the open graph locale or the default locale
func (Page) GetOgTitle ¶
GetOgTitle returns the open graph title for the page, or the regular title, or the default value passed in
func (Page) GetTitle ¶
GetTitle returns the page title, intended to be called from the template with a default value
func (Page) GetTwitterCard ¶
GetTwitterCard returns the twitter card summary
func (Page) GetTwitterCreator ¶
GetTwitterCreator returns the twitter creator or default
func (Page) GetTwitterDescription ¶
GetTwitterDescription returns the twitter description or the page description or the default
func (Page) GetTwitterImage ¶
GetTwitterImage returns the twitter image or default
func (Page) GetTwitterSite ¶
GetTwitterSite returns the twitter site or default. i.e. @KendellFab
func (Page) GetTwitterTitle ¶
GetTwitterTitle returns the twitter title or the page title or the default
func (*Page) SetOptions ¶ added in v0.4.2
type PageOpts ¶ added in v0.4.2
type PageOpts func(page *Page)
func SetDescription ¶ added in v0.4.2
type Partial ¶
func NewPartial ¶ added in v0.4.2
type Vault ¶ added in v0.4.0
type Vault struct {
// contains filtered or unexported fields
}
Vault is a wrapper around the go template library. The pageFS parameter is to be the root file system used where all of the page & partial tpls reference from
func NewVault ¶ added in v0.4.0
func NewVault(flashAdapter FlashAdapter, prod bool, config interface{}, pageFs fs.FS, opts ...VaultConfig) *Vault
NewVault creates a new Vault instance.
func (*Vault) AddJsonManifest ¶ added in v0.4.0
AddJsonManifest is a json representation of the pages, partials, messages, and assets to be managed by this Vault instance It is to be formatted as
{ "pages": [], "partials": [], "messages": [], "js": [], "css": [], "img": [] }
It is recommended that this use the embed directive to get a string from the filesystem. However it could be stored as a string and passed in.
func (*Vault) AutoRegisterPages ¶ added in v0.6.0
func (v *Vault) AutoRegisterPages()
AutoRegisterPages will look for pages, layouts, and partials based upon the glob patterns that are set. You need your templates setup properly for this to work, but it does make it easier to get started. base.layout.gohtml {{define "base"}} <!DOCTYPE html>
<html lang="en"> <head> <title>{{block "title" .}}Title{{end}}</title> </head> <body> {{block "content" .}}{{end}} </body> </html>
{{end}} # Ends defining base template
index.page.gohtml {{template "base" .}}
{{define "title"}}Page Title{{end}} {{define "content"}}
<h1>Page</h1> {{end}}
func (*Vault) GetCssPath ¶ added in v0.4.0
func (*Vault) GetImgPath ¶ added in v0.4.0
func (*Vault) Partial ¶ added in v0.4.0
Partial allows a partial to be loaded within the template. Use: {{ partial "key" . }}
func (*Vault) RedirectCode ¶ added in v0.4.0
RedirectCode returns a redirect with given http status
func (*Vault) RegisterCSS ¶ added in v0.4.0
func (*Vault) RegisterImg ¶ added in v0.4.0
func (*Vault) RegisterJS ¶ added in v0.4.0
func (*Vault) RegisterMerge ¶ added in v0.4.0
func (*Vault) RegisterMessage ¶ added in v0.4.0
func (*Vault) RegisterMessageFS ¶ added in v0.4.0
RegisterMessageFS takes a file system where the message tpls reference from
func (*Vault) RegisterPage ¶ added in v0.4.0
func (*Vault) RegisterPartial ¶ added in v0.4.0
func (*Vault) RegisterTemplateFunc ¶ added in v0.4.0
func (*Vault) RenderJson ¶ added in v0.4.0
func (v *Vault) RenderJson(w http.ResponseWriter, data any)
RenderJson is a shortcut method for rendering json to the response
func (*Vault) RenderJsonWithCode ¶ added in v0.7.0
func (v *Vault) RenderJsonWithCode(code int, w http.ResponseWriter, data any)
func (*Vault) RenderMessageHtml ¶ added in v0.4.0
func (*Vault) RenderMessagePlain ¶ added in v0.4.0
func (*Vault) RenderPage ¶ added in v0.4.0
func (*Vault) SetErrorFlash ¶ added in v0.4.0
SetErrorFlash sets a flash error message if the fazer.store is not nil
func (*Vault) SetSuccessFlash ¶ added in v0.4.0
SetSuccessFlash sets a flash success message if the fazer.store is not nil
type VaultConfig ¶ added in v0.6.0
type VaultConfig func(*Vault)