Beispiel #1
0
func index(defaultProvider string, w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/html")

	t := template.New("index")

	selected := func(p string) string {
		if p == defaultProvider {
			return " selected"
		}

		return ""
	}

	t.Funcs(template.FuncMap{
		"Selected": selected,
	})

	t, _ = t.Parse(IndexTemplate)

	tvars := templateVars{
		CSS:         IndexCSS,
		JS:          IndexJS,
		Placeholder: "kittens...",
		Providers:   providers.ProviderNames(),
	}

	t.Execute(w, tvars)
}
Beispiel #2
0
func index(defaultProvider string, w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/html")

	t := template.New("index")

	selected := func(p string) string {
		if p == defaultProvider {
			return " selected"
		}

		return ""
	}

	label := func(opt string) string {
		if opt == "" {
			return fmt.Sprintf(" label=%q", "-")
		}

		return ""
	}

	t.Funcs(template.FuncMap{
		"Selected": selected,
		"Label":    label,
	})

	t, _ = t.Parse(indexTemplate)

	providerList := []string{""}
	providerList = append(providerList, providers.ProviderNames(false)...)

	tagList := []string{""}
	tagList = append(tagList, providers.TagNames(false)...)

	tvars := templateVars{
		CSS:         indexCSS,
		JS:          indexJS(defaultProvider),
		Placeholder: "kittens...",
		Providers:   providerList,
		Tags:        tagList,
	}

	t.Execute(w, tvars)
}