From e34084f3f0e18360ef14e1e28d207b8b03ceeee2 Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Thu, 23 Oct 2014 14:59:57 +0100 Subject: [PATCH] Initial project with Context and Variable. --- Stencil.xcodeproj/project.pbxproj | 433 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + Stencil/Context.swift | 54 +++ Stencil/Info.plist | 28 ++ Stencil/Stencil.h | 19 + Stencil/Variable.swift | 51 +++ StencilTests/ContextTests.swift | 73 +++ StencilTests/Info.plist | 24 + StencilTests/StencilTests.swift | 36 ++ StencilTests/VariableTests.swift | 70 +++ 10 files changed, 795 insertions(+) create mode 100644 Stencil.xcodeproj/project.pbxproj create mode 100644 Stencil.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 Stencil/Context.swift create mode 100644 Stencil/Info.plist create mode 100644 Stencil/Stencil.h create mode 100644 Stencil/Variable.swift create mode 100644 StencilTests/ContextTests.swift create mode 100644 StencilTests/Info.plist create mode 100644 StencilTests/StencilTests.swift create mode 100644 StencilTests/VariableTests.swift diff --git a/Stencil.xcodeproj/project.pbxproj b/Stencil.xcodeproj/project.pbxproj new file mode 100644 index 0000000..9b2d8e5 --- /dev/null +++ b/Stencil.xcodeproj/project.pbxproj @@ -0,0 +1,433 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 7725B3CB19F92B4F002CF74B /* VariableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7725B3CA19F92B4F002CF74B /* VariableTests.swift */; }; + 7725B3CD19F92B61002CF74B /* Variable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7725B3CC19F92B61002CF74B /* Variable.swift */; }; + 77FAAE5819F91E480029DC5E /* Stencil.h in Headers */ = {isa = PBXBuildFile; fileRef = 77FAAE5719F91E480029DC5E /* Stencil.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 77FAAE5E19F91E480029DC5E /* Stencil.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 77FAAE5219F91E480029DC5E /* Stencil.framework */; }; + 77FAAE6519F91E480029DC5E /* StencilTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77FAAE6419F91E480029DC5E /* StencilTests.swift */; }; + 77FAAE6F19F920750029DC5E /* Context.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77FAAE6E19F920750029DC5E /* Context.swift */; }; + 77FAAE7119F9208C0029DC5E /* ContextTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77FAAE7019F9208C0029DC5E /* ContextTests.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 77FAAE5F19F91E480029DC5E /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 77FAAE4919F91E480029DC5E /* Project object */; + proxyType = 1; + remoteGlobalIDString = 77FAAE5119F91E480029DC5E; + remoteInfo = Stencil; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 7725B3CA19F92B4F002CF74B /* VariableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VariableTests.swift; sourceTree = ""; }; + 7725B3CC19F92B61002CF74B /* Variable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Variable.swift; sourceTree = ""; }; + 77FAAE5219F91E480029DC5E /* Stencil.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Stencil.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 77FAAE5619F91E480029DC5E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 77FAAE5719F91E480029DC5E /* Stencil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Stencil.h; sourceTree = ""; }; + 77FAAE5D19F91E480029DC5E /* StencilTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = StencilTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 77FAAE6319F91E480029DC5E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 77FAAE6419F91E480029DC5E /* StencilTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StencilTests.swift; sourceTree = ""; }; + 77FAAE6E19F920750029DC5E /* Context.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Context.swift; sourceTree = ""; }; + 77FAAE7019F9208C0029DC5E /* ContextTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContextTests.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 77FAAE4E19F91E480029DC5E /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 77FAAE5A19F91E480029DC5E /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 77FAAE5E19F91E480029DC5E /* Stencil.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 77FAAE4819F91E480029DC5E = { + isa = PBXGroup; + children = ( + 77FAAE5419F91E480029DC5E /* Stencil */, + 77FAAE6119F91E480029DC5E /* StencilTests */, + 77FAAE5319F91E480029DC5E /* Products */, + ); + sourceTree = ""; + }; + 77FAAE5319F91E480029DC5E /* Products */ = { + isa = PBXGroup; + children = ( + 77FAAE5219F91E480029DC5E /* Stencil.framework */, + 77FAAE5D19F91E480029DC5E /* StencilTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; + 77FAAE5419F91E480029DC5E /* Stencil */ = { + isa = PBXGroup; + children = ( + 77FAAE5719F91E480029DC5E /* Stencil.h */, + 77FAAE6E19F920750029DC5E /* Context.swift */, + 7725B3CC19F92B61002CF74B /* Variable.swift */, + 77FAAE5519F91E480029DC5E /* Supporting Files */, + ); + path = Stencil; + sourceTree = ""; + }; + 77FAAE5519F91E480029DC5E /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 77FAAE5619F91E480029DC5E /* Info.plist */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + 77FAAE6119F91E480029DC5E /* StencilTests */ = { + isa = PBXGroup; + children = ( + 77FAAE6419F91E480029DC5E /* StencilTests.swift */, + 77FAAE7019F9208C0029DC5E /* ContextTests.swift */, + 7725B3CA19F92B4F002CF74B /* VariableTests.swift */, + 77FAAE6219F91E480029DC5E /* Supporting Files */, + ); + path = StencilTests; + sourceTree = ""; + }; + 77FAAE6219F91E480029DC5E /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 77FAAE6319F91E480029DC5E /* Info.plist */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + 77FAAE4F19F91E480029DC5E /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 77FAAE5819F91E480029DC5E /* Stencil.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + 77FAAE5119F91E480029DC5E /* Stencil */ = { + isa = PBXNativeTarget; + buildConfigurationList = 77FAAE6819F91E480029DC5E /* Build configuration list for PBXNativeTarget "Stencil" */; + buildPhases = ( + 77FAAE4D19F91E480029DC5E /* Sources */, + 77FAAE4E19F91E480029DC5E /* Frameworks */, + 77FAAE4F19F91E480029DC5E /* Headers */, + 77FAAE5019F91E480029DC5E /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = Stencil; + productName = Stencil; + productReference = 77FAAE5219F91E480029DC5E /* Stencil.framework */; + productType = "com.apple.product-type.framework"; + }; + 77FAAE5C19F91E480029DC5E /* StencilTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 77FAAE6B19F91E480029DC5E /* Build configuration list for PBXNativeTarget "StencilTests" */; + buildPhases = ( + 77FAAE5919F91E480029DC5E /* Sources */, + 77FAAE5A19F91E480029DC5E /* Frameworks */, + 77FAAE5B19F91E480029DC5E /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 77FAAE6019F91E480029DC5E /* PBXTargetDependency */, + ); + name = StencilTests; + productName = StencilTests; + productReference = 77FAAE5D19F91E480029DC5E /* StencilTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 77FAAE4919F91E480029DC5E /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0600; + ORGANIZATIONNAME = Cocode; + TargetAttributes = { + 77FAAE5119F91E480029DC5E = { + CreatedOnToolsVersion = 6.1; + }; + 77FAAE5C19F91E480029DC5E = { + CreatedOnToolsVersion = 6.1; + }; + }; + }; + buildConfigurationList = 77FAAE4C19F91E480029DC5E /* Build configuration list for PBXProject "Stencil" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = 77FAAE4819F91E480029DC5E; + productRefGroup = 77FAAE5319F91E480029DC5E /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 77FAAE5119F91E480029DC5E /* Stencil */, + 77FAAE5C19F91E480029DC5E /* StencilTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 77FAAE5019F91E480029DC5E /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 77FAAE5B19F91E480029DC5E /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 77FAAE4D19F91E480029DC5E /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 77FAAE6F19F920750029DC5E /* Context.swift in Sources */, + 7725B3CD19F92B61002CF74B /* Variable.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 77FAAE5919F91E480029DC5E /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 77FAAE6519F91E480029DC5E /* StencilTests.swift in Sources */, + 7725B3CB19F92B4F002CF74B /* VariableTests.swift in Sources */, + 77FAAE7119F9208C0029DC5E /* ContextTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 77FAAE6019F91E480029DC5E /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 77FAAE5119F91E480029DC5E /* Stencil */; + targetProxy = 77FAAE5F19F91E480029DC5E /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + 77FAAE6619F91E480029DC5E /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.10; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Debug; + }; + 77FAAE6719F91E480029DC5E /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = YES; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.10; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Release; + }; + 77FAAE6919F91E480029DC5E /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ENABLE_MODULES = YES; + COMBINE_HIDPI_IMAGES = YES; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_VERSION = A; + INFOPLIST_FILE = Stencil/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 77FAAE6A19F91E480029DC5E /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ENABLE_MODULES = YES; + COMBINE_HIDPI_IMAGES = YES; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_VERSION = A; + INFOPLIST_FILE = Stencil/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + }; + name = Release; + }; + 77FAAE6C19F91E480029DC5E /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(DEVELOPER_FRAMEWORKS_DIR)", + "$(inherited)", + ); + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + INFOPLIST_FILE = StencilTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 77FAAE6D19F91E480029DC5E /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(DEVELOPER_FRAMEWORKS_DIR)", + "$(inherited)", + ); + INFOPLIST_FILE = StencilTests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 77FAAE4C19F91E480029DC5E /* Build configuration list for PBXProject "Stencil" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 77FAAE6619F91E480029DC5E /* Debug */, + 77FAAE6719F91E480029DC5E /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 77FAAE6819F91E480029DC5E /* Build configuration list for PBXNativeTarget "Stencil" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 77FAAE6919F91E480029DC5E /* Debug */, + 77FAAE6A19F91E480029DC5E /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 77FAAE6B19F91E480029DC5E /* Build configuration list for PBXNativeTarget "StencilTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 77FAAE6C19F91E480029DC5E /* Debug */, + 77FAAE6D19F91E480029DC5E /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 77FAAE4919F91E480029DC5E /* Project object */; +} diff --git a/Stencil.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Stencil.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..1533932 --- /dev/null +++ b/Stencil.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Stencil/Context.swift b/Stencil/Context.swift new file mode 100644 index 0000000..14746dc --- /dev/null +++ b/Stencil/Context.swift @@ -0,0 +1,54 @@ +// +// Context.swift +// Stencil +// +// Created by Kyle Fuller on 23/10/2014. +// Copyright (c) 2014 Cocode. All rights reserved. +// + +import Foundation + +/// A container for template variables. +public class Context : Equatable { + var dictionaries:[Dictionary] + + public init(dictionary:Dictionary) { + dictionaries = [dictionary] + } + + public subscript(key: String) -> AnyObject? { + get { + for dictionary in reverse(dictionaries) { + if let value:AnyObject = dictionary[key] { + return value + } + } + + return nil + } + + set(value) { + if dictionaries.count > 0 { + var dictionary = dictionaries.removeLast() + dictionary[key] = value + dictionaries.append(dictionary) + } + } + } + + public func push() { + push(Dictionary()) + } + + public func push(dictionary:Dictionary) { + dictionaries.append(dictionary) + } + + public func pop() { + dictionaries.removeLast() + } +} + +public func ==(lhs:Context, rhs:Context) -> Bool { + return lhs.dictionaries == rhs.dictionaries +} diff --git a/Stencil/Info.plist b/Stencil/Info.plist new file mode 100644 index 0000000..22b5066 --- /dev/null +++ b/Stencil/Info.plist @@ -0,0 +1,28 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + org.cocode.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + NSHumanReadableCopyright + Copyright © 2014 Cocode. All rights reserved. + NSPrincipalClass + + + diff --git a/Stencil/Stencil.h b/Stencil/Stencil.h new file mode 100644 index 0000000..fcfa5e2 --- /dev/null +++ b/Stencil/Stencil.h @@ -0,0 +1,19 @@ +// +// Stencil.h +// Stencil +// +// Created by Kyle Fuller on 23/10/2014. +// Copyright (c) 2014 Cocode. All rights reserved. +// + +#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/Variable.swift b/Stencil/Variable.swift new file mode 100644 index 0000000..d595229 --- /dev/null +++ b/Stencil/Variable.swift @@ -0,0 +1,51 @@ +// +// Variable.swift +// Stencil +// +// Created by Kyle Fuller on 23/10/2014. +// Copyright (c) 2014 Cocode. All rights reserved. +// + +import Foundation + +public struct Variable { + public let variable:String + + public init(_ variable:String) { + self.variable = variable + } + + private func lookup() -> [String] { + return variable.componentsSeparatedByString(".") + } + + public func resolve(context:Context) -> AnyObject? { + var current:AnyObject? = context + + if (variable.hasPrefix("'") && variable.hasSuffix("'")) || (variable.hasPrefix("\"") && variable.hasSuffix("\"")) { + return variable.substringWithRange(variable.startIndex.successor() ..< variable.endIndex.predecessor()) + } + + for bit in lookup() { + if let context = current as? Context { + current = context[bit] + } else if let dictionary = current as? Dictionary { + current = dictionary[bit] + } else if let array = current as? [AnyObject] { + if let index = bit.toInt() { + current = array[index] + } else if bit == "first" { + current = array.first + } else if bit == "last" { + current = array.last + } + } else if let object = current as? NSObject { + current = object.valueForKey(bit) + } else { + return nil + } + } + + return current + } +} diff --git a/StencilTests/ContextTests.swift b/StencilTests/ContextTests.swift new file mode 100644 index 0000000..509bf2e --- /dev/null +++ b/StencilTests/ContextTests.swift @@ -0,0 +1,73 @@ +// +// ContextTests.swift +// Stencil +// +// Created by Kyle Fuller on 23/10/2014. +// Copyright (c) 2014 Cocode. All rights reserved. +// + +import Cocoa +import XCTest +import Stencil + +class ContextTests: XCTestCase { + var context:Context! + + override func setUp() { + context = Context(dictionary: ["name": "Kyle"]) + } + + func testItAllowsYouToRetrieveAValue() { + let name = context["name"] as String! + XCTAssertEqual(name, "Kyle") + } + + func testItAllowsYouToSetValue() { + context["name"] = "Katie" + + let name = context["name"] as String! + XCTAssertEqual(name, "Katie") + } + + func testItAllowsYouToRemoveAValue() { + context["name"] = nil + XCTAssertNil(context["name"]) + } + + func testItAllowsYouToRetrieveAValueFromParent() { + context.push() + + let name = context["name"] as String! + XCTAssertEqual(name, "Kyle") + } + + func testItAllowsYouToOverideAParentVariable() { + context.push() + context["name"] = "Katie" + + let name = context["name"] as String! + XCTAssertEqual(name, "Katie") + } + + func testShowAllowYouToPopVariablesRestoringPreviousState() { + context.push() + context["name"] = "Katie" + context.pop() + + let name = context["name"] as String! + XCTAssertEqual(name, "Kyle") + } + + func testItAllowsYouToPushADictionaryToTheStack() { + context.push(["name": "Katie"]) + + let name = context["name"] as String! + XCTAssertEqual(name, "Katie") + } + + func testItAllowsYouToCompareTwoContextsForEquality() { + let otherContext = Context(dictionary: ["name": "Kyle"]) + + XCTAssertEqual(otherContext, context ) + } +} diff --git a/StencilTests/Info.plist b/StencilTests/Info.plist new file mode 100644 index 0000000..d3de7c7 --- /dev/null +++ b/StencilTests/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + org.cocode.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/StencilTests/StencilTests.swift b/StencilTests/StencilTests.swift new file mode 100644 index 0000000..7deb437 --- /dev/null +++ b/StencilTests/StencilTests.swift @@ -0,0 +1,36 @@ +// +// StencilTests.swift +// StencilTests +// +// Created by Kyle Fuller on 23/10/2014. +// Copyright (c) 2014 Cocode. All rights reserved. +// + +import Cocoa +import XCTest + +class StencilTests: XCTestCase { + + override func setUp() { + super.setUp() + // Put setup code here. This method is called before the invocation of each test method in the class. + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + } + + func testExample() { + // This is an example of a functional test case. + XCTAssert(true, "Pass") + } + + func testPerformanceExample() { + // This is an example of a performance test case. + self.measureBlock() { + // Put the code you want to measure the time of here. + } + } + +} diff --git a/StencilTests/VariableTests.swift b/StencilTests/VariableTests.swift new file mode 100644 index 0000000..97b7134 --- /dev/null +++ b/StencilTests/VariableTests.swift @@ -0,0 +1,70 @@ +// +// VariableTests.swift +// Stencil +// +// Created by Kyle Fuller on 23/10/2014. +// Copyright (c) 2014 Cocode. All rights reserved. +// + +import Cocoa +import XCTest +import Stencil + +@objc class Object : NSObject { + let title = "Hello World" +} + +class VariableTests: XCTestCase { + var context:Context! + + override func setUp() { + context = Context(dictionary: [ + "name": "Kyle", + "contacts": [ "Katie", "Orta", ], + "profiles": [ "github": "kylef", ], + "object": Object(), + ]) + } + + func testResolvingStringLiteral() { + let variable = Variable("\"name\"") + let result = variable.resolve(context) as String! + XCTAssertEqual(result, "name") + } + + func testResolvingVariable() { + let variable = Variable("name") + let result = variable.resolve(context) as String! + XCTAssertEqual(result, "Kyle") + } + + func testResolvingItemFromDictionary() { + let variable = Variable("profiles.github") + let result = variable.resolve(context) as String! + XCTAssertEqual(result, "kylef") + } + + func testResolvingItemFromArrayWithIndex() { + let variable = Variable("contacts.0") + let result = variable.resolve(context) as String! + XCTAssertEqual(result, "Katie") + } + + func testResolvingFirstItemFromArray() { + let variable = Variable("contacts.first") + let result = variable.resolve(context) as String! + XCTAssertEqual(result, "Katie") + } + + func testResolvingLastItemFromArray() { + let variable = Variable("contacts.last") + let result = variable.resolve(context) as String! + XCTAssertEqual(result, "Orta") + } + + func testResolvingValueViaKVO() { + let variable = Variable("object.title") + let result = variable.resolve(context) as String! + XCTAssertEqual(result, "Hello World") + } +}