bootstrap

This commit is contained in:
Ruidy Nemausat 2020-03-14 15:46:58 +01:00
parent f35cc2d2fd
commit 9f075c72d4
7 changed files with 104 additions and 4 deletions

View file

@ -69,12 +69,15 @@ func saveHandler(w http.ResponseWriter, r *http.Request, title string) {
func renderTemplate(w http.ResponseWriter, tmpl string, p *model.Page) {
// err := templates.ExecuteTemplate(w, "templates/"+tmpl+".html", p)
t, err := template.ParseFiles("templates/" + tmpl + ".html")
t, err := template.ParseFiles(getTmplName("base"), getTmplName(tmpl))
checkError(err, w)
err = t.Execute(w, p)
checkError(err, w)
}
func getTmplName(tmpl string) string {
return tmplDir + tmpl + ".html"
}
func checkError(err error, w http.ResponseWriter) {
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)

View file

@ -1,3 +1,4 @@
package controller
var Port int = 8080
var tmplDir string = "templates/"

7
data/doc.txt Normal file
View file

@ -0,0 +1,7 @@
Type a term in the search bar.
If it already exist you will reach this page.
If it is not yet defined you will have the possibility to create it.
Have fun

74
templates/base.html Normal file
View file

@ -0,0 +1,74 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
crossorigin="anonymous"
/>
<nav>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="/">🐹 Go-Wiki</a>
<button
class="navbar-toggler"
type="button"
data-toggle="collapse"
data-target="#navbarSupportedContent"
aria-controls="navbarSupportedContent"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<form class="form-inline my-2 my-lg-0">
<input
class="form-control mr-sm-2"
type="search"
placeholder="Search"
aria-label="Search"
/>
<button
class="btn btn-outline-success my-2 my-sm-0"
type="submit"
action="/view/"
>
Search
</button>
</form>
</div>
</nav>
</nav>
<title>{{template "title" .}}</title>
</head>
<body>
<div class="container">
{{template "content" .}}
</div>
<script
src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
crossorigin="anonymous"
></script>
<script
src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"
></script>
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
crossorigin="anonymous"
></script>
</body>
</html>

View file

@ -1,3 +1,4 @@
{{define "title"}} {{.Title}} | Go-Wiki {{end}} {{define "content"}}
<h1>Editing {{.Title}}</h1>
<form action="/save/{{.Title}}" method="POST">
@ -6,3 +7,4 @@
</div>
<div><input type="submit" value="Save" /></div>
</form>
{{end}}

View file

@ -1,5 +1,16 @@
<h1>Hi there, Welcome to Go-Wiki</h1>
{{define "title"}} Welcome to Go-Wiki {{end}} {{define "content"}}
<div>
<h2>Useful links</h2>
<div class="jumbotron">
<h1 class="display-4">Welcome to Go-Wiki</h1>
<p class="lead">
Golang powered Wiki web application
</p>
<hr class="my-4" />
<p>
Look at our documentation to discover how to contribute !
</p>
<a class="btn btn-primary btn-lg" href="/view/Doc" role="button"
>Documentation</a
>
</div>
{{end}}

View file

@ -1,5 +1,7 @@
{{define "title"}} {{.Title}} | Go-Wiki {{end}} {{define "content"}}
<h1>{{.Title}}</h1>
<p>[<a href="/edit/{{.Title}}">edit</a>]</p>
<div>{{printf "%s" .Body}}</div>
{{end}}