mirror of
https://github.com/danog/liquid.git
synced 2024-11-27 01:24:40 +01:00
remove fmt.Stringer render case
This commit is contained in:
parent
a1c59270ea
commit
474edc1ca8
@ -65,7 +65,7 @@ func (n *ObjectNode) render(w *trimWriter, ctx nodeContext) Error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return wrapRenderError(err, n)
|
return wrapRenderError(err, n)
|
||||||
}
|
}
|
||||||
if err := wrapRenderError(writeObject(value, w), n); err != nil {
|
if err := wrapRenderError(writeObject(w, value), n); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
w.TrimRight(n.TrimRight)
|
w.TrimRight(n.TrimRight)
|
||||||
@ -94,7 +94,7 @@ func (n *TextNode) render(w *trimWriter, ctx nodeContext) Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// writeObject writes a value used in an object node
|
// writeObject writes a value used in an object node
|
||||||
func writeObject(value interface{}, w io.Writer) error {
|
func writeObject(w io.Writer, value interface{}) error {
|
||||||
value = evaluator.ToLiquid(value)
|
value = evaluator.ToLiquid(value)
|
||||||
if value == nil {
|
if value == nil {
|
||||||
return nil
|
return nil
|
||||||
@ -103,9 +103,8 @@ func writeObject(value interface{}, w io.Writer) error {
|
|||||||
case []byte:
|
case []byte:
|
||||||
_, err := w.Write(value)
|
_, err := w.Write(value)
|
||||||
return err
|
return err
|
||||||
case fmt.Stringer:
|
// there used be a case on fmt.Stringer here, but fmt.Sprint produces better results than obj.Write
|
||||||
_, err := io.WriteString(w, value.String())
|
// for instances of error and *string
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
rt := reflect.ValueOf(value)
|
rt := reflect.ValueOf(value)
|
||||||
switch rt.Kind() {
|
switch rt.Kind() {
|
||||||
@ -113,12 +112,14 @@ func writeObject(value interface{}, w io.Writer) error {
|
|||||||
for i := 0; i < rt.Len(); i++ {
|
for i := 0; i < rt.Len(); i++ {
|
||||||
item := rt.Index(i)
|
item := rt.Index(i)
|
||||||
if item.IsValid() {
|
if item.IsValid() {
|
||||||
if err := writeObject(item.Interface(), w); err != nil {
|
if err := writeObject(w, item.Interface()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
case reflect.Ptr:
|
||||||
|
return writeObject(w, reflect.ValueOf(value).Elem())
|
||||||
default:
|
default:
|
||||||
_, err := io.WriteString(w, fmt.Sprint(value))
|
_, err := io.WriteString(w, fmt.Sprint(value))
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user