Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Removed tuple type, introduced kwargs to filter signature
Browse files Browse the repository at this point in the history
  • Loading branch information
Kat Butler committed Nov 6, 2019
1 parent 700d143 commit 149795a
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 125 deletions.
15 changes: 3 additions & 12 deletions Sources/Liquid/Expression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ struct Expression: CustomStringConvertible {
switch kind {
case let .lookup(lookup):
return lookup.map { $0.description }.joined(separator: "/")
case .namedParam(let value):
return "\(value.0): \(value.1.description)"
case .variable(let key):
return key
case .filter(let filter):
Expand All @@ -33,7 +31,6 @@ struct Expression: CustomStringConvertible {

indirect enum Kind {
case lookup([Expression])
case namedParam(key: String, expression: Expression)
case variable(key: String)
case filter(LookupFilter)
case value(Value)
Expand Down Expand Up @@ -66,10 +63,6 @@ struct Expression: CustomStringConvertible {
self.kind = .lookup(lookup)
}

init(key: String, expression: Expression) {
self.kind = .namedParam(key: key, expression: expression)
}

func evaluate(context: Context) -> Value {
return evaluate(context: context, data: nil)
}
Expand All @@ -82,8 +75,6 @@ struct Expression: CustomStringConvertible {
for expression in expressions.dropFirst() {
result = expression.evaluate(context: context, data: result)
}
case let .namedParam(key, expression):
result = Value((key, expression.evaluate(context: context, data: data)))
case let .variable(key):
if let data = data {
result = data.lookup(Value(key), encoder: context.encoder)
Expand All @@ -108,11 +99,11 @@ struct Expression: CustomStringConvertible {
} else {
switch filter {
case .size:
result = try? Filters.sizeFilter(value: data, args: [], encoder: context.encoder)
result = try? Filters.sizeFilter(value: data, args: [], kwargs: [:], encoder: context.encoder)
case .first:
result = try? Filters.firstFilter(value: data, args: [], encoder: context.encoder)
result = try? Filters.firstFilter(value: data, args: [], kwargs: [:], encoder: context.encoder)
case .last:
result = try? Filters.lastFilter(value: data, args: [], encoder: context.encoder)
result = try? Filters.lastFilter(value: data, args: [], kwargs: [:], encoder: context.encoder)
}
}
} else {
Expand Down
Loading

0 comments on commit 149795a

Please sign in to comment.