Cleanup
This commit is contained in:
parent
42c98df5f7
commit
488ccdebe4
@ -2,16 +2,23 @@ package sideload
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"embed"
|
"io/fs"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"git.foosoft.net/alex/goldsmith"
|
"git.foosoft.net/alex/goldsmith"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Sideload struct {
|
type (
|
||||||
|
Sideload struct {
|
||||||
files []*goldsmith.File
|
files []*goldsmith.File
|
||||||
fileSystems []embed.FS
|
fileSystems []sideloadFs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sideloadFs interface {
|
||||||
|
fs.ReadDirFS
|
||||||
|
fs.ReadFileFS
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
func New() *Sideload {
|
func New() *Sideload {
|
||||||
return &Sideload{}
|
return &Sideload{}
|
||||||
@ -45,12 +52,15 @@ func (self *Sideload) Files(files ...*goldsmith.File) *Sideload {
|
|||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Sideload) FileSystems(fileSystems ...embed.FS) *Sideload {
|
func (self *Sideload) FileSystems(fileSystems ...fs.FS) *Sideload {
|
||||||
self.fileSystems = append(self.fileSystems, fileSystems...)
|
for _, fileSystem := range fileSystems {
|
||||||
|
self.fileSystems = append(self.fileSystems, fileSystem.(sideloadFs))
|
||||||
|
}
|
||||||
|
|
||||||
return self
|
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)
|
entries, err := fileSystem.ReadDir(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package sideload
|
package sideload
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/fs"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"embed"
|
"embed"
|
||||||
@ -13,10 +14,15 @@ import (
|
|||||||
var embedFs embed.FS
|
var embedFs embed.FS
|
||||||
|
|
||||||
func Test(self *testing.T) {
|
func Test(self *testing.T) {
|
||||||
|
subFs, err := fs.Sub(embedFs, "testdata/source")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
harness.Validate(
|
harness.Validate(
|
||||||
self,
|
self,
|
||||||
func(gs *goldsmith.Goldsmith) {
|
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