New file creation

This commit is contained in:
Alex Yatskov 2015-10-29 23:36:01 +09:00
parent 71837cf160
commit 8b9d841c7c
3 changed files with 20 additions and 8 deletions

View File

@ -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
}

View File

@ -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 {

View File

@ -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 {