ctdo.de/html.go

45 lines
1.3 KiB
Go
Raw Normal View History

package main
import "strings"
func html_Element(tag string, innerHTML string, args string) string {
return "<" + tag + " " + args + ">" + innerHTML + "</" + tag + ">"
}
func html_LinkElement(innerHTML string, destination string, blank bool, args string) string {
b := ""
if blank {
b = "target=\"_blank\""
}
return html_Element("a", innerHTML, " href=\""+destination+"\" "+b)
}
func html_InputElement(name string, _type string, value string, args string) string {
return "<input name=\"" + name + "\" type=\"" + _type + "\" value=\"" + value + "\" " + args + ">"
}
func html_Nav(pages [][]string) string {
output := ""
for _, page := range pages {
output += html_Element("li", html_LinkElement(page[0], page[1], false, ""), "")
}
return html_Element("nav", html_Element("ul", output, ""), "")
}
func html_replacer(input string) string {
output := strings.ReplaceAll(input, "!NAV", html_Nav(getPages()))
if getRoomState().state {
output = strings.ReplaceAll(output, "!RAUMSTATUS", "<p>Raumstatus: <b class=\"green-text\">offen</b></p>")
} else {
output = strings.ReplaceAll(output, "!RAUMSTATUS", "<p>Raumstatus: <b class=\"red-text\">geschlossen</b></p>")
}
output = strings.ReplaceAll(output, "!FOOTERNAV", html_Nav(getFooterPages()))
return output
}