From c86ab9c5b9a7ad63f08fadb16205b25a4af3c2d0 Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Sat, 21 Nov 2015 14:06:04 +0000 Subject: [PATCH] Remove unnessecary uses of Foundation --- Stencil.podspec.json | 2 +- Stencil/Stencil.h | 18 -------- Stencil/TemplateLoader.swift | 11 ++--- Stencil/TemplateLoader/Include.swift | 9 ++-- Stencil/TemplateLoader/Inheritence.swift | 55 +++++++++++++----------- 5 files changed, 40 insertions(+), 55 deletions(-) delete mode 100644 Stencil/Stencil.h diff --git a/Stencil.podspec.json b/Stencil.podspec.json index e60a7aa..a6fbaf3 100644 --- a/Stencil.podspec.json +++ b/Stencil.podspec.json @@ -34,7 +34,7 @@ "StencilSpecs/Nodes/*.swift" ], "dependencies": { - "Spectre": [ "~> 0.4.1" ], + "Spectre": [ "~> 0.5.0" ], "PathKit": [ "~> 0.5.0" ] } } diff --git a/Stencil/Stencil.h b/Stencil/Stencil.h deleted file mode 100644 index 2de938f..0000000 --- a/Stencil/Stencil.h +++ /dev/null @@ -1,18 +0,0 @@ -// -// Stencil.h -// Stencil -// -// Created by Kyle Fuller on 23/10/2014. -// Copyright (c) 2014 Cocode. All rights reserved. -// See LICENSE for more details. -// - -#import - -//! Project version number for Stencil. -FOUNDATION_EXPORT double StencilVersionNumber; - -//! Project version string for Stencil. -FOUNDATION_EXPORT const unsigned char StencilVersionString[]; - -// In this header, you should import all the public headers of your framework using statements like #import diff --git a/Stencil/TemplateLoader.swift b/Stencil/TemplateLoader.swift index 33c84a7..99201f2 100644 --- a/Stencil/TemplateLoader.swift +++ b/Stencil/TemplateLoader.swift @@ -1,25 +1,26 @@ import Foundation import PathKit + // A class for loading a template from disk public class TemplateLoader { - public let paths:[Path] + public let paths: [Path] - public init(paths:[Path]) { + public init(paths: [Path]) { self.paths = paths } - public init(bundle:[NSBundle]) { + public init(bundle: [NSBundle]) { self.paths = bundle.map { return Path($0.bundlePath) } } - public func loadTemplate(templateName:String) -> Template? { + public func loadTemplate(templateName: String) -> Template? { return loadTemplate([templateName]) } - public func loadTemplate(templateNames:[String]) -> Template? { + public func loadTemplate(templateNames: [String]) -> Template? { for path in paths { for templateName in templateNames { let templatePath = path + Path(templateName) diff --git a/Stencil/TemplateLoader/Include.swift b/Stencil/TemplateLoader/Include.swift index 5af2ad0..647af38 100644 --- a/Stencil/TemplateLoader/Include.swift +++ b/Stencil/TemplateLoader/Include.swift @@ -1,12 +1,11 @@ -import Foundation import PathKit public class IncludeNode : NodeType { - public let templateName:String + public let templateName: String - public class func parse(parser:TokenParser, token:Token) throws -> NodeType { - let bits = token.contents.componentsSeparatedByString("\"") + public class func parse(parser: TokenParser, token: Token) throws -> NodeType { + let bits = token.contents.characters.split("\"", allowEmptySlices: true).map(String.init) guard bits.count == 3 else { throw TemplateSyntaxError("'include' tag takes one argument, the template file to be included") @@ -15,7 +14,7 @@ public class IncludeNode : NodeType { return IncludeNode(templateName: bits[1]) } - public init(templateName:String) { + public init(templateName: String) { self.templateName = templateName } diff --git a/Stencil/TemplateLoader/Inheritence.swift b/Stencil/TemplateLoader/Inheritence.swift index fce0f16..51342ea 100644 --- a/Stencil/TemplateLoader/Inheritence.swift +++ b/Stencil/TemplateLoader/Inheritence.swift @@ -1,34 +1,36 @@ -import Foundation - class BlockContext { - class var contextKey:String { return "block_context" } + class var contextKey: String { return "block_context" } - var blocks:[String:BlockNode] + var blocks: [String:BlockNode] - init(blocks:[String:BlockNode]) { + init(blocks: [String:BlockNode]) { self.blocks = blocks } - func pop(blockName:String) -> BlockNode? { + func pop(blockName: String) -> BlockNode? { return blocks.removeValueForKey(blockName) } } -func any(elements:[Element], closure:(Element -> Bool)) -> Element? { - for element in elements { - if closure(element) { - return element - } - } - return nil +extension CollectionType { + func any(closure: Generator.Element -> Bool) -> Generator.Element? { + for element in self { + if closure(element) { + return element + } + } + + return nil + } } -class ExtendsNode : NodeType { - let templateName:String - let blocks:[String:BlockNode] - class func parse(parser:TokenParser, token:Token) throws -> NodeType { +class ExtendsNode : NodeType { + let templateName: String + let blocks: [String:BlockNode] + + class func parse(parser: TokenParser, token: Token) throws -> NodeType { let bits = token.contents.componentsSeparatedByString("\"") guard bits.count == 3 else { @@ -36,23 +38,23 @@ class ExtendsNode : NodeType { } let parsedNodes = try parser.parse() - guard (any(parsedNodes) { $0 is ExtendsNode }) == nil else { + guard (parsedNodes.any { $0 is ExtendsNode }) == nil else { throw TemplateSyntaxError("'extends' cannot appear more than once in the same template") } let blockNodes = parsedNodes.filter { node in node is BlockNode } - let nodes = blockNodes.reduce([String:BlockNode](), combine: { (accumulator, node:NodeType) -> [String:BlockNode] in + let nodes = blockNodes.reduce([String:BlockNode]()) { (accumulator, node:NodeType) -> [String:BlockNode] in let node = (node as! BlockNode) var dict = accumulator dict[node.name] = node return dict - }) + } return ExtendsNode(templateName: bits[1], blocks: nodes) } - init(templateName:String, blocks:[String:BlockNode]) { + init(templateName: String, blocks: [String:BlockNode]) { self.templateName = templateName self.blocks = blocks } @@ -75,11 +77,12 @@ class ExtendsNode : NodeType { } } -class BlockNode : NodeType { - let name:String - let nodes:[NodeType] - class func parse(parser:TokenParser, token:Token) throws -> NodeType { +class BlockNode : NodeType { + let name: String + let nodes: [NodeType] + + class func parse(parser: TokenParser, token: Token) throws -> NodeType { let bits = token.components() guard bits.count == 2 else { @@ -92,7 +95,7 @@ class BlockNode : NodeType { return BlockNode(name:blockName, nodes:nodes) } - init(name:String, nodes:[NodeType]) { + init(name: String, nodes: [NodeType]) { self.name = name self.nodes = nodes }