Skip to content

Commit

Permalink
Rename interface contentRewriter to contentTransformer
Browse files Browse the repository at this point in the history
Is is a much better name.
  • Loading branch information
bep committed Mar 19, 2015
1 parent efb5647 commit 66cf3bd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions transform/absurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func absURLFromURL(URL string) (trs []link, err error) {
}

func absURLFromReplacer(ar *absURLReplacer) (trs []link, err error) {
trs = append(trs, func(rw contentRewriter) {
trs = append(trs, func(rw contentTransformer) {
ar.replaceInHTML(rw)
})
return
Expand All @@ -34,7 +34,7 @@ func absURLInXMLFromURL(URL string) (trs []link, err error) {
}

func absURLInXMLFromReplacer(ar *absURLReplacer) (trs []link, err error) {
trs = append(trs, func(rw contentRewriter) {
trs = append(trs, func(rw contentTransformer) {
ar.replaceInXML(rw)
})
return
Expand Down
14 changes: 7 additions & 7 deletions transform/absurlreplacer.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ func (l *contentlexer) replace() {
}
}

func doReplace(rw contentRewriter, matchers []absURLMatcher) {
func doReplace(ct contentTransformer, matchers []absURLMatcher) {

lexer := &contentlexer{
content: rw.Content(),
w: rw,
content: ct.Content(),
w: ct,
prefixLookup: &prefixes{pr: mainPrefixRunes},
matchers: matchers}

Expand Down Expand Up @@ -226,10 +226,10 @@ func newAbsURLReplacer(baseURL string) *absURLReplacer {

}

func (au *absURLReplacer) replaceInHTML(rw contentRewriter) {
doReplace(rw, au.htmlMatchers)
func (au *absURLReplacer) replaceInHTML(ct contentTransformer) {
doReplace(ct, au.htmlMatchers)
}

func (au *absURLReplacer) replaceInXML(rw contentRewriter) {
doReplace(rw, au.xmlMatchers)
func (au *absURLReplacer) replaceInXML(ct contentTransformer) {
doReplace(ct, au.xmlMatchers)
}
8 changes: 4 additions & 4 deletions transform/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"io"
)

type trans func(rw contentRewriter)
type trans func(rw contentTransformer)

type link trans

Expand All @@ -20,14 +20,14 @@ func NewEmptyTransforms() []link {
return make([]link, 0, 20)
}

// contentRewriter is an interface that enables rotation
// contentTransformer is an interface that enables rotation
// of pooled buffers in the transformer chain.
type contentRewriter interface {
type contentTransformer interface {
Content() []byte
io.Writer
}

// Implements contentRewriter
// Implements contentTransformer
// Content is read from the from-buffer,
// and rewritten to to the to-buffer.
type fromToBuffer struct {
Expand Down
16 changes: 8 additions & 8 deletions transform/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,18 @@ func TestChainZeroTransformers(t *testing.T) {
}

func TestChaingMultipleTransformers(t *testing.T) {
f1 := func(rw contentRewriter) {
rw.Write(bytes.Replace(rw.Content(), []byte("f1"), []byte("f1r"), -1))
f1 := func(ct contentTransformer) {
ct.Write(bytes.Replace(ct.Content(), []byte("f1"), []byte("f1r"), -1))
}
f2 := func(rw contentRewriter) {
rw.Write(bytes.Replace(rw.Content(), []byte("f2"), []byte("f2r"), -1))
f2 := func(ct contentTransformer) {
ct.Write(bytes.Replace(ct.Content(), []byte("f2"), []byte("f2r"), -1))
}
f3 := func(rw contentRewriter) {
rw.Write(bytes.Replace(rw.Content(), []byte("f3"), []byte("f3r"), -1))
f3 := func(ct contentTransformer) {
ct.Write(bytes.Replace(ct.Content(), []byte("f3"), []byte("f3r"), -1))
}

f4 := func(rw contentRewriter) {
rw.Write(bytes.Replace(rw.Content(), []byte("f4"), []byte("f4r"), -1))
f4 := func(ct contentTransformer) {
ct.Write(bytes.Replace(ct.Content(), []byte("f4"), []byte("f4r"), -1))
}

tr := NewChain(f1, f2, f3, f4)
Expand Down
10 changes: 5 additions & 5 deletions transform/livereloadinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import (
"github.com/spf13/viper"
)

func LiveReloadInject(rw contentRewriter) {
func LiveReloadInject(ct contentTransformer) {
match := []byte("</body>")
port := viper.GetString("port")
replace := []byte(`<script>document.write('<script src="http://'
+ (location.host || 'localhost').split(':')[0]
+ ':` + port + `/livereload.js?mindelay=10"></'
+ 'script>')</script></body>`)
newcontent := bytes.Replace(rw.Content(), match, replace, -1)
newcontent := bytes.Replace(ct.Content(), match, replace, -1)

if len(newcontent) == len(rw.Content()) {
if len(newcontent) == len(ct.Content()) {
match := []byte("</BODY>")
newcontent = bytes.Replace(rw.Content(), match, replace, -1)
newcontent = bytes.Replace(ct.Content(), match, replace, -1)
}

rw.Write(newcontent)
ct.Write(newcontent)
}

0 comments on commit 66cf3bd

Please sign in to comment.