Rename Transform to AbsURL

This commit is contained in:
Noah Campbell 2013-10-01 12:56:27 -07:00
parent 03d1a57fea
commit f0211b84a1
3 changed files with 10 additions and 6 deletions

View file

@ -64,7 +64,7 @@ type Site struct {
Info SiteInfo Info SiteInfo
Shortcodes map[string]ShortcodeFunc Shortcodes map[string]ShortcodeFunc
timer *nitro.B timer *nitro.B
Transformer *transform.Transformer Transformer transform.Transformer
Target target.Output Target target.Output
Alias target.AliasPublisher Alias target.AliasPublisher
} }
@ -618,7 +618,7 @@ func (s *Site) WritePublic(path string, content io.Reader) (err error) {
} }
if s.Transformer == nil { if s.Transformer == nil {
s.Transformer = &transform.Transformer{BaseURL: s.Config.BaseUrl} s.Transformer = &transform.AbsURL{BaseURL: s.Config.BaseUrl}
} }
final := new(bytes.Buffer) final := new(bytes.Buffer)
s.Transformer.Apply(content, final) s.Transformer.Apply(content, final)

View file

@ -6,11 +6,15 @@ import (
"net/url" "net/url"
) )
type Transformer struct { type Transformer interface {
Apply(io.Reader, io.Writer) error
}
type AbsURL struct {
BaseURL string BaseURL string
} }
func (t *Transformer) Apply(r io.Reader, w io.Writer) (err error) { func (t *AbsURL) Apply(r io.Reader, w io.Writer) (err error) {
var tr *htmltran.Transformer var tr *htmltran.Transformer
if tr, err = htmltran.NewFromReader(r); err != nil { if tr, err = htmltran.NewFromReader(r); err != nil {
@ -28,7 +32,7 @@ type elattr struct {
tag, attr string tag, attr string
} }
func (t *Transformer) absUrlify(tr *htmltran.Transformer, selectors ...elattr) (err error) { func (t *AbsURL) absUrlify(tr *htmltran.Transformer, selectors ...elattr) (err error) {
var baseURL, inURL *url.URL var baseURL, inURL *url.URL
if baseURL, err = url.Parse(t.BaseURL); err != nil { if baseURL, err = url.Parse(t.BaseURL); err != nil {

View file

@ -26,7 +26,7 @@ func TestAbsUrlify(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
tr := &Transformer{ tr := &AbsURL{
BaseURL: "http://base", BaseURL: "http://base",
} }
out := new(bytes.Buffer) out := new(bytes.Buffer)