-
Notifications
You must be signed in to change notification settings - Fork 0
/
Enum.py
91 lines (82 loc) · 3.19 KB
/
Enum.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from datetime import datetime
# Get the current local date
current_date = datetime.now()
# Format the date as a string in the desired format
formatted_date = current_date.strftime('%-m/%-d/%Y')
numbers = {
"case": "caseImage",
"repeat": "repeatImage",
"return": "returnImage",
"0": "zero",
"1": "one",
"2": "two",
"3": "three",
"4": "four",
"5": "five",
"6": "six",
"7": "seven",
"8": "eight",
"9": "nine"
}
file = open("Sources/SFSymbolsKit/Enum.swift", "w")
file.write("//\n")
file.write("// SFSymbol.swift\n")
file.write("// SFSymbols\n")
file.write("//\n")
file.write(f"// Generated by SFSymbolsKit on {formatted_date}\n")
file.write("//\n")
file.write("\n")
file.write("#if canImport(AppKit)\n")
file.write("import AppKit\n")
file.write("#endif\n")
file.write("#if canImport(UIKit)\n")
file.write("import UIKit\n")
file.write("#endif\n")
file.write("\n")
file.write("/// This is the `SFSymbolsKit` enum that provides the SFSymbols `String` as a raw values for each case corresponding to each SFSymbol. The corresponding SFSybmol to each case can be found in the SFSybmols App.\n")
file.write("public enum SFSymbol: String, CaseIterable {\n")
file.write("\n")
with open('SFSymbols.txt') as topo_file:
for line in topo_file:
parts = line.split('.')
camel_case_name = ""
for part in parts:
if part == parts[0]:
if part.rstrip() in numbers:
camel_case_name += numbers[part.rstrip()]
continue
elif part[0] in numbers:
camel_case_name += numbers[part[0]] + part[1:]
continue
camel_case_name += part
continue
camel_case_name += part.capitalize()
result = " case {} = \"{}\"\n".format(camel_case_name.rstrip(), line.rstrip())
file.write(result)
file.write("\n")
file.write("#if canImport(UIKit)\n")
file.write(" @available(iOS 13, *)\n")
file.write(" /// The `image` property of the `SFSymbols` enum provides a `UIImage` corresponding to the `SFSymbols` case selected.\n")
file.write(" var image: UIImage {\n")
file.write(" guard let image = UIImage(systemName: self.rawValue)\n")
file.write(" else { return UIImage() }\n")
file.write(" return image\n")
file.write(" }\n")
file.write("#endif\n")
file.write("#if canImport(AppKit)\n")
file.write(" @available(macOS 11.0, *)\n")
file.write(" /// The `image` property of the `SFSymbols` enum provides a `NSImage` corresponding to the `SFSymbols` case selected.\n")
file.write(" var image: NSImage {\n")
file.write(" guard let image = NSImage(systemSymbolName: self.rawValue, accessibilityDescription: \"This is the symbole for\\(self.rawValue)\")\n")
file.write(" else { return NSImage() }\n")
file.write(" return image\n")
file.write(" }\n")
file.write("#endif\n")
file.write("\n")
file.write(" /// The `string` property of the `SFSymbols` enum provides a `String` corresponding to the `SFSymbols` case selected.\n")
file.write(" var string: String {\n")
file.write(" return self.rawValue\n")
file.write(" }\n")
file.write("\n")
file.write("}\n")
file.close()