Browse Source

Optimization

Vova Tkach 5 years ago
parent
commit
9cd16b4d87
3 changed files with 26 additions and 44 deletions
  1. 1 22
      engine/fetdata/fetdata.go
  2. 1 22
      engine/wrapper/wrapper.go
  3. 24 0
      utils/utils.go

+ 1 - 22
engine/fetdata/fetdata.go

@@ -136,28 +136,7 @@ func (this *FERData) EscapeString(str string) string {
 }
 
 func (this *FERData) cachedBlock(block string) template.HTML {
-	tmplFuncs := template.FuncMap{
-		"plus": func(a, b int) int {
-			return a + b
-		},
-		"minus": func(a, b int) int {
-			return a - b
-		},
-		"multiply": func(a, b int) int {
-			return a * b
-		},
-		"divide": func(a, b int) int {
-			return a / b
-		},
-		"repeat": func(a string, n int) template.HTML {
-			out := ""
-			for i := 1; i <= n; i++ {
-				out += a
-			}
-			return template.HTML(out)
-		},
-	}
-	tmpl, err := template.New(block + ".html").Funcs(tmplFuncs).ParseFiles(
+	tmpl, err := template.New(block + ".html").Funcs(utils.TemplateAdditionalFuncs()).ParseFiles(
 		this.wrap.DTemplate + string(os.PathSeparator) + block + ".html",
 	)
 	if err != nil {

+ 1 - 22
engine/wrapper/wrapper.go

@@ -203,28 +203,7 @@ func (this *Wrapper) RenderToString(tcont []byte, data interface{}) string {
 }
 
 func (this *Wrapper) RenderFrontEnd(tname string, data interface{}, status int) {
-	tmplFuncs := template.FuncMap{
-		"plus": func(a, b int) int {
-			return a + b
-		},
-		"minus": func(a, b int) int {
-			return a - b
-		},
-		"multiply": func(a, b int) int {
-			return a * b
-		},
-		"divide": func(a, b int) int {
-			return a / b
-		},
-		"repeat": func(a string, n int) template.HTML {
-			out := ""
-			for i := 1; i <= n; i++ {
-				out += a
-			}
-			return template.HTML(out)
-		},
-	}
-	tmpl, err := template.New(tname+".html").Funcs(tmplFuncs).ParseFiles(
+	tmpl, err := template.New(tname+".html").Funcs(utils.TemplateAdditionalFuncs()).ParseFiles(
 		this.DTemplate+string(os.PathSeparator)+tname+".html",
 		this.DTemplate+string(os.PathSeparator)+"header.html",
 		this.DTemplate+string(os.PathSeparator)+"sidebar-left.html",

+ 24 - 0
utils/utils.go

@@ -416,3 +416,27 @@ func ArrayOfStringToArrayOfInt(arr []string) []int {
 	}
 	return res
 }
+
+func TemplateAdditionalFuncs() template.FuncMap {
+	return template.FuncMap{
+		"plus": func(a, b int) int {
+			return a + b
+		},
+		"minus": func(a, b int) int {
+			return a - b
+		},
+		"multiply": func(a, b int) int {
+			return a * b
+		},
+		"divide": func(a, b int) int {
+			return a / b
+		},
+		"repeat": func(a string, n int) template.HTML {
+			out := ""
+			for i := 1; i <= n; i++ {
+				out += a
+			}
+			return template.HTML(out)
+		},
+	}
+}