Skip to content
This repository was archived by the owner on Aug 24, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SyntaxKit.podspec
Original file line number Diff line number Diff line change
@@ -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.'
Expand Down
8 changes: 8 additions & 0 deletions SyntaxKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -138,6 +141,7 @@
21F28DDA1B7AC7F8009DD1E9 /* X.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = X.framework; path = Carthage/Build/iOS/X.framework; sourceTree = "<group>"; };
21F28DDC1B7AC802009DD1E9 /* X.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = X.framework; path = Carthage/Build/Mac/X.framework; sourceTree = "<group>"; };
21F28DDE1B7AC80B009DD1E9 /* X.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = X.framework; path = Carthage/Build/watchOS/X.framework; sourceTree = "<group>"; };
414874421C1C4867008BD781 /* Color.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Color.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -263,6 +267,7 @@
211989961B2EC38B00F0D786 /* Theme.swift */,
210299C11B2E8924009C61EE /* Resources */,
210299CD1B2E8924009C61EE /* Tests */,
414874421C1C4867008BD781 /* Color.swift */,
);
path = SyntaxKit;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
65 changes: 65 additions & 0 deletions SyntaxKit/Color.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
1 change: 0 additions & 1 deletion SyntaxKit/Theme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//

import Foundation
import X

#if os(iOS) || os(watchOS)
import UIKit
Expand Down