Fix issues in Sources
Sources sources
This commit is contained in:
@@ -72,7 +72,7 @@ func indentFilter(value: Any?, arguments: [Any?]) throws -> Any? {
|
||||
}
|
||||
|
||||
var indentWidth = 4
|
||||
if arguments.count > 0 {
|
||||
if !arguments.isEmpty {
|
||||
guard let value = arguments[0] as? Int else {
|
||||
throw TemplateSyntaxError("""
|
||||
'indent' filter width argument must be an Integer (\(String(describing: arguments[0])))
|
||||
@@ -99,18 +99,17 @@ func indentFilter(value: Any?, arguments: [Any?]) throws -> Any? {
|
||||
indentFirst = value
|
||||
}
|
||||
|
||||
let indentation = [String](repeating: indentationChar, count: indentWidth).joined(separator: "")
|
||||
let indentation = [String](repeating: indentationChar, count: indentWidth).joined()
|
||||
return indent(stringify(value), indentation: indentation, indentFirst: indentFirst)
|
||||
}
|
||||
|
||||
|
||||
func indent(_ content: String, indentation: String, indentFirst: Bool) -> String {
|
||||
guard !indentation.isEmpty else { return content }
|
||||
|
||||
var lines = content.components(separatedBy: .newlines)
|
||||
let firstLine = (indentFirst ? indentation : "") + lines.removeFirst()
|
||||
let result = lines.reduce([firstLine]) { (result, line) in
|
||||
return result + [(line.isEmpty ? "" : "\(indentation)\(line)")]
|
||||
let result = lines.reduce([firstLine]) { result, line in
|
||||
result + [(line.isEmpty ? "" : "\(indentation)\(line)")]
|
||||
}
|
||||
return result.joined(separator: "\n")
|
||||
}
|
||||
@@ -120,7 +119,7 @@ func filterFilter(value: Any?, arguments: [Any?], context: Context) throws -> An
|
||||
guard arguments.count == 1 else {
|
||||
throw TemplateSyntaxError("'filter' filter takes one argument")
|
||||
}
|
||||
|
||||
|
||||
let attribute = stringify(arguments[0])
|
||||
|
||||
let expr = try context.environment.compileFilter("$0|\(attribute)")
|
||||
|
||||
Reference in New Issue
Block a user