-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update dependencies, initial support for fonts * Don't use keypaths as functions * Better indent ergonomics * Encapsulate bundle access and clean up * More cleanup * Reorder to image - color - font - localization. Trim space-only lines. * Improve README
- Loading branch information
1 parent
3ada8be
commit 8178d10
Showing
14 changed files
with
377 additions
and
416 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Foundation | ||
|
||
private struct FontValue: Equatable, Comparable { | ||
let methodName: String | ||
let fontName: String | ||
|
||
func declaration(indentLevel: Int) -> String { | ||
#"\#(String.indent(indentLevel))public static func \#(methodName)(ofSize size: CGFloat) -> UIFont { return UIFont(name: "\#(fontName)", size: size)! }"# | ||
} | ||
|
||
static func <(lhs: FontValue, rhs: FontValue) -> Bool { | ||
lhs.methodName < rhs.methodName | ||
} | ||
} | ||
|
||
enum FontEnumBuilder { | ||
static func fontsEnumString(forFilesAtPaths paths: [String], topLevelName: String) throws -> String? { | ||
let fontValues: [FontValue] = paths.compactMap { path in | ||
guard | ||
let data = try? Data(contentsOf: URL(fileURLWithPath: path)), | ||
let font = CGDataProvider(data: data as CFData).flatMap(CGFont.init), | ||
let fullName = font.fullName as String?, | ||
let postScriptName = font.postScriptName as String? else { return nil } | ||
|
||
var components = fullName.split(separator: " ") | ||
let first = components.removeFirst().lowercased() | ||
let rest = components.map { $0.capitalized } | ||
let methodName = ([first] + rest).joined() | ||
|
||
return FontValue(methodName: methodName, | ||
fontName: postScriptName) | ||
} | ||
|
||
guard fontValues.isEmpty == false else { return nil } | ||
|
||
var result = """ | ||
public enum \(topLevelName) { | ||
""" | ||
|
||
for font in fontValues.sorted() { | ||
result += font.declaration(indentLevel: 1) | ||
result += "\n" | ||
} | ||
|
||
result += "}" | ||
return result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.