Files
EdgeAdmin/internal/web/actions/default/ui/components.go

43 lines
832 B
Go
Raw Normal View History

2020-07-22 22:19:39 +08:00
package ui
import (
"bytes"
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/files"
"github.com/iwind/TeaGo/logs"
)
type ComponentsAction actions.Action
func (this *ComponentsAction) RunGet(params struct{}) {
this.AddHeader("Content-Type", "text/javascript; charset=utf-8")
var webRoot string
if Tea.IsTesting() {
webRoot = Tea.Root + "/../web/public/js/components/"
} else {
webRoot = Tea.Root + "/web/public/js/components/"
}
f := files.NewFile(webRoot)
buf := bytes.NewBuffer([]byte{})
f.Range(func(file *files.File) {
if !file.IsFile() {
return
}
if file.Ext() != ".js" {
return
}
data, err := file.ReadAll()
if err != nil {
logs.Error(err)
return
}
buf.Write(data)
buf.WriteByte('\n')
buf.WriteByte('\n')
})
this.Write(buf.Bytes())
}