fixed indetnations
This commit is contained in:
@@ -189,8 +189,7 @@ extension String {
|
|||||||
lineNumber += 1
|
lineNumber += 1
|
||||||
lineContent = line
|
lineContent = line
|
||||||
if let rangeOfLine = self.range(of: line), rangeOfLine.contains(range.lowerBound) {
|
if let rangeOfLine = self.range(of: line), rangeOfLine.contains(range.lowerBound) {
|
||||||
offset = distance(from: rangeOfLine.lowerBound, to:
|
offset = distance(from: rangeOfLine.lowerBound, to: range.lowerBound)
|
||||||
range.lowerBound)
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,13 +11,13 @@ public protocol NodeType {
|
|||||||
|
|
||||||
/// Render the collection of nodes in the given context
|
/// Render the collection of nodes in the given context
|
||||||
public func renderNodes(_ nodes:[NodeType], _ context:Context) throws -> String {
|
public func renderNodes(_ nodes:[NodeType], _ context:Context) throws -> String {
|
||||||
return try nodes.map({
|
return try nodes.map {
|
||||||
do {
|
do {
|
||||||
return try $0.render(context)
|
return try $0.render(context)
|
||||||
} catch {
|
} catch {
|
||||||
throw error.withToken($0.token)
|
throw error.withToken($0.token)
|
||||||
}
|
}
|
||||||
}).joined(separator: "")
|
}.joined(separator: "")
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SimpleNode : NodeType {
|
public class SimpleNode : NodeType {
|
||||||
|
|||||||
@@ -120,19 +120,18 @@ public class TokenParser {
|
|||||||
do {
|
do {
|
||||||
return try FilterExpression(token: filterToken, parser: self)
|
return try FilterExpression(token: filterToken, parser: self)
|
||||||
} catch {
|
} catch {
|
||||||
if var error = error as? TemplateSyntaxError, error.token == nil {
|
guard var syntaxError = error as? TemplateSyntaxError, syntaxError.token == nil else {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
// find offset of filter in the containing token so that only filter is highligted, not the whole token
|
// find offset of filter in the containing token so that only filter is highligted, not the whole token
|
||||||
if let filterTokenRange = containingToken.contents.range(of: filterToken) {
|
if let filterTokenRange = containingToken.contents.range(of: filterToken) {
|
||||||
var rangeLine = containingToken.sourceMap.line
|
var rangeLine = containingToken.sourceMap.line
|
||||||
rangeLine.offset += containingToken.contents.distance(from: containingToken.contents.startIndex, to: filterTokenRange.lowerBound)
|
rangeLine.offset += containingToken.contents.distance(from: containingToken.contents.startIndex, to: filterTokenRange.lowerBound)
|
||||||
error.token = .variable(value: filterToken, at: SourceMap(filename: containingToken.sourceMap.filename, line: rangeLine))
|
syntaxError.token = .variable(value: filterToken, at: SourceMap(filename: containingToken.sourceMap.filename, line: rangeLine))
|
||||||
} else {
|
} else {
|
||||||
error.token = containingToken
|
syntaxError.token = containingToken
|
||||||
}
|
|
||||||
throw error
|
|
||||||
} else {
|
|
||||||
throw error
|
|
||||||
}
|
}
|
||||||
|
throw syntaxError
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ func testForNode() {
|
|||||||
try expect(try node.render(context)) == "123"
|
try expect(try node.render(context)) == "123"
|
||||||
}
|
}
|
||||||
|
|
||||||
#if os(OSX)
|
#if os(OSX)
|
||||||
$0.it("renders a context variable of type NSArray") {
|
$0.it("renders a context variable of type NSArray") {
|
||||||
let nsarray_context = Context(dictionary: [
|
let nsarray_context = Context(dictionary: [
|
||||||
"items": NSArray(array: [1, 2, 3])
|
"items": NSArray(array: [1, 2, 3])
|
||||||
@@ -64,7 +64,7 @@ func testForNode() {
|
|||||||
let node = ForNode(resolvable: Variable("items"), loopVariables: ["item"], nodes: nodes, emptyNodes: [])
|
let node = ForNode(resolvable: Variable("items"), loopVariables: ["item"], nodes: nodes, emptyNodes: [])
|
||||||
try expect(try node.render(nsarray_context)) == "123"
|
try expect(try node.render(nsarray_context)) == "123"
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
$0.it("renders the given nodes while providing if the item is first in the context") {
|
$0.it("renders the given nodes while providing if the item is first in the context") {
|
||||||
let nodes: [NodeType] = [VariableNode(variable: "item"), VariableNode(variable: "forloop.first")]
|
let nodes: [NodeType] = [VariableNode(variable: "item"), VariableNode(variable: "forloop.first")]
|
||||||
|
|||||||
Reference in New Issue
Block a user