File size: 1,903 Bytes
530729e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package login

import (
	"bytes"
	"fmt"
	"html/template"
	"strings"

	"github.com/GoAdminGroup/go-admin/modules/language"
	"github.com/GoAdminGroup/go-admin/modules/logger"
)

type Installation struct {
	Name string
}

func Get() *Installation {
	return &Installation{
		Name: "installation",
	}
}

var DefaultFuncMap = template.FuncMap{
	"lang":     language.Get,
	"langHtml": language.GetFromHtml,
	"link": func(cdnUrl, prefixUrl, assetsUrl string) string {
		if cdnUrl == "" {
			return prefixUrl + assetsUrl
		}
		return cdnUrl + assetsUrl
	},
	"isLinkUrl": func(s string) bool {
		return (len(s) > 7 && s[:7] == "http://") || (len(s) > 8 && s[:8] == "https://")
	},
	"render": func(s, old, repl template.HTML) template.HTML {
		return template.HTML(strings.ReplaceAll(string(s), string(old), string(repl)))
	},
	"renderJS": func(s template.JS, old, repl template.HTML) template.JS {
		return template.JS(strings.ReplaceAll(string(s), string(old), string(repl)))
	},
	"divide": func(a, b int) int {
		return a / b
	},
}

func (i *Installation) GetTemplate() (*template.Template, string) {
	tmpl, err := template.New("installation").
		Funcs(DefaultFuncMap).
		Parse(List["installation"])

	if err != nil {
		logger.Error("Installation GetTemplate Error: ", err)
	}

	return tmpl, "installation"
}

func (i *Installation) GetAssetList() []string               { return AssetsList }
func (i *Installation) GetAsset(name string) ([]byte, error) { return Asset(name[1:]) }
func (i *Installation) IsAPage() bool                        { return true }
func (i *Installation) GetName() string                      { return "login" }

func (i *Installation) GetContent() template.HTML {
	buffer := new(bytes.Buffer)
	tmpl, defineName := i.GetTemplate()
	err := tmpl.ExecuteTemplate(buffer, defineName, i)
	if err != nil {
		fmt.Println("ComposeHtml Error:", err)
	}
	return template.HTML(buffer.String())
}