Add support for Swift 3.0

This commit is contained in:
Kyle Fuller
2016-09-13 19:09:58 +01:00
parent f393efbd0b
commit feff3b18b1
41 changed files with 252 additions and 229 deletions

View File

@@ -7,14 +7,14 @@ class BlockContext {
self.blocks = blocks
}
func pop(blockName: String) -> BlockNode? {
return blocks.removeValueForKey(blockName)
func pop(_ blockName: String) -> BlockNode? {
return blocks.removeValue(forKey: blockName)
}
}
extension CollectionType {
func any(closure: Generator.Element -> Bool) -> Generator.Element? {
extension Collection {
func any(_ closure: (Iterator.Element) -> Bool) -> Iterator.Element? {
for element in self {
if closure(element) {
return element
@@ -30,7 +30,7 @@ class ExtendsNode : NodeType {
let templateName: Variable
let blocks: [String:BlockNode]
class func parse(parser: TokenParser, token: Token) throws -> NodeType {
class func parse(_ parser: TokenParser, token: Token) throws -> NodeType {
let bits = token.components()
guard bits.count == 2 else {
@@ -59,7 +59,7 @@ class ExtendsNode : NodeType {
self.blocks = blocks
}
func render(context: Context) throws -> String {
func render(_ context: Context) throws -> String {
guard let loader = context["loader"] as? TemplateLoader else {
throw TemplateSyntaxError("Template loader not in context")
}
@@ -69,12 +69,12 @@ class ExtendsNode : NodeType {
}
guard let template = loader.loadTemplate(templateName) else {
let paths:String = loader.paths.map { $0.description }.joinWithSeparator(", ")
let paths:String = loader.paths.map { $0.description }.joined(separator: ", ")
throw TemplateSyntaxError("'\(templateName)' template not found in \(paths)")
}
let blockContext = BlockContext(blocks: blocks)
return try context.push([BlockContext.contextKey: blockContext]) {
return try context.push(dictionary: [BlockContext.contextKey: blockContext]) {
return try template.render(context)
}
}
@@ -85,7 +85,7 @@ class BlockNode : NodeType {
let name: String
let nodes: [NodeType]
class func parse(parser: TokenParser, token: Token) throws -> NodeType {
class func parse(_ parser: TokenParser, token: Token) throws -> NodeType {
let bits = token.components()
guard bits.count == 2 else {
@@ -94,7 +94,7 @@ class BlockNode : NodeType {
let blockName = bits[1]
let nodes = try parser.parse(until(["endblock"]))
parser.nextToken()
_ = parser.nextToken()
return BlockNode(name:blockName, nodes:nodes)
}
@@ -103,8 +103,8 @@ class BlockNode : NodeType {
self.nodes = nodes
}
func render(context: Context) throws -> String {
if let blockContext = context[BlockContext.contextKey] as? BlockContext, node = blockContext.pop(name) {
func render(_ context: Context) throws -> String {
if let blockContext = context[BlockContext.contextKey] as? BlockContext, let node = blockContext.pop(name) {
return try node.render(context)
}