diff --git a/goldsmith.go b/goldsmith.go index 562e746..3c9de04 100644 --- a/goldsmith.go +++ b/goldsmith.go @@ -24,6 +24,7 @@ package goldsmith import ( "bytes" + "fmt" "os" "path" "path/filepath" @@ -69,11 +70,7 @@ func (gs *goldsmith) scan() { panic(err) } - file := &File{ - Path: relPath, - Meta: make(map[string]interface{}), - Buff: new(bytes.Buffer), - } + file, _ := gs.NewFile(relPath) var f *os.File if f, file.Err = os.Open(match); file.Err == nil { @@ -178,6 +175,29 @@ func (gs *goldsmith) chainMultiple(s stage, cm ChainerMultiple, globs []string) } } +func (gs *goldsmith) NewFile(path string) (*File, error) { + if filepath.IsAbs(path) { + return nil, fmt.Errorf("absolute paths are not supported: %s", path) + } + + file := &File{ + Path: path, + Meta: make(map[string]interface{}), + Buff: new(bytes.Buffer), + } + + return file, nil +} + +func (gs *goldsmith) RefFile(path string) error { + if filepath.IsAbs(path) { + return fmt.Errorf("absolute paths are not supported: %s", path) + } + + gs.refs[path] = true + return nil +} + func (gs *goldsmith) SrcDir() string { return gs.srcDir } diff --git a/types.go b/types.go index 22011ca..d4df79c 100644 --- a/types.go +++ b/types.go @@ -45,6 +45,9 @@ type File struct { } type Context interface { + NewFile(path string) (*File, error) + RefFile(path string) error + SrcDir() string DstDir() string }