summaryrefslogtreecommitdiff
blob: 77f1383190f73c2720587e9139c34923099e7a95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// miscellaneous utility functions used for the about pages of the application

package about

import (
	"glsamaker/pkg/models"
	"glsamaker/pkg/models/users"
	"html/template"
	"net/http"
)

// renderAboutTemplate renders all templates used for the main about page
func renderAboutTemplate(w http.ResponseWriter, user *users.User) {
	templates := template.Must(
		template.Must(
			template.New("Show").
				ParseGlob("web/templates/layout/*.tmpl")).
			ParseGlob("web/templates/about/*.tmpl"))

	templates.ExecuteTemplate(w, "about.tmpl", createPageData("about", user))
}

// renderAboutSearchTemplate renders all templates used for
// the about page about the search functionality
func renderAboutSearchTemplate(w http.ResponseWriter, user *users.User) {
	templates := template.Must(
		template.Must(
			template.New("Show").
				ParseGlob("web/templates/layout/*.tmpl")).
			ParseGlob("web/templates/about/*.tmpl"))

	templates.ExecuteTemplate(w, "aboutSearch.tmpl", createPageData("about", user))
}

// renderAboutCLITemplate renders all templates used for
// the about page about the command line tool
func renderAboutCLITemplate(w http.ResponseWriter, user *users.User) {
	templates := template.Must(
		template.Must(
			template.New("Show").
				ParseGlob("web/templates/layout/*.tmpl")).
			ParseGlob("web/templates/about/*.tmpl"))

	templates.ExecuteTemplate(w, "aboutCLI.tmpl", createPageData("about", user))
}

// createPageData creates the data used in the templates of the about pages
func createPageData(page string, user *users.User) interface{} {
	return struct {
		Page        string
		Application *models.GlobalSettings
		User        *users.User
	}{
		Page:        page,
		Application: models.GetDefaultGlobalSettings(),
		User:        user,
	}
}