Skip to content

Commit

Permalink
iss #69: base template with bootstrap 5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
maizy committed May 5, 2021
1 parent 122471f commit 43cc280
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 17 deletions.
4 changes: 3 additions & 1 deletion cmd/ponylib/cmd/web_ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ var (
bindPort int
bindHost string
debugMode bool
devMode bool
)

func init() {
webUiCmd.PersistentFlags().IntVar(&bindPort, "port", 55387, "bind port")
webUiCmd.PersistentFlags().StringVar(&bindHost, "host", "127.0.0.1", "bind host")
webUiCmd.PersistentFlags().BoolVar(&debugMode, "debug", false, "enable debug mode")
webUiCmd.PersistentFlags().BoolVar(&devMode, "dev-mode", false, "enable dev mode (templates hot reload)")

rootCmd.AddCommand(webUiCmd)
}
Expand All @@ -42,7 +44,7 @@ var webUiCmd = &cobra.Command{

engine := gin.Default()
web.SetupMiddlewares(engine)
web.SetupTemplates(engine)
web.SetupTemplates(engine, devMode)
web.AppendRouters(engine)

addr := fmt.Sprintf("%s:%d", bindHost, bindPort)
Expand Down
6 changes: 5 additions & 1 deletion ponylib_app/web/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import (
"strings"

"github.com/gin-gonic/gin"

"dev.maizy.ru/ponylib/ponylib_app"
)

func AppendWebUiRouters(engine *gin.Engine) {
engine.GET("/", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.tmpl", gin.H{
"test": "Hi! <b>test</b>",
"subtitle": "Search",
"lang": "en",
"version": ponylib_app.GetVersion(),
})
})
}
Expand Down
7 changes: 7 additions & 0 deletions ponylib_app/web/static/css/bootstrap.min.css

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions ponylib_app/web/static/css/main.css
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
body {
color: darkorange;
}
141 changes: 132 additions & 9 deletions ponylib_app/web/templates/index.tmpl
Original file line number Diff line number Diff line change
@@ -1,16 +1,139 @@
<!DOCTYPE>
<html lang="ru">
<!doctype html>
<html lang="{{.lang}}" class="h-100">
<head>
<title>Ponylib</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="/static/css/main.css" rel="stylesheet" type="text/css">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="/static/css/bootstrap.min.css" rel="stylesheet">
<link href="/static/css/main.css" rel="stylesheet">
<title>Ponylib{{if .subtitle}} · {{.subtitle}}{{end}}</title>
</head>
<body class="d-flex flex-column h-100">
<header class="border-bottom bg-dark mb-2">
<div class="container d-flex flex-wrap align-items-center">
<a href="/"
class="d-flex col-12 col-md-3 align-items-center justify-content-center justify-content-md-start pt-1 py-md-2 text-dark text-decoration-none">
<span class="fs-2">🎠&nbsp;</span>
<span class="fs-4 text-white">Ponylib</span>
</a>
<form class="col-12 col-md-9 align-items-center pt-0 pb-2 py-md-2">
<div class="container-fluid d-flex gap-0 p-0">
<div class="col-9 pe-2">
<input type="search" class="form-control">
</div>
<div class="col-3">
<button type="button" class="btn btn-outline-light col-12 col-md-auto">Search</button>
</div>
</div>
</form>
</div>
</header>

<body>
<main class="container flex-shrink-0">
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
<p>hi!</p>
</main>

<h1>Ponylib</h1>

{{ .test }}
<footer class="footer mt-auto py-3 bg-light">
<div class="container">
<small class="text-muted">{{ .version }}</small>
</div>
</footer>

</body>
</html>
10 changes: 7 additions & 3 deletions ponylib_app/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ func SetupMiddlewares(engine *gin.Engine) {
//go:embed templates/*
var templates embed.FS

func SetupTemplates(engine *gin.Engine) {
template := template.Must(template.New("").ParseFS(templates, "templates/*.tmpl"))
engine.SetHTMLTemplate(template)
func SetupTemplates(engine *gin.Engine, devMode bool) {
if devMode {
engine.LoadHTMLGlob("ponylib_app/web/templates/*.tmpl")
} else {
embedTemplate := template.Must(template.New("").ParseFS(templates, "templates/*.tmpl"))
engine.SetHTMLTemplate(embedTemplate)
}
}

0 comments on commit 43cc280

Please sign in to comment.