Documentation ¶
Index ¶
- Constants
- func Rel(gctx *gin.Context, paths ...string) string
- type Links
- type Manager
- type Option
- type ViewContext
- func (vc *ViewContext) Context() *gin.Context
- func (vc *ViewContext) Data() interface{}
- func (vc *ViewContext) In(href string) bool
- func (vc *ViewContext) Path() string
- func (vc *ViewContext) Ref(alias string, args ...interface{}) (string, error)
- func (vc *ViewContext) Rel(values ...interface{}) string
- func (vc *ViewContext) RelArgs(href string, paths []string) string
Constants ¶
const LayoutFile = "@layout.html"
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Links ¶
type Links struct {
// contains filtered or unexported fields
}
func (*Links) Named ¶
Named registers route under provided name, which could be used in Views by .Ref function. Example:
gin.GET(links.Named("eventByID", "/event/:id"), func(gctx *gin.Context) { }) ...
Then in view we can use
{{.Ref "eventByID" 1234}}
Which will generate relative URL to named route with proper parameters
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager of templates. Supports caching (builds template once), streaming (render directly to client), and functions map (ex: Sprig).
func (*Manager) Alias ¶
Alias template file (related to FS used during creation) and to short name. Thread UNSAFE, since templates are usually supposed to be added once during the initialization phase.
func (*Manager) Compile ¶
Compile all templates. There is no sense to use it without enabled caching. Could be used as warm-up.
type Option ¶
type Option func(mgr *Manager)
func Cache ¶
func Cache() Option
Cache compiled template. Slightly increases memory usage. Recommended in production environment.
type ViewContext ¶
type ViewContext struct {
// contains filtered or unexported fields
}
ViewContext is convenient wrapper around context and data which could be used in templates.
func View ¶
func View(gctx *gin.Context, userData interface{}) *ViewContext
View creates view context which could be used in template. Provides useful methods and exposes user data via .Data method.
func (*ViewContext) Context ¶
func (vc *ViewContext) Context() *gin.Context
Context used by handler.
func (*ViewContext) In ¶
func (vc *ViewContext) In(href string) bool
In checks is current path equal or under provided href.
func (*ViewContext) Ref ¶
func (vc *ViewContext) Ref(alias string, args ...interface{}) (string, error)
Ref creates relative path to alias with args if required. Requires Links to be installed.
func (*ViewContext) Rel ¶
func (vc *ViewContext) Rel(values ...interface{}) string
Rel constructs relative path from absolute.