Renaming variables

This commit is contained in:
Alex Yatskov 2015-12-18 19:19:43 +09:00
parent a26aeafd08
commit 6bb87248ab
4 changed files with 34 additions and 69 deletions

62
file.go
View File

@ -34,31 +34,13 @@ type file struct {
path string path string
meta map[string]interface{} meta map[string]interface{}
srcData []byte reader *bytes.Reader
srcReader *bytes.Reader asset string
srcPath string
}
func newFileFromData(path string, srcData []byte) *file {
return &file{
path: path,
meta: make(map[string]interface{}),
srcData: srcData,
srcReader: bytes.NewReader(srcData),
}
}
func newFileFromPath(path, srcPath string) *file {
return &file{
path: path,
meta: make(map[string]interface{}),
srcPath: srcPath,
}
} }
func (f *file) rewind() { func (f *file) rewind() {
if f.srcReader != nil { if f.reader != nil {
f.srcReader.Seek(0, os.SEEK_SET) f.reader.Seek(0, os.SEEK_SET)
} }
} }
@ -86,11 +68,11 @@ func (f *file) export(dstPath string) error {
} }
func (f *file) cache() error { func (f *file) cache() error {
if f.srcReader != nil { if f.reader != nil {
return nil return nil
} }
data, err := ioutil.ReadFile(f.srcPath) data, err := ioutil.ReadFile(f.asset)
if err != nil { if err != nil {
return err return err
} }
@ -111,21 +93,8 @@ func (f *file) Rename(path string) {
f.path = path f.path = path
} }
func (f *file) Keys() (keys []string) { func (f *file) Meta() map[string]interface{} {
for key := range f.meta { return f.meta
keys = append(keys, key)
}
return keys
}
func (f *file) Value(key string) (interface{}, bool) {
value, ok := f.meta[key]
return value, ok
}
func (f *file) SetValue(key string, value interface{}) {
f.meta[key] = value
} }
func (f *file) Read(p []byte) (int, error) { func (f *file) Read(p []byte) (int, error) {
@ -133,7 +102,7 @@ func (f *file) Read(p []byte) (int, error) {
return 0, err return 0, err
} }
return f.srcReader.Read(p) return f.reader.Read(p)
} }
func (f *file) WriteTo(w io.Writer) (int64, error) { func (f *file) WriteTo(w io.Writer) (int64, error) {
@ -141,18 +110,9 @@ func (f *file) WriteTo(w io.Writer) (int64, error) {
return 0, err return 0, err
} }
return f.srcReader.WriteTo(w) return f.reader.WriteTo(w)
} }
func (f *file) Rewrite(data []byte) { func (f *file) Rewrite(data []byte) {
f.srcData = data f.reader = bytes.NewReader(data)
f.srcReader = bytes.NewReader(data)
}
func (f *file) Bytes() []byte {
return f.srcData
}
func (f *file) Meta() map[string]interface{} {
return f.meta
} }

View File

@ -64,7 +64,8 @@ func (gs *goldsmith) queueFiles(target uint) {
panic(err) panic(err)
} }
s.AddFile(NewFileFromPath(relPath, path)) f := NewFileFromAsset(relPath, path)
s.DispatchFile(f)
} }
}() }()
} }
@ -119,11 +120,11 @@ func (gs *goldsmith) exportFile(f *file) error {
return err return err
} }
gs.refFile(f.path) gs.referenceFile(f.path)
return nil return nil
} }
func (gs *goldsmith) refFile(path string) { func (gs *goldsmith) referenceFile(path string) {
gs.mtx.Lock() gs.mtx.Lock()
defer gs.mtx.Unlock() defer gs.mtx.Unlock()

View File

@ -111,13 +111,13 @@ func (s *stage) chain(p Plugin) {
// Context Implementation // Context Implementation
// //
func (s *stage) AddFile(f File) { func (s *stage) DispatchFile(f File) {
atomic.AddInt64(&s.gs.active, 1) atomic.AddInt64(&s.gs.active, 1)
s.output <- f.(*file) s.output <- f.(*file)
} }
func (s *stage) RefFile(path string) { func (s *stage) ReferenceFile(path string) {
s.gs.refFile(path) s.gs.referenceFile(path)
} }
func (s *stage) SrcDir() string { func (s *stage) SrcDir() string {

View File

@ -23,6 +23,7 @@
package goldsmith package goldsmith
import ( import (
"bytes"
"io" "io"
"runtime" "runtime"
) )
@ -51,29 +52,32 @@ type File interface {
Path() string Path() string
Rename(path string) Rename(path string)
Keys() []string Meta() map[string]interface{}
Value(key string) (interface{}, bool)
SetValue(key string, value interface{})
Read(p []byte) (int, error) Read(p []byte) (int, error)
WriteTo(w io.Writer) (int64, error) WriteTo(w io.Writer) (int64, error)
Rewrite(data []byte) Rewrite(data []byte)
Bytes() []byte
Meta() map[string]interface{}
} }
func NewFileFromData(path string, srcData []byte) File { func NewFileFromData(path string, data []byte) File {
return newFileFromData(path, srcData) return &file{
path: path,
meta: make(map[string]interface{}),
reader: bytes.NewReader(data),
}
} }
func NewFileFromPath(path, srcPath string) File { func NewFileFromAsset(path, asset string) File {
return newFileFromPath(path, srcPath) return &file{
path: path,
meta: make(map[string]interface{}),
asset: asset,
}
} }
type Context interface { type Context interface {
AddFile(f File) DispatchFile(f File)
RefFile(path string) ReferenceFile(path string)
SrcDir() string SrcDir() string
DstDir() string DstDir() string