diff options
author | jan <jan@ruken.pw> | 2015-12-18 14:15:15 (UTC) |
---|---|---|
committer | jan <jan@ruken.pw> | 2015-12-18 14:15:15 (UTC) |
commit | bdf4e9cc5c5934281631af09bf9a7d58719d0cbb (patch) | |
tree | 708429d7ed6fca2a0ab83d36d68fca05fa4ca958 /frontend | |
parent | 2a27df2954e925ea17fd7d7dd7db787c1694e3b5 (diff) |
kleiner renderer inklusive benutzung von charakterin.
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/renderer.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/frontend/renderer.go b/frontend/renderer.go new file mode 100644 index 0000000..5673860 --- /dev/null +++ b/frontend/renderer.go | |||
@@ -0,0 +1,33 @@ | |||
1 | package frontend | ||
2 | |||
3 | import ( | ||
4 | "html/template" | ||
5 | "net/http" | ||
6 | ) | ||
7 | |||
8 | // Renderer rendert Seiten. | ||
9 | type Renderer struct { | ||
10 | templates *template.Template | ||
11 | } | ||
12 | |||
13 | // New erstellt einen neuen Renderer und sucht alle Templates aus dem gegebenen pfad. | ||
14 | func New(path string) *Renderer { | ||
15 | r := &Renderer{ | ||
16 | template.Must(template.ParseGlob(path + "/*")), | ||
17 | } | ||
18 | |||
19 | return r | ||
20 | } | ||
21 | |||
22 | // RenderPage rendert eine bestimmte Seite (basierend auf dem Template-Namen) und den gegebenen Daten. | ||
23 | func (r *Renderer) RenderPage(name string, w http.ResponseWriter, data map[string]interface{}) { | ||
24 | err := r.templates.ExecuteTemplate(w, name, data) | ||
25 | if err != nil { | ||
26 | http.Error(w, err.Error(), http.StatusInternalServerError) | ||
27 | } | ||
28 | } | ||
29 | |||
30 | // RenderLoginPage zeigt die Loginseite an. | ||
31 | func (r *Renderer) RenderLoginPage(w http.ResponseWriter, data map[string]interface{}) { | ||
32 | r.RenderPage("login", w, data) | ||
33 | } | ||