提交 845056dc 编写于 作者: N Nicholas Maccharoli

Alphabetize font enum, remove nonessential code.

上级 5b14f799
此差异已折叠。
......@@ -13,7 +13,6 @@
AAE1A29D1E02618D00610C40 /* UIFontComplete.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AAE1A2931E02618D00610C40 /* UIFontComplete.framework */; };
AAE1A2A21E02618D00610C40 /* UIFontCompleteTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE1A2A11E02618D00610C40 /* UIFontCompleteTests.swift */; };
AAE1A2A41E02618D00610C40 /* UIFontComplete.h in Headers */ = {isa = PBXBuildFile; fileRef = AAE1A2961E02618D00610C40 /* UIFontComplete.h */; settings = {ATTRIBUTES = (Public, ); }; };
AAE1A2B31E027E8100610C40 /* CodeGeneration.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE1A2B21E027E8100610C40 /* CodeGeneration.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
......@@ -36,7 +35,6 @@
AAE1A29C1E02618D00610C40 /* UIFontCompleteTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UIFontCompleteTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
AAE1A2A11E02618D00610C40 /* UIFontCompleteTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIFontCompleteTests.swift; sourceTree = "<group>"; };
AAE1A2A31E02618D00610C40 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
AAE1A2B21E027E8100610C40 /* CodeGeneration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = CodeGeneration.swift; path = Util/CodeGeneration.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -91,7 +89,6 @@
AAE1A2B61E027F4B00610C40 /* Supporting */,
136122C41EB2AD2A009F45E4 /* Sources */,
AAE1A2B41E027F1A00610C40 /* Extensions */,
AAE1A2B11E027E5600610C40 /* Util */,
);
path = UIFontComplete;
sourceTree = "<group>";
......@@ -105,14 +102,6 @@
path = UIFontCompleteTests;
sourceTree = "<group>";
};
AAE1A2B11E027E5600610C40 /* Util */ = {
isa = PBXGroup;
children = (
AAE1A2B21E027E8100610C40 /* CodeGeneration.swift */,
);
name = Util;
sourceTree = "<group>";
};
AAE1A2B41E027F1A00610C40 /* Extensions */ = {
isa = PBXGroup;
children = (
......@@ -243,7 +232,6 @@
AA813B591F0092450096ABBD /* FontRepresentable.swift in Sources */,
AA813B581F0092450096ABBD /* Font.swift in Sources */,
AA813B5A1F0092450096ABBD /* UIFont+Extension.swift in Sources */,
AAE1A2B31E027E8100610C40 /* CodeGeneration.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
//
// CodeGeneration.swift
// UIFontComplete
//
// Created by Nicholas Maccharoli on 2016/12/15.
//
//
import Foundation
import UIKit
extension String {
fileprivate var enumified: String {
let hyphenless = self.replacingOccurrences(of: "-", with: "")
return String(hyphenless.characters.first!).lowercased() + String(hyphenless.characters.dropFirst())
}
}
enum FontCase {
case family(String)
case name(String, String)
}
func createEnumNamesAndCases() -> [FontCase] {
var fontData = [FontCase]()
for family in UIFont.familyNames where !UIFont.fontNames(forFamilyName: family).isEmpty {
fontData += [FontCase.family(family)]
for font in UIFont.fontNames(forFamilyName: family) {
fontData += [FontCase.name(font.enumified, font)]
}
}
return fontData
}
func createEnum(with fonts: [FontCase], spacing: Int = 4, familyComment: Bool = true) -> String {
var outputString = ""
let indent = (0..<spacing).map({ _ in " "}).joined()
for fontItem in fonts {
switch fontItem {
case .family(let familyName) where familyComment:
outputString += "\n\n" + indent + "// Font Family: " + familyName
case .name(let enumCaseName, let fontString):
outputString += "\n" + indent + "case " + enumCaseName + " = \"\(fontString)\""
default:
break
}
}
return "public enum Font: String {" + outputString + "\n}"
}
func makeTestCases(with fonts: [FontCase]) -> String {
func makeTestCase(fontInfo: FontCase) -> String? {
switch fontInfo {
case .name(let enumName, let fontString):
return "func testFont" + enumName.capitalized + "() {\n" +
" XCTAssert(UIFont(font: ." + enumName + ", size: 12.0) != nil," +
" \"Font \\\"\(fontString)\\\" can not be found.\")" +
"\n}"
default:
return nil
}
}
let results = fonts.flatMap { makeTestCase(fontInfo: $0) }
return results.joined(separator: "\n\n")
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册