Cleanup
This commit is contained in:
parent
42c98df5f7
commit
488ccdebe4
@ -2,16 +2,23 @@ package sideload
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"embed"
|
||||
"io/fs"
|
||||
"path/filepath"
|
||||
|
||||
"git.foosoft.net/alex/goldsmith"
|
||||
)
|
||||
|
||||
type Sideload struct {
|
||||
type (
|
||||
Sideload struct {
|
||||
files []*goldsmith.File
|
||||
fileSystems []embed.FS
|
||||
}
|
||||
fileSystems []sideloadFs
|
||||
}
|
||||
|
||||
sideloadFs interface {
|
||||
fs.ReadDirFS
|
||||
fs.ReadFileFS
|
||||
}
|
||||
)
|
||||
|
||||
func New() *Sideload {
|
||||
return &Sideload{}
|
||||
@ -45,12 +52,15 @@ func (self *Sideload) Files(files ...*goldsmith.File) *Sideload {
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *Sideload) FileSystems(fileSystems ...embed.FS) *Sideload {
|
||||
self.fileSystems = append(self.fileSystems, fileSystems...)
|
||||
func (self *Sideload) FileSystems(fileSystems ...fs.FS) *Sideload {
|
||||
for _, fileSystem := range fileSystems {
|
||||
self.fileSystems = append(self.fileSystems, fileSystem.(sideloadFs))
|
||||
}
|
||||
|
||||
return self
|
||||
}
|
||||
|
||||
func (self *Sideload) gatherFsFiles(context *goldsmith.Context, fileSystem embed.FS, path string) ([]*goldsmith.File, error) {
|
||||
func (self *Sideload) gatherFsFiles(context *goldsmith.Context, fileSystem sideloadFs, path string) ([]*goldsmith.File, error) {
|
||||
entries, err := fileSystem.ReadDir(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -1,6 +1,7 @@
|
||||
package sideload
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"testing"
|
||||
|
||||
"embed"
|
||||
@ -13,10 +14,15 @@ import (
|
||||
var embedFs embed.FS
|
||||
|
||||
func Test(self *testing.T) {
|
||||
subFs, err := fs.Sub(embedFs, "testdata/source")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
harness.Validate(
|
||||
self,
|
||||
func(gs *goldsmith.Goldsmith) {
|
||||
gs.Chain(New().FileSystems(embedFs))
|
||||
gs.Chain(New().FileSystems(subFs))
|
||||
},
|
||||
)
|
||||
}
|
||||
|
0
plugins/sideload/testdata/reference/1.txt
vendored
Normal file
0
plugins/sideload/testdata/reference/1.txt
vendored
Normal file
0
plugins/sideload/testdata/reference/child/2.txt
vendored
Normal file
0
plugins/sideload/testdata/reference/child/2.txt
vendored
Normal file
Loading…
Reference in New Issue
Block a user