~foosoft/goldsmith

946e77e9eee58404e5cfe181ade9f9732271e927 — Alex Yatskov 9 years ago be7d133
WIP
3 files changed, 45 insertions(+), 13 deletions(-)

M cmd/main.go
M core.go
M goldsmith.go
M cmd/main.go => cmd/main.go +1 -3
@@ 22,9 22,7 @@

package main

import "github.com/FooSoft/goldsmith"
import _ "github.com/FooSoft/goldsmith"

func main() {
	gs := goldsmith.NewGoldsmith("", "")
	gs.Use(nil)
}

M core.go => core.go +33 -6
@@ 23,6 23,7 @@
package goldsmith

import (
	"bytes"
	"path/filepath"
	"sync"



@@ 30,17 31,43 @@ import (
)

type stage struct {
	input  chan File
	output chan File
	input  chan file
	output chan file
}

type file struct {
	path string
	meta map[string]interface{}
}

type goldsmith struct {
	srcPath, dstPath string
	stages           []stage
	files            chan File
	files            chan file
	wg               sync.WaitGroup
}

func (f *file) Path() string {
	return f.path
}

func (f *file) SetPath(path string) {
	f.path = path
}

func (f *file) Meta(key string) (interface{}, bool) {
	value, ok := f.meta[key]
	return value, ok
}

func (f *file) SetMeta(key string, value interface{}) {
	f.meta[key] = value
}

func (f *file) Data() (*bytes.Buffer, error) {
	return nil, nil
}

func NewGoldsmith(srcPath, dstPath string) (Applier, error) {
	gs := &goldsmith{srcPath: srcPath, dstPath: dstPath}
	if err := gs.scan(); err != nil {


@@ 56,7 83,7 @@ func (gs *goldsmith) scan() error {
		return err
	}

	gs.files = make(chan File, len(matches))
	gs.files = make(chan file, len(matches))

	for _, match := range matches {
		path, err := filepath.Rel(gs.srcPath, match)


@@ 64,14 91,14 @@ func (gs *goldsmith) scan() error {
			return err
		}

		gs.files <- File{path, make(map[string]interface{})}
		gs.files <- file{path, make(map[string]interface{})}
	}

	return nil
}

func (gs *goldsmith) stage() stage {
	s := stage{output: make(chan File)}
	s := stage{output: make(chan file)}
	if len(gs.stages) == 0 {
		s.input = gs.files
	} else {

M goldsmith.go => goldsmith.go +11 -4
@@ 22,18 22,25 @@

package goldsmith

import "bytes"

type Context interface {
	AbsSrcPath(path string) string
	AbsDstPath(path string) string
}

type File struct {
	Path string
	Meta map[string]interface{}
type File interface {
	Path() string
	SetPath(path string)

	Meta(key string) (interface{}, bool)
	SetMeta(key string, value interface{})

	Data() (*bytes.Buffer, error)
}

type Processor interface {
	Process(ctx Context, input chan File, output chan File) error
	Process(ctx Context, input chan file, output chan file) error
}

type Applier interface {

Do not follow this link