1
0
mirror of https://github.com/kataras/iris.git synced 2026-03-05 16:05:58 +00:00

Implementation of https://github.com/kataras/iris/issues/412 , as requested. Read HISTORY for a code snippet

This commit is contained in:
Gerasimos Maropoulos
2016-09-29 17:05:22 +03:00
parent 4bf1d65877
commit f4b4dd0275
6 changed files with 161 additions and 40 deletions

40
iris.go
View File

@@ -79,7 +79,7 @@ import (
const (
// Version is the current version of the Iris web framework
Version = "4.4.0"
Version = "4.4.1"
banner = ` _____ _
|_ _| (_)
@@ -149,6 +149,7 @@ type (
UseSessionDB(sessions.Database)
UseSerializer(string, serializer.Serializer)
UseTemplate(template.Engine) *template.Loader
UsePreRender(PreRender)
UseGlobal(...Handler)
UseGlobalFunc(...HandlerFunc)
Lookup(string) Route
@@ -773,6 +774,28 @@ func (s *Framework) UseSerializer(forContentType string, e serializer.Serializer
s.serializers.For(forContentType, e)
}
// UsePreRender adds a Template's PreRender
// PreRender is typeof func(*iris.Context, filenameOrSource string, binding interface{}, options ...map[string]interface{}) bool
// PreRenders helps developers to pass middleware between the route Handler and a context.Render call
// all parameter receivers can be changed before passing it to the actual context's Render
// so, you can change the filenameOrSource, the page binding, the options, and even add cookies, session value or a flash message through ctx
// the return value of a PreRender is a boolean, if returns false then the next PreRender will not be executed, keep note
// that the actual context's Render will be called at any case.
func UsePreRender(pre PreRender) {
Default.UsePreRender(pre)
}
// UsePreRender adds a Template's PreRender
// PreRender is typeof func(*iris.Context, filenameOrSource string, binding interface{}, options ...map[string]interface{}) bool
// PreRenders helps developers to pass middleware between the route Handler and a context.Render call
// all parameter receivers can be changed before passing it to the actual context's Render
// so, you can change the filenameOrSource, the page binding, the options, and even add cookies, session value or a flash message through ctx
// the return value of a PreRender is a boolean, if returns false then the next PreRender will not be executed, keep note
// that the actual context's Render will be called at any case.
func (s *Framework) UsePreRender(pre PreRender) {
s.templates.usePreRender(pre)
}
// UseTemplate adds a template engine to the iris view system
// it does not build/load them yet
func UseTemplate(e template.Engine) *template.Loader {
@@ -1942,6 +1965,20 @@ func (api *muxAPI) Favicon(favPath string, requestPath ...string) RouteNameFunc
return api.Get(reqPath, h)
}
// Layout oerrides the parent template layout with a more specific layout for this Party
// returns this Party, to continue as normal
// example:
// my := iris.Party("/my").Layout("layouts/mylayout.html")
// {
// my.Get("/", func(ctx *iris.Context) {
// ctx.MustRender("page1.html", nil)
// })
// }
//
func Layout(tmplLayoutFile string) MuxAPI {
return Default.Layout(tmplLayoutFile)
}
// Layout oerrides the parent template layout with a more specific layout for this Party
// returns this Party, to continue as normal
// example:
@@ -1957,6 +1994,7 @@ func (api *muxAPI) Layout(tmplLayoutFile string) MuxAPI {
ctx.Set(TemplateLayoutContextKey, tmplLayoutFile)
ctx.Next()
})
return api
}