Initial project with Context and Variable.

This commit is contained in:
Kyle Fuller
2014-10-23 14:59:57 +01:00
parent c415bfe84b
commit e34084f3f0
10 changed files with 795 additions and 0 deletions

View File

@@ -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 = "<group>"; };
7725B3CC19F92B61002CF74B /* Variable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Variable.swift; sourceTree = "<group>"; };
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 = "<group>"; };
77FAAE5719F91E480029DC5E /* Stencil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Stencil.h; sourceTree = "<group>"; };
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 = "<group>"; };
77FAAE6419F91E480029DC5E /* StencilTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StencilTests.swift; sourceTree = "<group>"; };
77FAAE6E19F920750029DC5E /* Context.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Context.swift; sourceTree = "<group>"; };
77FAAE7019F9208C0029DC5E /* ContextTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContextTests.swift; sourceTree = "<group>"; };
/* 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 = "<group>";
};
77FAAE5319F91E480029DC5E /* Products */ = {
isa = PBXGroup;
children = (
77FAAE5219F91E480029DC5E /* Stencil.framework */,
77FAAE5D19F91E480029DC5E /* StencilTests.xctest */,
);
name = Products;
sourceTree = "<group>";
};
77FAAE5419F91E480029DC5E /* Stencil */ = {
isa = PBXGroup;
children = (
77FAAE5719F91E480029DC5E /* Stencil.h */,
77FAAE6E19F920750029DC5E /* Context.swift */,
7725B3CC19F92B61002CF74B /* Variable.swift */,
77FAAE5519F91E480029DC5E /* Supporting Files */,
);
path = Stencil;
sourceTree = "<group>";
};
77FAAE5519F91E480029DC5E /* Supporting Files */ = {
isa = PBXGroup;
children = (
77FAAE5619F91E480029DC5E /* Info.plist */,
);
name = "Supporting Files";
sourceTree = "<group>";
};
77FAAE6119F91E480029DC5E /* StencilTests */ = {
isa = PBXGroup;
children = (
77FAAE6419F91E480029DC5E /* StencilTests.swift */,
77FAAE7019F9208C0029DC5E /* ContextTests.swift */,
7725B3CA19F92B4F002CF74B /* VariableTests.swift */,
77FAAE6219F91E480029DC5E /* Supporting Files */,
);
path = StencilTests;
sourceTree = "<group>";
};
77FAAE6219F91E480029DC5E /* Supporting Files */ = {
isa = PBXGroup;
children = (
77FAAE6319F91E480029DC5E /* Info.plist */,
);
name = "Supporting Files";
sourceTree = "<group>";
};
/* 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 */;
}

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:Stencil.xcodeproj">
</FileRef>
</Workspace>

54
Stencil/Context.swift Normal file
View File

@@ -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<String, AnyObject>]
public init(dictionary:Dictionary<String, AnyObject>) {
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<String, String>())
}
public func push(dictionary:Dictionary<String, String>) {
dictionaries.append(dictionary)
}
public func pop() {
dictionaries.removeLast()
}
}
public func ==(lhs:Context, rhs:Context) -> Bool {
return lhs.dictionaries == rhs.dictionaries
}

28
Stencil/Info.plist Normal file
View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>org.cocode.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2014 Cocode. All rights reserved.</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>

19
Stencil/Stencil.h Normal file
View File

@@ -0,0 +1,19 @@
//
// Stencil.h
// Stencil
//
// Created by Kyle Fuller on 23/10/2014.
// Copyright (c) 2014 Cocode. All rights reserved.
//
#import <Cocoa/Cocoa.h>
//! 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 <Stencil/PublicHeader.h>

51
Stencil/Variable.swift Normal file
View File

@@ -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<String, AnyObject> {
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
}
}

View File

@@ -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 )
}
}

24
StencilTests/Info.plist Normal file
View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>org.cocode.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

View File

@@ -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.
}
}
}

View File

@@ -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")
}
}