Files
api_web_manager/web/render/render.go

62 lines
1.5 KiB
Go

package render
import (
"fmt"
"os"
"strings"
)
func Template_with_string(str string) string {
head, err := os.ReadFile("web/views/head.html")
foot, err := os.ReadFile("web/views/foot.html")
template := "" + string(head) + str + string(foot)
fmt.Println(err)
return template
}
func Template_with_page(str string) string {
head, err := os.ReadFile("web/views/head.html")
foot, err := os.ReadFile("web/views/foot.html")
page, err := os.ReadFile("web/views/" + str + ".html")
template := "" + string(head) + string(page) + string(foot)
fmt.Println(err)
return template
}
func Template_with_page_vars(str string, tags_and_variables map[string]string) string {
head, err := os.ReadFile("web/views/head.html")
foot, err := os.ReadFile("web/views/foot.html")
page := ""
for tag, varr := range tags_and_variables {
page = templating(str, tag, varr)
}
template := "" + string(head) + string(page) + string(foot)
fmt.Println(err)
return template
}
func Template_of_tag(str string, html_tag string) string {
tag, err := os.ReadFile("web/views/tag/" + html_tag + ".html")
result := strings.Replace(string(tag), "<fnr>", str, 1)
fmt.Println(err)
return result
}
func templating(file string, tag string, variable string) string {
content, err := os.ReadFile("web/views/" + file + ".html")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
find_tag := `{` + tag + `}`
template_result := strings.Replace(string(content), find_tag, variable, 1)
return template_result
}