From b5470ba3962d44f0371fcb646a23645e77da5367 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Mon, 2 Nov 2015 18:52:05 +0900 Subject: [PATCH] Adding ways to create new files --- goldsmith.go | 30 +++++++++++++++++++++++++----- types.go | 3 +++ 2 files changed, 28 insertions(+), 5 deletions(-) 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 }