feat: added split fitler (#187)

This commit is contained in:
Ilya Puchka
2018-01-22 01:49:32 +01:00
committed by Kyle Fuller
parent 2e80f70f67
commit c30597457f
4 changed files with 31 additions and 0 deletions

View File

@@ -40,3 +40,16 @@ func joinFilter(value: Any?, arguments: [Any?]) throws -> Any? {
return value
}
func splitFilter(value: Any?, arguments: [Any?]) throws -> Any? {
guard arguments.count < 2 else {
throw TemplateSyntaxError("'split' filter takes a single argument")
}
let separator = stringify(arguments.first ?? " ")
if let value = value as? String {
return value.components(separatedBy: separator)
}
return value
}