diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2019-06-03 05:43:47 +0800 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2019-06-03 00:43:47 +0300 |
commit | 83b90e41999d30e4abb46f6bf0f1c3359cfd4d04 (patch) | |
tree | 4a15e9a42a850534a00346116da84153600a3027 /modules/templates | |
parent | 8eba27c79257c6bc68cefbdffbb36d3596e6d3ee (diff) | |
download | gitea-83b90e41999d30e4abb46f6bf0f1c3359cfd4d04.tar.gz gitea-83b90e41999d30e4abb46f6bf0f1c3359cfd4d04.zip |
Use vfsgen instead of go-bindata (#7080)
* use vfsgen instead of go-bindata
* fix templates
* fix fmt
* vendor vsfgen
Diffstat (limited to 'modules/templates')
-rw-r--r-- | modules/templates/main.go | 23 | ||||
-rw-r--r-- | modules/templates/static.go | 18 | ||||
-rw-r--r-- | modules/templates/templates.go | 4 |
3 files changed, 42 insertions, 3 deletions
diff --git a/modules/templates/main.go b/modules/templates/main.go new file mode 100644 index 0000000000..4460f58cbf --- /dev/null +++ b/modules/templates/main.go @@ -0,0 +1,23 @@ +// +build ignore + +package main + +import ( + "log" + "net/http" + + "github.com/shurcooL/vfsgen" +) + +func main() { + var fsTemplates http.FileSystem = http.Dir("../../templates") + err := vfsgen.Generate(fsTemplates, vfsgen.Options{ + PackageName: "templates", + BuildTags: "bindata", + VariableName: "Assets", + Filename: "bindata.go", + }) + if err != nil { + log.Fatal("%v", err) + } +} diff --git a/modules/templates/static.go b/modules/templates/static.go index e69e1cae48..3aabe17e4f 100644 --- a/modules/templates/static.go +++ b/modules/templates/static.go @@ -203,3 +203,21 @@ func Mailer() *template.Template { return templates } + +func Asset(name string) ([]byte, error) { + f, err := Assets.Open("/" + name) + if err != nil { + return nil, err + } + defer f.Close() + return ioutil.ReadAll(f) +} + +func AssetNames() []string { + realFS := Assets.(vfsgen۰FS) + var results = make([]string, 0, len(realFS)) + for k := range realFS { + results = append(results, k[1:]) + } + return results +} diff --git a/modules/templates/templates.go b/modules/templates/templates.go index 91c8db5228..e7fe3b2bfb 100644 --- a/modules/templates/templates.go +++ b/modules/templates/templates.go @@ -4,7 +4,5 @@ package templates -//go:generate go-bindata -tags "bindata" -ignore "\\.go" -pkg "templates" -o "bindata.go" ../../templates/... +//go:generate go run -mod=vendor main.go //go:generate go fmt bindata.go -//go:generate sed -i.bak s/..\/..\/templates\/// bindata.go -//go:generate rm -f bindata.go.bak |