diff --git a/file.go b/file.go index 19a5aef..ab151f6 100644 --- a/file.go +++ b/file.go @@ -30,6 +30,7 @@ import ( type file struct { path string meta map[string]interface{} + buff *bytes.Buffer } func (f *file) Path() string { @@ -50,6 +51,10 @@ func (f *file) SetProperty(key string, value interface{}) { } func (f *file) Data() (*bytes.Buffer, error) { + if f.buff != nil { + return f.buff, nil + } + file, err := os.Open(f.path) if err != nil { return nil, err @@ -61,5 +66,6 @@ func (f *file) Data() (*bytes.Buffer, error) { return nil, err } - return &buff, nil + f.buff = &buff + return f.buff, nil } diff --git a/goldsmith.go b/goldsmith.go index c0ec452..ae280cf 100644 --- a/goldsmith.go +++ b/goldsmith.go @@ -64,7 +64,7 @@ func (gs *goldsmith) scan() error { return err } - gs.files <- &file{path, make(map[string]interface{})} + gs.files <- gs.NewFile(path) } return nil @@ -82,12 +82,16 @@ func (gs *goldsmith) stage() stage { return s } -func (gs *goldsmith) AbsSrcPath(path string) string { - return filepath.Join(gs.srcPath, path) +func (gs *goldsmith) SrcPath(path string) string { + return gs.srcPath } -func (gs *goldsmith) AbsDstPath(path string) string { - return filepath.Join(gs.dstPath, path) +func (gs *goldsmith) DstPath(path string) string { + return gs.dstPath +} + +func (gs *goldsmith) NewFile(path string) File { + return &file{path, make(map[string]interface{}), nil} } func (gs *goldsmith) Apply(p Processor) Applier { diff --git a/types.go b/types.go index 1577ed1..d701a69 100644 --- a/types.go +++ b/types.go @@ -25,8 +25,10 @@ package goldsmith import "bytes" type Context interface { - AbsSrcPath(path string) string - AbsDstPath(path string) string + SrcPath(path string) string + DstPath(path string) string + + NewFile(path string) File } type File interface {