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
meta map[string]interface{}
srcData []byte
srcReader *bytes.Reader
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,
}
reader *bytes.Reader
asset string
}
func (f *file) rewind() {
if f.srcReader != nil {
f.srcReader.Seek(0, os.SEEK_SET)
if f.reader != nil {
f.reader.Seek(0, os.SEEK_SET)
}
}
@ -86,11 +68,11 @@ func (f *file) export(dstPath string) error {
}
func (f *file) cache() error {
if f.srcReader != nil {
if f.reader != nil {
return nil
}
data, err := ioutil.ReadFile(f.srcPath)
data, err := ioutil.ReadFile(f.asset)
if err != nil {
return err
}
@ -111,21 +93,8 @@ func (f *file) Rename(path string) {
f.path = path
}
func (f *file) Keys() (keys []string) {
for key := range 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) Meta() map[string]interface{} {
return f.meta
}
func (f *file) Read(p []byte) (int, error) {
@ -133,7 +102,7 @@ func (f *file) Read(p []byte) (int, error) {
return 0, err
}
return f.srcReader.Read(p)
return f.reader.Read(p)
}
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 f.srcReader.WriteTo(w)
return f.reader.WriteTo(w)
}
func (f *file) Rewrite(data []byte) {
f.srcData = data
f.srcReader = bytes.NewReader(data)
}
func (f *file) Bytes() []byte {
return f.srcData
}
func (f *file) Meta() map[string]interface{} {
return f.meta
f.reader = bytes.NewReader(data)
}

View File

@ -64,7 +64,8 @@ func (gs *goldsmith) queueFiles(target uint) {
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
}
gs.refFile(f.path)
gs.referenceFile(f.path)
return nil
}
func (gs *goldsmith) refFile(path string) {
func (gs *goldsmith) referenceFile(path string) {
gs.mtx.Lock()
defer gs.mtx.Unlock()

View File

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

View File

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