diff --git a/SyntaxKit.podspec b/SyntaxKit.podspec index 57d6ff7..1d827f5 100644 --- a/SyntaxKit.podspec +++ b/SyntaxKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'SyntaxKit' - spec.version = '0.1.0' + spec.version = '0.1.1' spec.authors = {'Sam Soffes' => 'sam@soff.es'} spec.homepage = 'https://github.com/soffes/SyntaxKit' spec.summary = 'TextMate-style syntax highlighting.' diff --git a/SyntaxKit.xcodeproj/project.pbxproj b/SyntaxKit.xcodeproj/project.pbxproj index 4a4e5db..a46ba29 100644 --- a/SyntaxKit.xcodeproj/project.pbxproj +++ b/SyntaxKit.xcodeproj/project.pbxproj @@ -64,6 +64,9 @@ 21F28DDB1B7AC7F8009DD1E9 /* X.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21F28DDA1B7AC7F8009DD1E9 /* X.framework */; }; 21F28DDD1B7AC802009DD1E9 /* X.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21F28DDC1B7AC802009DD1E9 /* X.framework */; }; 21F28DDF1B7AC80B009DD1E9 /* X.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21F28DDE1B7AC80B009DD1E9 /* X.framework */; }; + 414874431C1C4867008BD781 /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 414874421C1C4867008BD781 /* Color.swift */; }; + 414874441C1C4889008BD781 /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 414874421C1C4867008BD781 /* Color.swift */; }; + 414874451C1C488A008BD781 /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 414874421C1C4867008BD781 /* Color.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -138,6 +141,7 @@ 21F28DDA1B7AC7F8009DD1E9 /* X.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = X.framework; path = Carthage/Build/iOS/X.framework; sourceTree = ""; }; 21F28DDC1B7AC802009DD1E9 /* X.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = X.framework; path = Carthage/Build/Mac/X.framework; sourceTree = ""; }; 21F28DDE1B7AC80B009DD1E9 /* X.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = X.framework; path = Carthage/Build/watchOS/X.framework; sourceTree = ""; }; + 414874421C1C4867008BD781 /* Color.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -263,6 +267,7 @@ 211989961B2EC38B00F0D786 /* Theme.swift */, 210299C11B2E8924009C61EE /* Resources */, 210299CD1B2E8924009C61EE /* Tests */, + 414874421C1C4867008BD781 /* Color.swift */, ); path = SyntaxKit; sourceTree = ""; @@ -525,6 +530,7 @@ 211989C01B2EC40500F0D786 /* Capture.swift in Sources */, 211989C31B2EC40500F0D786 /* Language.swift in Sources */, 211989C41B2EC40500F0D786 /* Parser.swift in Sources */, + 414874441C1C4889008BD781 /* Color.swift in Sources */, 211989C11B2EC40500F0D786 /* CaptureCollection.swift in Sources */, 211989C71B2EC40500F0D786 /* ResultSet.swift in Sources */, 211989C51B2EC40500F0D786 /* Pattern.swift in Sources */, @@ -553,6 +559,7 @@ 211989981B2EC38B00F0D786 /* Capture.swift in Sources */, 2119899B1B2EC38B00F0D786 /* Language.swift in Sources */, 2119899C1B2EC38B00F0D786 /* Parser.swift in Sources */, + 414874431C1C4867008BD781 /* Color.swift in Sources */, 211989991B2EC38B00F0D786 /* CaptureCollection.swift in Sources */, 2119899F1B2EC38B00F0D786 /* ResultSet.swift in Sources */, 2119899D1B2EC38B00F0D786 /* Pattern.swift in Sources */, @@ -581,6 +588,7 @@ 2198CED31B36D5DE00BD463F /* Capture.swift in Sources */, 2198CED61B36D5DE00BD463F /* Language.swift in Sources */, 2198CED71B36D5DE00BD463F /* Parser.swift in Sources */, + 414874451C1C488A008BD781 /* Color.swift in Sources */, 2198CED41B36D5DE00BD463F /* CaptureCollection.swift in Sources */, 2198CEDA1B36D5DE00BD463F /* ResultSet.swift in Sources */, 2198CED81B36D5DE00BD463F /* Pattern.swift in Sources */, diff --git a/SyntaxKit/Color.swift b/SyntaxKit/Color.swift new file mode 100644 index 0000000..ddcd8d4 --- /dev/null +++ b/SyntaxKit/Color.swift @@ -0,0 +1,65 @@ +// +// Color.swift +// X +// +// Created by Sam Soffes on 4/28/15. +// Copyright (c) 2015 Sam Soffes. All rights reserved. +// + +#if os(OSX) + import AppKit.NSColor + public typealias ColorType = NSColor + + extension NSColor { + public convenience init(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) { + self.init(SRGBRed: red, green: green, blue: blue, alpha: alpha) + } + } +#else + import UIKit.UIColor + public typealias ColorType = UIColor +#endif + +public typealias Color = ColorType + +extension Color { + public convenience init?(hex s: String) { + var hex: NSString = s + + // Remove `#` and `0x` + if hex.hasPrefix("#") { + hex = hex.substringFromIndex(1) + } else if hex.hasPrefix("0x") { + hex = hex.substringFromIndex(2) + } + + // Invalid if not 3, 6, or 8 characters + let length = hex.length + if length != 3 && length != 6 && length != 8 { + return nil + } + + // Make the string 8 characters long for easier parsing + if length == 3 { + let r = hex.substringWithRange(NSMakeRange(0, 1)) + let g = hex.substringWithRange(NSMakeRange(1, 1)) + let b = hex.substringWithRange(NSMakeRange(2, 1)) + hex = r + r + g + g + b + b + "ff" + } else if length == 6 { + hex = String(hex) + "ff" + } + + // Convert 2 character strings to CGFloats + func hexValue(string: String) -> CGFloat { + let value = Double(strtoul(string, nil, 16)) + return CGFloat(value / 255.0) + } + + let red = hexValue(hex.substringWithRange(NSMakeRange(0, 2))) + let green = hexValue(hex.substringWithRange(NSMakeRange(2, 2))) + let blue = hexValue(hex.substringWithRange(NSMakeRange(4, 2))) + let alpha = hexValue(hex.substringWithRange(NSMakeRange(6, 2))) + + self.init(red: red, green: green, blue: blue, alpha: alpha) + } +} \ No newline at end of file diff --git a/SyntaxKit/Theme.swift b/SyntaxKit/Theme.swift index 0e22ee2..b105522 100644 --- a/SyntaxKit/Theme.swift +++ b/SyntaxKit/Theme.swift @@ -7,7 +7,6 @@ // import Foundation -import X #if os(iOS) || os(watchOS) import UIKit