github.com/gocaveman/caveman@v0.0.0-20191211162744-0ddf99dbdf6e/uiproto/files/files.go (about) 1 package files 2 3 import ( 4 "net/http" 5 "path" 6 7 "github.com/gocaveman/caveman/filesystem/fsutil" 8 "github.com/gocaveman/caveman/tmpl" 9 "github.com/gocaveman/caveman/tmpl/tmplregistry" 10 ) 11 12 //go:generate go run files-gogen.go 13 14 func init() { 15 16 // TODO: static stuff 17 18 tmplregistry.MustRegister(tmplregistry.SeqTheme, "files", NewTmplStore()) 19 20 } 21 22 func NewViewsFS() http.FileSystem { 23 return fsutil.NewHTTPFuncFS(func(name string) (http.File, error) { 24 return EmbeddedAssets.Open("/views" + path.Clean("/"+name)) 25 }) 26 } 27 28 func NewIncludesFS() http.FileSystem { 29 return fsutil.NewHTTPFuncFS(func(name string) (http.File, error) { 30 return EmbeddedAssets.Open("/includes" + path.Clean("/"+name)) 31 }) 32 } 33 34 func NewTmplStore() tmpl.Store { 35 return &tmpl.HFSStore{ 36 FileSystems: map[string]http.FileSystem{ 37 tmpl.ViewsCategory: NewViewsFS(), 38 tmpl.IncludesCategory: NewIncludesFS(), 39 }, 40 } 41 }