-
Notifications
You must be signed in to change notification settings - Fork 223
Added filter to apply dynamic filters #203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
564ccb7
f3d5843
2c411ca
e795f05
0269052
dbb5e14
da6a0cc
019d0cc
08fc21d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,7 +48,7 @@ public class TokenParser { | |
| } | ||
|
|
||
| if let tag = token.components().first { | ||
| let parser = try findTag(name: tag) | ||
| let parser = try environment.findTag(name: tag) | ||
| nodes.append(try parser(self, token)) | ||
| } | ||
| case .comment: | ||
|
|
@@ -71,8 +71,24 @@ public class TokenParser { | |
| tokens.insert(token, at: 0) | ||
| } | ||
|
|
||
| public func compileFilter(_ token: String) throws -> Resolvable { | ||
|
||
| return try environment.compileFilter(token) | ||
| } | ||
|
|
||
| public func compileExpression(components: [String]) throws -> Expression { | ||
| return try environment.compileExpression(components: components) | ||
| } | ||
|
|
||
| public func compileResolvable(_ token: String) throws -> Resolvable { | ||
| return try environment.compileResolvable(token) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| extension Environment { | ||
|
|
||
| func findTag(name: String) throws -> Extension.TagParser { | ||
| for ext in environment.extensions { | ||
| for ext in extensions { | ||
| if let filter = ext.tags[name] { | ||
| return filter | ||
| } | ||
|
|
@@ -82,7 +98,7 @@ public class TokenParser { | |
| } | ||
|
|
||
| func findFilter(_ name: String) throws -> FilterType { | ||
| for ext in environment.extensions { | ||
| for ext in extensions { | ||
| if let filter = ext.filters[name] { | ||
| return filter | ||
| } | ||
|
|
@@ -97,7 +113,7 @@ public class TokenParser { | |
| } | ||
|
|
||
| private func suggestedFilters(for name: String) -> [String] { | ||
| let allFilters = environment.extensions.flatMap({ $0.filters.keys }) | ||
| let allFilters = extensions.flatMap({ $0.filters.keys }) | ||
|
|
||
| let filtersWithDistance = allFilters | ||
| .map({ (filterName: $0, distance: $0.levenshteinDistance(name)) }) | ||
|
|
@@ -111,11 +127,15 @@ public class TokenParser { | |
| } | ||
|
|
||
| public func compileFilter(_ token: String) throws -> Resolvable { | ||
ilyapuchka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return try FilterExpression(token: token, parser: self) | ||
| return try FilterExpression(token: token, environment: self) | ||
| } | ||
|
|
||
| public func compileExpression(components: [String]) throws -> Expression { | ||
| return try IfExpressionParser(components: components, environment: self).parse() | ||
| } | ||
|
|
||
| public func compileResolvable(_ token: String) throws -> Resolvable { | ||
| return try RangeVariable(token, parser: self) | ||
| return try RangeVariable(token, environment: self) | ||
| ?? compileFilter(token) | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If (when?) #221 gets merged(merged), could you fix the format of this entry? Remove the newline above, add a.and 2 spaces at the end, and credit yourself + link to this PR.