1
0
mirror of https://github.com/danog/liquid.git synced 2024-11-26 21:34:44 +01:00

TIL io.WriteString

This commit is contained in:
Oliver Steele 2017-07-15 21:13:21 -04:00
parent 68a3e9bb3c
commit 41e7b29ba2
5 changed files with 11 additions and 11 deletions

View File

@ -28,7 +28,7 @@ func (e *Engine) RegisterBlock(name string, td Renderer) {
if err != nil {
return err
}
_, err = w.Write([]byte(s))
_, err = io.WriteString(w, s)
return err
})
}
@ -60,7 +60,7 @@ func (e *Engine) RegisterTag(name string, td Renderer) {
if err != nil {
return err
}
_, err = w.Write([]byte(s))
_, err = io.WriteString(w, s)
return err
}, nil
})

View File

@ -16,19 +16,19 @@ func addContextTestTags(s Config) {
if err != nil {
return err
}
_, err = w.Write([]byte(fmt.Sprint(v)))
_, err = fmt.Fprint(w, v)
return err
})
s.AddBlock("parse").Compiler(func(c BlockNode) (func(io.Writer, Context) error, error) {
a := c.Args
return func(w io.Writer, c Context) error {
_, err := w.Write([]byte(a))
_, err := io.WriteString(w, a)
return err
}, nil
})
s.AddTag("tag_name", func(string) (func(io.Writer, Context) error, error) {
return func(w io.Writer, c Context) error {
_, err := w.Write([]byte(c.TagName()))
_, err := io.WriteString(w, c.TagName())
return err
}, nil
})
@ -38,7 +38,7 @@ func addContextTestTags(s Config) {
if err != nil {
return err
}
_, err = w.Write([]byte(s))
_, err = io.WriteString(w, s)
return err
}, nil
})

View File

@ -30,7 +30,7 @@ func (n *BlockNode) render(w io.Writer, ctx nodeContext) Error {
func (n *RawNode) render(w io.Writer, ctx nodeContext) Error {
for _, s := range n.slices {
_, err := w.Write([]byte(s))
_, err := io.WriteString(w, s)
if err != nil {
return wrapRenderError(err, n)
}
@ -60,7 +60,7 @@ func (n *TagNode) render(w io.Writer, ctx nodeContext) Error {
}
func (n *TextNode) render(w io.Writer, ctx nodeContext) Error {
_, err := w.Write([]byte(n.Source))
_, err := io.WriteString(w, n.Source)
return wrapRenderError(err, n)
}
@ -83,7 +83,7 @@ func writeObject(value interface{}, w io.Writer) error {
}
return nil
default:
_, err := w.Write([]byte(fmt.Sprint(value)))
_, err := io.WriteString(w, fmt.Sprint(value))
return err
}
}

View File

@ -25,7 +25,7 @@ func includeTag(source string) (func(io.Writer, render.Context) error, error) {
if err != nil {
return err
}
_, err = w.Write([]byte(s))
_, err = io.WriteString(w, s)
return err
}, nil
}

View File

@ -51,7 +51,7 @@ func cycleTag(args string) (func(io.Writer, render.Context) error, error) {
n := cycleMap[group]
cycleMap[group] = n + 1
// The parser guarantees that there will be at least one item.
_, err = w.Write([]byte(values[n%len(values)]))
_, err = io.WriteString(w, values[n%len(values)])
return err
}, nil
}