hugo/transform/chain.go
2013-10-08 18:40:41 +02:00

29 lines
450 B
Go

package transform
import (
"bytes"
"io"
)
type chain struct {
transformers []Transformer
}
func NewChain(trs ...Transformer) Transformer {
return &chain{transformers: trs}
}
func (c *chain) Apply(w io.Writer, r io.Reader) (err error) {
in := r
for _, tr := range c.transformers {
out := new(bytes.Buffer)
err = tr.Apply(out, in)
if err != nil {
return
}
in = bytes.NewBuffer(out.Bytes())
}
_, err = io.Copy(w, in)
return
}