Factorise templates
This commit is contained in:
parent
8a06369839
commit
8df3f87a23
@ -99,42 +99,55 @@ type SeriesFull struct {
|
||||
Books []*Book
|
||||
}
|
||||
|
||||
type BouquinsModel struct {
|
||||
Title string
|
||||
}
|
||||
|
||||
// Constructor BouquinsModel
|
||||
func NewBouquinsModel(title string) *BouquinsModel {
|
||||
return &BouquinsModel{
|
||||
title,
|
||||
}
|
||||
}
|
||||
|
||||
type IndexModel struct {
|
||||
BouquinsModel
|
||||
BooksCount int64
|
||||
Books []*BookAdv
|
||||
Series []*SeriesAdv
|
||||
Authors []*AuthorAdv
|
||||
}
|
||||
|
||||
func (app *Bouquins) IndexPage(res http.ResponseWriter, req *http.Request) {
|
||||
series := make([]*SeriesAdv, 0)
|
||||
a1 := make([]*Author, 0)
|
||||
s1 := &SeriesAdv{
|
||||
Series{
|
||||
666,
|
||||
"Serie 1",
|
||||
},
|
||||
12,
|
||||
a1,
|
||||
}
|
||||
series = append(series, s1)
|
||||
model := &IndexModel{
|
||||
123,
|
||||
// Constructor IndexModel
|
||||
func NewIndexModel(title string, count int64) *IndexModel {
|
||||
return &IndexModel{
|
||||
*NewBouquinsModel(title),
|
||||
count,
|
||||
nil,
|
||||
nil,
|
||||
series,
|
||||
nil,
|
||||
}
|
||||
err := app.Template.ExecuteTemplate(res, TPL_INDEX, model)
|
||||
}
|
||||
|
||||
// ROUTES //
|
||||
|
||||
func (app *Bouquins) render(res http.ResponseWriter, tpl string, model interface{}) {
|
||||
err := app.Template.ExecuteTemplate(res, tpl, model)
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (app *Bouquins) IndexPage(res http.ResponseWriter, req *http.Request) {
|
||||
model := NewIndexModel("", 123)
|
||||
app.render(res, TPL_INDEX, model)
|
||||
}
|
||||
func (app *Bouquins) BooksPage(res http.ResponseWriter, req *http.Request) {
|
||||
panic("not implemented")
|
||||
app.render(res, TPL_BOOKS, nil)
|
||||
}
|
||||
func (app *Bouquins) AuthorsPage(res http.ResponseWriter, req *http.Request) {
|
||||
panic("not implemented")
|
||||
app.render(res, TPL_AUTHORS, nil)
|
||||
}
|
||||
func (app *Bouquins) SeriesPage(res http.ResponseWriter, req *http.Request) {
|
||||
panic("not implemented")
|
||||
app.render(res, TPL_SERIES, nil)
|
||||
}
|
||||
|
4
main.go
4
main.go
@ -15,6 +15,7 @@ const (
|
||||
SERIES = "/series"
|
||||
JS = "/js/"
|
||||
CSS = "/css/"
|
||||
FONTS = "/fonts/"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -22,11 +23,9 @@ func init() {
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
app := &bouquins.Bouquins{
|
||||
tpl,
|
||||
}
|
||||
|
||||
assets()
|
||||
router(app)
|
||||
}
|
||||
@ -34,6 +33,7 @@ func init() {
|
||||
func assets() {
|
||||
http.Handle(JS, http.FileServer(http.Dir("assets")))
|
||||
http.Handle(CSS, http.FileServer(http.Dir("assets")))
|
||||
http.Handle(FONTS, http.FileServer(http.Dir("assets")))
|
||||
}
|
||||
|
||||
func router(app *bouquins.Bouquins) {
|
||||
|
@ -1,30 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<title>Auteur | Bouquins</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta charset="utf-8" />
|
||||
<link rel="stylesheet" href="/css/bootstrap.min.css">
|
||||
<link rel="preload" href="/js/author.min.js" as="script">
|
||||
<link rel="preload" href="/js/vue.min.js" as="script">
|
||||
<link rel="prefetch" href="/js/author.min.js">
|
||||
<link rel="prefetch" href="/js/vue.min.js">
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-inverse" id="nav">
|
||||
<div class="container">
|
||||
<ul class="nav navbar-nav">
|
||||
<li><a href="index.html">Accueil</a></li>
|
||||
<li><a href="search.html">Recherche</a></li>
|
||||
<li><a href="#">A propos</a></li>
|
||||
</ul>
|
||||
<form class="navbar-form navbar-right" role="search" method="get" action="search.html">
|
||||
<div class="form-group">
|
||||
<input name="q" type="text" class="form-control" placeholder="Recherche">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</nav>
|
||||
{{ template "header.html" . }}
|
||||
<div class="container" id="app">
|
||||
<div class="page-header" v-if="author.id">
|
||||
<h1>
|
||||
@ -66,8 +40,4 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="js/vue.min.js"></script>
|
||||
<script src="js/author.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
{{ template "footer.html" . }}
|
||||
|
@ -1,30 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<title>Livre | Bouquins</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta charset="utf-8" />
|
||||
<link rel="stylesheet" href="/css/bootstrap.min.css">
|
||||
<link rel="preload" href="/js/book.min.js" as="script">
|
||||
<link rel="preload" href="/js/vue.min.js" as="script">
|
||||
<link rel="prefetch" href="/js/book.min.js">
|
||||
<link rel="prefetch" href="/js/vue.min.js">
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-inverse" id="nav">
|
||||
<div class="container">
|
||||
<ul class="nav navbar-nav">
|
||||
<li><a href="index.html">Accueil</a></li>
|
||||
<li><a href="search.html">Recherche</a></li>
|
||||
<li><a href="#">A propos</a></li>
|
||||
</ul>
|
||||
<form class="navbar-form navbar-right" role="search" method="get" action="search.html">
|
||||
<div class="form-group">
|
||||
<input name="q" type="text" class="form-control" placeholder="Recherche">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</nav>
|
||||
{{ template "header.html" . }}
|
||||
<div class="container" id="app">
|
||||
<div class="page-header" v-if="book.id">
|
||||
<div class="row" v-if="book.has_cover">
|
||||
@ -84,9 +58,5 @@
|
||||
<li v-if="book.publisher"><strong>Editeur</strong> {{ .Book.Publisher }}</li>
|
||||
</ul>
|
||||
</div>
|
||||
<!-- TODO cover -->
|
||||
</div>
|
||||
<script src="js/vue.min.js"></script>
|
||||
<script src="js/book.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
{{ template "footer.html" . }}
|
||||
|
3
templates/footer.html
Normal file
3
templates/footer.html
Normal file
@ -0,0 +1,3 @@
|
||||
<script src="js/vue.min.js"></script>
|
||||
</body>
|
||||
</html>
|
23
templates/header.html
Normal file
23
templates/header.html
Normal file
@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<title>Bouquins{{ if .Title }} - {{ .Title }}{{ end }}</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta charset="utf-8" />
|
||||
<link rel="stylesheet" href="/css/bootstrap.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-inverse" id="nav">
|
||||
<div class="container">
|
||||
<ul class="nav navbar-nav">
|
||||
<li class="active"><a href="#">Accueil</a></li>
|
||||
<li><a href="search.html">Recherche</a></li>
|
||||
<li><a href="#">A propos</a></li>
|
||||
</ul>
|
||||
<form class="navbar-form navbar-right" role="search" method="get" action="search.html">
|
||||
<div class="form-group">
|
||||
<input name="q" type="text" class="form-control" placeholder="Recherche">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</nav>
|
@ -1,30 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<title>Bouquins</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta charset="utf-8" />
|
||||
<link rel="stylesheet" href="/css/bootstrap.min.css">
|
||||
<link rel="preload" href="/js/index.min.js" as="script">
|
||||
<link rel="preload" href="/js/vue.min.js" as="script">
|
||||
<link rel="prefetch" href="/js/index.min.js">
|
||||
<link rel="prefetch" href="/js/vue.min.js">
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-inverse" id="nav">
|
||||
<div class="container">
|
||||
<ul class="nav navbar-nav">
|
||||
<li class="active"><a href="#">Accueil</a></li>
|
||||
<li><a href="search.html">Recherche</a></li>
|
||||
<li><a href="#">A propos</a></li>
|
||||
</ul>
|
||||
<form class="navbar-form navbar-right" role="search" method="get" action="search.html">
|
||||
<div class="form-group">
|
||||
<input name="q" type="text" class="form-control" placeholder="Recherche">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</nav>
|
||||
{{ template "header.html" . }}
|
||||
<div class="container" id="app">
|
||||
<div class="jumbotron">
|
||||
<h1>Bouquins</h1>
|
||||
@ -33,13 +7,15 @@
|
||||
<button class="btn btn-primary" type="button" @click="showAuthors">Auteurs</button>
|
||||
<button class="btn btn-primary" type="button" @click="showSeries">Series</button>
|
||||
</div>
|
||||
<div class="table-responsive" v-if="books.length > 0 || authors.length > 0 || series.length > 0">
|
||||
<div class="table-responsive">
|
||||
{{ if (ne (len .Books) 0) or (ne (len .Authors) 0) or (ne (len .Series) 0) }}
|
||||
<nav aria-label="Pages">
|
||||
<ul class="pager">
|
||||
<li class="previous" v-bind:class="{ disabled: page <= 1 }"><a href="#" @click="prevPage"><span aria-hidden="true">←</span> Précédents</a></li>
|
||||
<li class="next"><a href="#" @click="nextPage">Suivants <span aria-hidden="true">→</span></a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
{{ end }}
|
||||
{{ if .Series }}
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
@ -114,15 +90,14 @@
|
||||
</tr>
|
||||
</table>
|
||||
{{ end }}
|
||||
{{ if (ne (len .Books) 0) or (ne (len .Authors) 0) or (ne (len .Series) 0) }}
|
||||
<nav aria-label="Pages">
|
||||
<ul class="pager">
|
||||
<li class="previous" v-bind:class="{ disabled: page <= 1 }"><a href="#" @click="prevPage"><span aria-hidden="true">←</span> Précédents</a></li>
|
||||
<li class="next"><a href="#" @click="nextPage">Suivants <span aria-hidden="true">→</span></a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
<script src="js/vue.min.js"></script>
|
||||
<script src="js/index.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
{{ template "footer.html" . }}
|
||||
|
@ -1,30 +1,4 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<title>Serie | Bouquins</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta charset="utf-8" />
|
||||
<link rel="stylesheet" href="/css/bootstrap.min.css">
|
||||
<link rel="preload" href="/js/series.min.js" as="script">
|
||||
<link rel="preload" href="/js/vue.min.js" as="script">
|
||||
<link rel="prefetch" href="/js/series.min.js">
|
||||
<link rel="prefetch" href="/js/vue.min.js">
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-inverse" id="nav">
|
||||
<div class="container">
|
||||
<ul class="nav navbar-nav">
|
||||
<li><a href="index.html">Accueil</a></li>
|
||||
<li><a href="search.html">Recherche</a></li>
|
||||
<li><a href="#">A propos</a></li>
|
||||
</ul>
|
||||
<form class="navbar-form navbar-right" role="search" method="get" action="search.html">
|
||||
<div class="form-group">
|
||||
<input name="q" type="text" class="form-control" placeholder="Recherche">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</nav>
|
||||
{{ template "header.html" . }}
|
||||
<div class="container" id="app">
|
||||
<div class="page-header" v-if="series">
|
||||
<h1>
|
||||
@ -53,8 +27,4 @@
|
||||
</ul>
|
||||
</template>
|
||||
</div>
|
||||
<script src="js/vue.min.js"></script>
|
||||
<script src="js/series.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
{{ template "footer.html" . }}
|
||||
|
Loading…
Reference in New Issue
Block a user