From c6de9b92bee5438bb5a0f6b096c986bfbde1c2ad Mon Sep 17 00:00:00 2001 From: Azareal Date: Mon, 14 May 2018 20:59:18 +1000 Subject: [PATCH] Hopefully this'll work. --- common/files.go | 4 +- common/template_init.go | 7 +- template_list.go | 148 +++++++++++++++------------------------- tmpl_client/filler.txt | 1 - tmpl_client/stub.go | 3 + tmpl_stub.go | 3 + 6 files changed, 67 insertions(+), 99 deletions(-) delete mode 100644 tmpl_client/filler.txt create mode 100644 tmpl_client/stub.go create mode 100644 tmpl_stub.go diff --git a/common/files.go b/common/files.go index aa06e7d0..361f64be 100644 --- a/common/files.go +++ b/common/files.go @@ -39,13 +39,13 @@ type CSSData struct { func (list SFileList) JSTmplInit() error { var fragMap = make(map[string][][]byte) - fragMap["alert"] = tmpl.Get_alert_frags() // TODO: Add a generic fetch function, so we don't rely on the presence of the template files for this + fragMap["alert"] = tmpl.GetFrag("alert") fmt.Println("fragMap: ", fragMap) return filepath.Walk("./tmpl_client", func(path string, f os.FileInfo, err error) error { if f.IsDir() { return nil } - if strings.HasSuffix(path, "template_list.go") { + if strings.HasSuffix(path, "template_list.go") || strings.HasSuffix(path, "stub.go") { return nil } diff --git a/common/template_init.go b/common/template_init.go index 2aafb4d3..c40bebc8 100644 --- a/common/template_init.go +++ b/common/template_init.go @@ -343,11 +343,14 @@ func writeTemplateList(c *tmpl.CTemplateSet, wg *sync.WaitGroup, prefix string) wg.Add(1) go func() { out := "package " + c.GetConfig().PackageName + "\n\n" + var getterstr = "\n// nolint\nGetFrag = func(name string) [][]byte {\nswitch(name) {\n" for templateName, count := range c.TemplateFragmentCount { out += "var " + templateName + "_frags = make([][]byte," + strconv.Itoa(count) + ")\n" - out += "\n// nolint\nfunc Get_" + templateName + "_frags() [][]byte {\nreturn " + templateName + "_frags\n}\n" + getterstr += "\tcase \"" + templateName + "\":\n" + getterstr += "\treturn " + templateName + "_frags\n" } - out += "\n// nolint\nfunc init() {\n" + c.FragOut + "}\n" + getterstr += "}\nreturn nil\n}\n" + out += "\n// nolint\nfunc init() {\n" + c.FragOut + "\n" + getterstr + "}\n" err := writeFile(prefix+"template_list.go", out) if err != nil { log.Fatal(err) diff --git a/template_list.go b/template_list.go index fec440f8..f442e444 100644 --- a/template_list.go +++ b/template_list.go @@ -1,101 +1,21 @@ package main -var error_frags = make([][]byte,4) - -// nolint -func Get_error_frags() [][]byte { -return error_frags -} -var profile_comments_row_frags = make([][]byte,51) - -// nolint -func Get_profile_comments_row_frags() [][]byte { -return profile_comments_row_frags -} -var topic_alt_frags = make([][]byte,200) - -// nolint -func Get_topic_alt_frags() [][]byte { -return topic_alt_frags -} -var profile_frags = make([][]byte,50) - -// nolint -func Get_profile_frags() [][]byte { -return profile_frags -} -var ip_search_frags = make([][]byte,18) - -// nolint -func Get_ip_search_frags() [][]byte { -return ip_search_frags -} -var header_frags = make([][]byte,26) - -// nolint -func Get_header_frags() [][]byte { -return header_frags -} -var forums_frags = make([][]byte,26) - -// nolint -func Get_forums_frags() [][]byte { -return forums_frags -} var login_frags = make([][]byte,8) - -// nolint -func Get_login_frags() [][]byte { -return login_frags -} -var register_frags = make([][]byte,9) - -// nolint -func Get_register_frags() [][]byte { -return register_frags -} -var footer_frags = make([][]byte,13) - -// nolint -func Get_footer_frags() [][]byte { -return footer_frags -} -var topic_frags = make([][]byte,199) - -// nolint -func Get_topic_frags() [][]byte { -return topic_frags -} -var paginator_frags = make([][]byte,16) - -// nolint -func Get_paginator_frags() [][]byte { -return paginator_frags -} -var topics_frags = make([][]byte,98) - -// nolint -func Get_topics_frags() [][]byte { -return topics_frags -} -var forum_frags = make([][]byte,90) - -// nolint -func Get_forum_frags() [][]byte { -return forum_frags -} -var guilds_guild_list_frags = make([][]byte,10) - -// nolint -func Get_guilds_guild_list_frags() [][]byte { -return guilds_guild_list_frags -} var notice_frags = make([][]byte,3) - -// nolint -func Get_notice_frags() [][]byte { -return notice_frags -} +var forums_frags = make([][]byte,26) +var paginator_frags = make([][]byte,16) +var forum_frags = make([][]byte,90) +var guilds_guild_list_frags = make([][]byte,10) +var header_frags = make([][]byte,26) +var topic_alt_frags = make([][]byte,200) +var topics_frags = make([][]byte,98) +var topic_frags = make([][]byte,199) +var profile_comments_row_frags = make([][]byte,51) +var register_frags = make([][]byte,9) +var ip_search_frags = make([][]byte,18) +var footer_frags = make([][]byte,13) +var profile_frags = make([][]byte,50) +var error_frags = make([][]byte,4) // nolint func init() { @@ -1757,4 +1677,44 @@ guilds_guild_list_frags[8] = []byte(` `) + + +// nolint +GetFrag = func(name string) [][]byte { +switch(name) { + case "login": + return login_frags + case "notice": + return notice_frags + case "forums": + return forums_frags + case "paginator": + return paginator_frags + case "forum": + return forum_frags + case "guilds_guild_list": + return guilds_guild_list_frags + case "header": + return header_frags + case "topic_alt": + return topic_alt_frags + case "topics": + return topics_frags + case "topic": + return topic_frags + case "profile_comments_row": + return profile_comments_row_frags + case "register": + return register_frags + case "ip_search": + return ip_search_frags + case "footer": + return footer_frags + case "profile": + return profile_frags + case "error": + return error_frags +} +return nil +} } diff --git a/tmpl_client/filler.txt b/tmpl_client/filler.txt deleted file mode 100644 index 20e14b1e..00000000 --- a/tmpl_client/filler.txt +++ /dev/null @@ -1 +0,0 @@ -This file is here so that Git will include this folder in the repository. \ No newline at end of file diff --git a/tmpl_client/stub.go b/tmpl_client/stub.go new file mode 100644 index 00000000..fd5e3c4c --- /dev/null +++ b/tmpl_client/stub.go @@ -0,0 +1,3 @@ +package tmpl + +var GetFrag func(name string) [][]byte diff --git a/tmpl_stub.go b/tmpl_stub.go new file mode 100644 index 00000000..8e31bef9 --- /dev/null +++ b/tmpl_stub.go @@ -0,0 +1,3 @@ +package main + +var GetFrag func(name string) [][]byte