Rename interface contentRewriter to contentTransformer

Is is a much better name.
This commit is contained in:
bep 2015-03-19 01:55:49 +01:00
parent efb564775a
commit 66cf3bdc77
5 changed files with 26 additions and 26 deletions

View file

@ -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
@ -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

View file

@ -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}
@ -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)
}

View file

@ -6,7 +6,7 @@ import (
"io"
)
type trans func(rw contentRewriter)
type trans func(rw contentTransformer)
type link trans
@ -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 {

View file

@ -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)

View file

@ -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)
}