changed lib removed map_args, project_dir debug; changed render added get_template; small changes to api,manager due to function delition; big change to web split listen and serve for server log and routing through switch-case
This commit is contained in:
@ -14,54 +14,55 @@ import (
|
||||
// loading default head and foot template and adding custom string in the middle
|
||||
func Template_with_string(str string) string {
|
||||
// loading head.html and foot.html
|
||||
head, err := os.ReadFile("web/views/head.html")
|
||||
foot, err := os.ReadFile("web/views/foot.html")
|
||||
// handling error by lib function and exiting if it occures
|
||||
lib.Handle_err(err, lib.Map_args("die", "1"))
|
||||
head, err := os.ReadFile(Get_template("head","")); lib.Handle_err(err, map[string]string{"die":"1"})
|
||||
foot, err := os.ReadFile(Get_template("foot","")); lib.Handle_err(err, map[string]string{"die":"1"})
|
||||
|
||||
// combining html parts
|
||||
template := "" + string(head) + str + string(foot)
|
||||
|
||||
lib.Debug(template,"Template_with_string") // debuging the template
|
||||
return template
|
||||
}
|
||||
|
||||
// loading default head and foot template and adding html template from file in the middle
|
||||
func Template_with_page(str string) string {
|
||||
// loading head.html and foot.html
|
||||
head, err := os.ReadFile("web/views/head.html")
|
||||
foot, err := os.ReadFile("web/views/foot.html")
|
||||
// loading custom html template file
|
||||
page, err := os.ReadFile("web/views/" + str + ".html")
|
||||
// handling error by lib function and exiting if it occures
|
||||
lib.Handle_err(err, lib.Map_args("die", "1"))
|
||||
head, err := os.ReadFile(Get_template("head","")); lib.Handle_err(err, map[string]string{"die":"1"})
|
||||
foot, err := os.ReadFile(Get_template("foot","")); lib.Handle_err(err, map[string]string{"die":"1"})
|
||||
// loading custom html template file
|
||||
page, err := os.ReadFile(Get_template(str,"part")); lib.Handle_err(err, map[string]string{"die":"1"})
|
||||
|
||||
// combining html parts
|
||||
template := "" + string(head) + string(page) + string(foot)
|
||||
|
||||
lib.Debug(template,"Template_with_page") // debuging the template output
|
||||
return template
|
||||
}
|
||||
|
||||
// loading default head and foot template and adding html template from tag file in the middle
|
||||
func Template_of_tag(html_tag string) string {
|
||||
// loading head.html and foot.html
|
||||
tag, err := os.ReadFile("web/views/tag/" + html_tag + ".html")
|
||||
// handling error by lib function and exiting if it occures
|
||||
lib.Handle_err(err, lib.Map_args("die", "1"))
|
||||
tag, err := os.ReadFile(Get_template(html_tag,"tag")); lib.Handle_err(err, map[string]string{"die":"1"})
|
||||
|
||||
lib.Debug(string(tag),"Template_of_tag") // debuging the template output
|
||||
return string(tag)
|
||||
}
|
||||
|
||||
// loading default head and foot template and adding html template from part file in the middle
|
||||
func Template_of_part(part_name string) string {
|
||||
// loading head.html and foot.html
|
||||
head, err := os.ReadFile("web/views/head.html")
|
||||
page, err := os.ReadFile("web/views/part/" + part_name + ".html")
|
||||
foot, err := os.ReadFile("web/views/foot.html")
|
||||
// handling error by lib function and exiting if it occures
|
||||
lib.Handle_err(err, lib.Map_args("die", "1"))
|
||||
head, err := os.ReadFile(Get_template("head","")); lib.Handle_err(err, map[string]string{"die":"1"})
|
||||
foot, err := os.ReadFile(Get_template("foot","")); lib.Handle_err(err, map[string]string{"die":"1"})
|
||||
page, err := os.ReadFile(Get_template(part_name,"part")); lib.Handle_err(err, map[string]string{"die":"1"})
|
||||
|
||||
|
||||
// combining html parts
|
||||
template := "" + string(head) + string(page) + string(foot)
|
||||
lib.Debug(template,"Template_of_part") // debuging the template output
|
||||
|
||||
return template
|
||||
}
|
||||
@ -74,5 +75,21 @@ func Put_vars_to_template(template string, vars map[string]string) string {
|
||||
template = strings.Replace(template, "{{"+tag+"}}", value, 1)
|
||||
}
|
||||
|
||||
lib.Debug(template,"Put_vars_to_template") // debuging the template output
|
||||
return template
|
||||
}
|
||||
|
||||
|
||||
// searchin default folder and retriving the template files in web views folder
|
||||
// type of template searching for sub folder in views
|
||||
func Get_template(path_to_template string, type_of_template string) string{
|
||||
path := ""
|
||||
if type_of_template == ""{
|
||||
path = lib.Project_dir()+"/web/views/"+path_to_template+".html";
|
||||
}else {
|
||||
path = lib.Project_dir()+"/web/views/"+type_of_template+"/"+path_to_template+".html";
|
||||
}
|
||||
|
||||
lib.Debug(path,"Get_template") // debuging the template
|
||||
return path;
|
||||
}
|
||||
Reference in New Issue
Block a user