Change the order of Apply to be more Unixy

Typically the destination is on the left and the src is on the right.
This commit is contained in:
Noah Campbell 2013-10-01 14:42:08 -07:00
parent 94a3184ad0
commit 80009b427f
7 changed files with 13 additions and 10 deletions

View file

@ -618,10 +618,13 @@ func (s *Site) WritePublic(path string, content io.Reader) (err error) {
}
if s.Transformer == nil {
s.Transformer = &transform.AbsURL{BaseURL: s.Config.BaseUrl}
s.Transformer = transform.NewChain(
&transform.AbsURL{BaseURL: s.Config.BaseUrl},
&transform.NavActive{Section: "tbd"},
)
}
final := new(bytes.Buffer)
s.Transformer.Apply(content, final)
s.Transformer.Apply(final, content)
return s.Target.Publish(path, final)
}

View file

@ -10,7 +10,7 @@ type AbsURL struct {
BaseURL string
}
func (t *AbsURL) Apply(r io.Reader, w io.Writer) (err error) {
func (t *AbsURL) Apply(w io.Writer, r io.Reader) (err error) {
var tr *htmltran.Transformer
if tr, err = htmltran.NewFromReader(r); err != nil {

View file

@ -13,11 +13,11 @@ func NewChain(trs ...Transformer) Transformer {
return &chain{transformers: trs}
}
func (c *chain) Apply(r io.Reader, w io.Writer) (err error) {
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(in, out)
err = tr.Apply(out, in)
if err != nil {
return
}

View file

@ -11,7 +11,7 @@ type NavActive struct {
AttrName string
}
func (n *NavActive) Apply(r io.Reader, w io.Writer) (err error) {
func (n *NavActive) Apply(w io.Writer, r io.Reader) (err error) {
var tr *htmltran.Transformer
if n.Section == "" {

View file

@ -37,7 +37,7 @@ func TestDegenerateNoSectionSet(t *testing.T) {
out = new(bytes.Buffer)
)
if err := tr.Apply(strings.NewReader(HTML_WITH_NAV), out); err != nil {
if err := tr.Apply(out, strings.NewReader(HTML_WITH_NAV)); err != nil {
t.Errorf("Unexpected error in NavActive.Apply: %s", err)
}
@ -49,7 +49,7 @@ func TestDegenerateNoSectionSet(t *testing.T) {
func TestSetNav(t *testing.T) {
tr := &NavActive{Section: "section_2"}
out := new(bytes.Buffer)
if err := tr.Apply(strings.NewReader(HTML_WITH_NAV), out); err != nil {
if err := tr.Apply(out, strings.NewReader(HTML_WITH_NAV)); err != nil {
t.Errorf("Unexpected error in Apply() for NavActive: %s", err)
}

View file

@ -5,5 +5,5 @@ import (
)
type Transformer interface {
Apply(io.Reader, io.Writer) error
Apply(io.Writer, io.Reader) error
}

View file

@ -38,7 +38,7 @@ var abs_url_tests = []test {
func apply(t *testing.T, tr Transformer, tests []test) {
for _, test := range tests {
out := new(bytes.Buffer)
err := tr.Apply(strings.NewReader(test.content), out)
err := tr.Apply(out, strings.NewReader(test.content))
if err != nil {
t.Errorf("Unexpected error: %s", err)
}