-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
198 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import "github.com/kataras/iris/v12" | ||
|
||
// Based on https://github.com/kataras/iris/issues/2214. | ||
func main() { | ||
app := initApp() | ||
app.Listen(":8080") | ||
} | ||
|
||
func initApp() *iris.Application { | ||
app := iris.New() | ||
app.Logger().SetLevel("debug") | ||
|
||
tmpl := iris.Blocks("./src/public/html", ".html") | ||
tmpl.Layout("main") | ||
app.RegisterView(tmpl) | ||
|
||
app.Get("/list", func(ctx iris.Context) { | ||
ctx.View("files/list") | ||
}) | ||
|
||
app.Get("/menu", func(ctx iris.Context) { | ||
ctx.View("menu/menu") | ||
}) | ||
|
||
app.Get("/list2", func(ctx iris.Context) { | ||
ctx.ViewLayout("secondary") | ||
ctx.View("files/list") | ||
}) | ||
|
||
app.Get("/menu2", func(ctx iris.Context) { | ||
ctx.ViewLayout("secondary") | ||
ctx.View("menu/menu") | ||
}) | ||
|
||
return app | ||
} |
7 changes: 7 additions & 0 deletions
7
_examples/view/template_blocks_2/src/public/html/files/list.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{{ define "title"}} | ||
<title>222</title> | ||
{{ end }} | ||
|
||
{{ define "content" }} | ||
<h1>List Content</h1> | ||
{{ end }} |
8 changes: 8 additions & 0 deletions
8
_examples/view/template_blocks_2/src/public/html/layouts/main.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
{{ block "title" .}}<title>Main Default Title</title>{{end}} | ||
</head> | ||
<body> | ||
{{ block "content" .}}<h1>Main Default Content</h1>{{end}} | ||
</body> | ||
</html> |
9 changes: 9 additions & 0 deletions
9
_examples/view/template_blocks_2/src/public/html/layouts/secondary.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<html> | ||
<head> | ||
{{ block "title" .}}<title>Secondary Default Title</title>{{end}} | ||
</head> | ||
<body> | ||
<h1>Secondary Layout</h1> | ||
{{ block "content" .}}<h1>Secondary Default Content</h1>{{end}} | ||
</body> | ||
</html> |
3 changes: 3 additions & 0 deletions
3
_examples/view/template_blocks_2/src/public/html/menu/menu.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{{ define "title" }} <title>111</title>{{ end }} | ||
|
||
{{ define "content" }}<h1>Menu Content</h1>{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package router | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/kataras/golog" | ||
"github.com/kataras/pio" | ||
) | ||
|
||
func printRoutesInfo(logger *golog.Logger, registeredRoutes []*Route, noLogCount int) { | ||
if !(logger != nil && logger.Level == golog.DebugLevel && noLogCount < len(registeredRoutes)) { | ||
return | ||
} | ||
|
||
// group routes by method and print them without the [DBUG] and time info, | ||
// the route logs are colorful. | ||
// Note: don't use map, we need to keep registered order, use | ||
// different slices for each method. | ||
|
||
collect := func(method string) (methodRoutes []*Route) { | ||
for _, r := range registeredRoutes { | ||
if r.NoLog { | ||
continue | ||
} | ||
if r.Method == method { | ||
methodRoutes = append(methodRoutes, r) | ||
} | ||
} | ||
|
||
return | ||
} | ||
|
||
type MethodRoutes struct { | ||
method string | ||
routes []*Route | ||
} | ||
|
||
allMethods := append(AllMethods, []string{MethodNone, ""}...) | ||
methodRoutes := make([]MethodRoutes, 0, len(allMethods)) | ||
|
||
for _, method := range allMethods { | ||
routes := collect(method) | ||
if len(routes) > 0 { | ||
methodRoutes = append(methodRoutes, MethodRoutes{method, routes}) | ||
} | ||
} | ||
|
||
if n := len(methodRoutes); n > 0 { | ||
tr := "routes" | ||
if len(registeredRoutes) == 1 { | ||
tr = tr[0 : len(tr)-1] | ||
} | ||
|
||
bckpNewLine := logger.NewLine | ||
logger.NewLine = false | ||
debugLevel := golog.Levels[golog.DebugLevel] | ||
// Replace that in order to not transfer it to the log handler (e.g. json) | ||
// logger.Debugf("API: %d registered %s (", len(registeredRoutes), tr) | ||
// with: | ||
pio.WriteRich(logger.Printer, debugLevel.Title, debugLevel.ColorCode, debugLevel.Style...) | ||
fmt.Fprintf(logger.Printer, " %s %sAPI: %d registered %s (", time.Now().Format(logger.TimeFormat), logger.Prefix, len(registeredRoutes)-noLogCount, tr) | ||
// | ||
logger.NewLine = bckpNewLine | ||
|
||
for i, m := range methodRoutes { | ||
// @method: @count | ||
if i > 0 { | ||
if i == n-1 { | ||
fmt.Fprint(logger.Printer, " and ") | ||
} else { | ||
fmt.Fprint(logger.Printer, ", ") | ||
} | ||
} | ||
if m.method == "" { | ||
m.method = "ERROR" | ||
} | ||
fmt.Fprintf(logger.Printer, "%d ", len(m.routes)) | ||
pio.WriteRich(logger.Printer, m.method, TraceTitleColorCode(m.method)) | ||
} | ||
|
||
fmt.Fprint(logger.Printer, ")\n") | ||
} | ||
|
||
for i, m := range methodRoutes { | ||
for _, r := range m.routes { | ||
r.Trace(logger.Printer, -1) | ||
} | ||
|
||
if i != len(allMethods)-1 { | ||
logger.Printer.Write(pio.NewLine) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.