From 424a0fad8e4426b870c8330877b0f3fa09621659 Mon Sep 17 00:00:00 2001 From: Las Zenow Date: Fri, 31 May 2013 00:34:11 +0200 Subject: [PATCH] Allow multiline descriptions --- store.go | 3 ++- templates/book.html | 8 ++++---- trantor.go | 7 +++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/store.go b/store.go index 8e3c5c7..e50e65f 100644 --- a/store.go +++ b/store.go @@ -87,7 +87,8 @@ func parseAuthr(creator []string) []string { } func parseDescription(description []string) string { - str := cleanStr(strings.Join(description, ", ")) + str := cleanStr(strings.Join(description, "\n")) + str = strings.Replace(str, "

", "\n", -1) exp, _ := regexp.Compile("<[^>]*>") str = exp.ReplaceAllString(str, "") str = strings.Replace(str, "&", "&", -1) diff --git a/templates/book.html b/templates/book.html index 02f273f..efb4eed 100644 --- a/templates/book.html +++ b/templates/book.html @@ -60,16 +60,16 @@ function delBook(){ +{{end}}
- {{if .Description}}
-

{{.Description}}

-
+ {{range .Description}} +

{{.}}

{{end}}
+ -{{end}} {{template "footer.html"}} diff --git a/trantor.go b/trantor.go index 418f53e..155309c 100644 --- a/trantor.go +++ b/trantor.go @@ -6,6 +6,7 @@ import ( "labix.org/v2/mgo/bson" "log" "net/http" + "strings" ) type aboutData struct { @@ -43,8 +44,9 @@ func loginHandler(w http.ResponseWriter, r *http.Request, sess *Session) { } type bookData struct { - S Status - Book Book + S Status + Book Book + Description []string } func bookHandler(w http.ResponseWriter, r *http.Request, sess *Session) { @@ -64,6 +66,7 @@ func bookHandler(w http.ResponseWriter, r *http.Request, sess *Session) { } db.IncVisit(id) data.Book = books[0] + data.Description = strings.Split(data.Book.Description, "\n") loadTemplate(w, "book", data) }