This commit is contained in:
Alex Yatskov 2024-03-03 21:39:08 -08:00
parent 889397b9c5
commit cd2e515141
4 changed files with 47 additions and 41 deletions

View File

@ -29,7 +29,9 @@ type Builder interface {
// website until it is terminated.
func DevServe(builder Builder, port int, sourceDir, targetDir, cacheDir string, watchDirs ...string) {
dirs := append(watchDirs, sourceDir)
build(dirs, func() { builder.Build(sourceDir, targetDir, cacheDir) })
build(dirs, func() {
builder.Build(sourceDir, targetDir, cacheDir)
})
httpAddr := fmt.Sprintf(":%d", port)
httpHandler := http.FileServer(http.Dir(targetDir))

View File

@ -2,29 +2,31 @@ package goldsmith
// Plugin contains the minimum set of methods required on plugins. Plugins can
// also optionally implement Initializer, Processor, and Finalizer interfaces.
type Plugin interface {
Name() string
}
type (
Plugin interface {
Name() string
}
// Initializer is used to optionally initialize a plugin and to specify a
// filter to be used for determining which files will be processed.
type Initializer interface {
Initialize(context *Context) error
}
// Initializer is used to optionally initialize a plugin and to specify a
// filter to be used for determining which files will be processed.
Initializer interface {
Initialize(context *Context) error
}
// Processor allows for optional processing of files passing through a plugin.
type Processor interface {
Process(context *Context, file *File) error
}
// Processor allows for optional processing of files passing through a plugin.
Processor interface {
Process(context *Context, file *File) error
}
// Finalizer allows for optional finalization of a plugin after all files
// queued in the chain have passed through it.
type Finalizer interface {
Finalize(context *Context) error
}
// Finalizer allows for optional finalization of a plugin after all files
// queued in the chain have passed through it.
Finalizer interface {
Finalize(context *Context) error
}
// Filter is used to determine which files should continue in the chain.
type Filter interface {
Name() string
Accept(file *File) bool
}
// Filter is used to determine which files should continue in the chain.
Filter interface {
Name() string
Accept(file *File) bool
}
)

26
file.go
View File

@ -12,21 +12,21 @@ import (
type (
FileProp any
FileProps map[string]FileProp
// File represents in-memory or on-disk files in a chain.
File struct {
relPath string
props FileProps
modTime time.Time
size int64
dataPath string
reader *bytes.Reader
index int
}
)
// File represents in-memory or on-disk files in a chain.
type File struct {
relPath string
props FileProps
modTime time.Time
size int64
dataPath string
reader *bytes.Reader
index int
}
// Rename modifies the file path relative to the source directory.
func (self *File) Rename(path string) error {
if filepath.IsAbs(path) {

View File

@ -1,11 +1,13 @@
package goldsmith
type filterEntry struct {
filter Filter
index int
}
type (
filterEntry struct {
filter Filter
index int
}
type filterStack []filterEntry
filterStack []filterEntry
)
func (self *filterStack) accept(file *File) bool {
for _, entry := range *self {