mirror of
https://github.com/danog/liquid.git
synced 2025-01-22 23:01:16 +01:00
Lint; remove dead code
This commit is contained in:
parent
a1784cd5d2
commit
fb26bb3f88
@ -8,6 +8,7 @@ import (
|
||||
|
||||
// ASTNode is a node of an AST.
|
||||
type ASTNode interface {
|
||||
// Render evaluates an AST node and writes the result to an io.Writer.
|
||||
Render(io.Writer, Context) error
|
||||
}
|
||||
|
||||
@ -21,12 +22,6 @@ type ASTSeq struct {
|
||||
Children []ASTNode
|
||||
}
|
||||
|
||||
// ASTChunks is a sequence of chunks.
|
||||
// TODO probably safe to remove this type and method, once the test suite is larger
|
||||
type ASTChunks struct {
|
||||
chunks []Chunk
|
||||
}
|
||||
|
||||
// ASTFunctional renders itself via a render function that is created during parsing.
|
||||
type ASTFunctional struct {
|
||||
Chunk
|
||||
|
@ -34,7 +34,10 @@ type SourceInfo struct {
|
||||
type ChunkType int
|
||||
|
||||
const (
|
||||
TextChunkType ChunkType = iota // TextChunkType is the type of a text Chunk
|
||||
TagChunkType // TagChunkType is the type of a tag Chunk "{%…%}"
|
||||
ObjChunkType // TextChunkType is the type of an object Chunk "{{…}}"
|
||||
// TextChunkType is the type of a text Chunk
|
||||
TextChunkType ChunkType = iota
|
||||
// TagChunkType is the type of a tag Chunk "{%…%}"
|
||||
TagChunkType
|
||||
// TextChunkType is the type of an object Chunk "{{…}}"
|
||||
ObjChunkType
|
||||
)
|
||||
|
@ -29,11 +29,6 @@ func (c Chunk) MarshalYAML() (interface{}, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// MarshalYAML marshalls a chunk for debugging.
|
||||
func (n ASTChunks) MarshalYAML() (interface{}, error) {
|
||||
return map[string]interface{}{"chunks": n.chunks}, nil
|
||||
}
|
||||
|
||||
// MarshalYAML marshalls a chunk for debugging.
|
||||
func (n ASTControlTag) MarshalYAML() (interface{}, error) {
|
||||
return map[string]map[string]interface{}{
|
||||
|
@ -68,13 +68,6 @@ func Parse(chunks []Chunk) (ASTNode, error) {
|
||||
ccn.Branches = append(ccn.Branches, n)
|
||||
ap = &n.Body
|
||||
case cd.isEndTag:
|
||||
// if ccn != nil && cd.parser != nil {
|
||||
// renderer, err := cd.parser(*ccn)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// ccn.renderer = renderer
|
||||
// }
|
||||
f := stack[len(stack)-1]
|
||||
stack = stack[:len(stack)-1]
|
||||
ccd, ccn, ap = f.cd, f.cn, f.ap
|
||||
@ -88,16 +81,6 @@ func Parse(chunks []Chunk) (ASTNode, error) {
|
||||
} else {
|
||||
return nil, fmt.Errorf("unknown tag: %s", c.Name)
|
||||
}
|
||||
// } else if len(*ap) > 0 {
|
||||
// switch n := ((*ap)[len(*ap)-1]).(type) {
|
||||
// case *ASTChunks:
|
||||
// n.chunks = append(n.chunks, c)
|
||||
// default:
|
||||
// *ap = append(*ap, &ASTChunks{chunks: []Chunk{c}})
|
||||
// }
|
||||
// } else {
|
||||
// *ap = append(*ap, &ASTChunks{chunks: []Chunk{c}})
|
||||
// }
|
||||
}
|
||||
}
|
||||
if ccd != nil {
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"github.com/osteele/liquid/generics"
|
||||
)
|
||||
|
||||
// Render evaluates an AST node and writes the result to an io.Writer.
|
||||
// Render is in the ASTNode interface.
|
||||
func (n *ASTSeq) Render(w io.Writer, ctx Context) error {
|
||||
for _, c := range n.Children {
|
||||
if err := c.Render(w, ctx); err != nil {
|
||||
@ -17,29 +17,23 @@ func (n *ASTSeq) Render(w io.Writer, ctx Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Render evaluates an AST node and writes the result to an io.Writer.
|
||||
// TODO probably safe to remove this type and method, once the test suite is larger
|
||||
func (n *ASTChunks) Render(w io.Writer, _ Context) error {
|
||||
fmt.Println(MustYAML(n))
|
||||
return fmt.Errorf("unimplemented: ASTChunks.Render")
|
||||
}
|
||||
|
||||
// Render evaluates an AST node and writes the result to an io.Writer.
|
||||
// Render is in the ASTNode interface.
|
||||
func (n *ASTFunctional) Render(w io.Writer, ctx Context) error {
|
||||
err := n.render(w, ctx)
|
||||
// TODO restore something like this
|
||||
// if err != nil {
|
||||
// fmt.Println("while parsing", n.Source)
|
||||
// }
|
||||
return err
|
||||
}
|
||||
|
||||
// Render evaluates an AST node and writes the result to an io.Writer.
|
||||
// Render is in the ASTNode interface.
|
||||
func (n *ASTText) Render(w io.Writer, _ Context) error {
|
||||
_, err := w.Write([]byte(n.Source))
|
||||
return err
|
||||
}
|
||||
|
||||
// Render evaluates an AST node and writes the result to an io.Writer.
|
||||
// Render is in the ASTNode interface.
|
||||
func (n *ASTRaw) Render(w io.Writer, _ Context) error {
|
||||
for _, s := range n.slices {
|
||||
_, err := w.Write([]byte(s))
|
||||
@ -50,7 +44,7 @@ func (n *ASTRaw) Render(w io.Writer, _ Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Render evaluates an AST node and writes the result to an io.Writer.
|
||||
// Render is in the ASTNode interface.
|
||||
func (n *ASTControlTag) Render(w io.Writer, ctx Context) error {
|
||||
cd, ok := findControlTagDefinition(n.Name)
|
||||
if !ok || cd.parser == nil {
|
||||
@ -59,12 +53,11 @@ func (n *ASTControlTag) Render(w io.Writer, ctx Context) error {
|
||||
renderer := n.renderer
|
||||
if renderer == nil {
|
||||
panic(fmt.Errorf("unset renderer for %v", n))
|
||||
return nil
|
||||
}
|
||||
return renderer(w, ctx)
|
||||
}
|
||||
|
||||
// Render evaluates an AST node and writes the result to an io.Writer.
|
||||
// Render is in the ASTNode interface.
|
||||
func (n *ASTObject) Render(w io.Writer, ctx Context) error {
|
||||
value, err := ctx.Evaluate(n.expr)
|
||||
if err != nil {
|
||||
|
@ -93,7 +93,7 @@ func DefineStandardFilters() {
|
||||
case int, int16, int32, int64:
|
||||
return int(a) / bt.(int)
|
||||
case float32, float64:
|
||||
return a / float64(b.(float64))
|
||||
return a / b.(float64)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ func IsEmpty(value interface{}) bool {
|
||||
case reflect.Array, reflect.Map, reflect.Slice, reflect.String:
|
||||
return r.Len() == 0
|
||||
case reflect.Bool:
|
||||
return r.Bool() == false
|
||||
return !r.Bool()
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user