-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstoryboardIdentifierConstants.py
95 lines (71 loc) · 3.26 KB
/
storyboardIdentifierConstants.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
92
93
94
def determineIdentiferNameFromString(string):
identiferName = ""
for stringSection in string.split(" "):
if "identifier=" in stringSection:
identiferName = stringSection.split("=")[1].replace("\"", "")
return identiferName
def stripOutIdentifierNames(arrayOfStrings):
arrayOfIdentiferNames = []
for string in arrayOfStrings:
if "<segue" in string:
if( determineIdentiferNameFromString(string) != "" ):
arrayOfIdentiferNames.append( determineIdentiferNameFromString(string) )
return arrayOfIdentiferNames
def identifierNamesToConstantCodeString(identifierNames):
resultCodeString = ""
for identifierName in identifierNames:
resultCodeString = resultCodeString + "NSString * const k" + identifierName.title() + " = @\"" + identifierName + "\";\n"
return resultCodeString
def storyboardNamesToConstantCodeString(storyboardNames):
resultCodeString = ""
for storyboardName in storyboardNames:
resultCodeString = resultCodeString + "NSString * const k" + storyboardName.title() + "Storyboard = @\"" + storyboardName + "\";\n"
return resultCodeString
def buildImplementationFileStringFromCodeBody(Bodystring):
return "#import \"StoryboardIdentifiers.h\"\n\n" + Bodystring
def identifierNamesToExternConstantsString(identifierNames):
resultCodeString = ""
for identifierName in identifierNames:
resultCodeString = resultCodeString + "extern NSString * const k" + identifierName.title() + ";\n"
return resultCodeString
def storyboardNamesToExternConstantsString(storyboardNames):
resultCodeString = ""
for storyboardName in storyboardNames:
resultCodeString = resultCodeString + "extern NSString * const k" + storyboardName.title() + "Storyboard;\n"
return resultCodeString
def buildInterfaceFileStringFromCodeBody(Bodystring):
return "#import <Foundation/Foundation.h>\n\n" + Bodystring
#--- script begin ---
import os
import sys
rootdir = os.path.dirname(os.path.realpath(__file__))
storyboardFileNames = []
for root, subFolders, files in os.walk(rootdir):
for afile in files:
if ".storyboard" in afile:
storyboardFileNames.append( os.path.join(root, afile) )
strippedStoryboardNames = []
for storyboardFileName in storyboardFileNames:
strippedName = storyboardFileName.split("/")[-1].replace(".storyboard","")
strippedStoryboardNames.append(strippedName)
identifierNames = []
for storyboardName in storyboardFileNames:
data = 0
with open (storyboardName, "r") as myfile:
data=myfile.readlines()
identifierNames = identifierNames + stripOutIdentifierNames(data)
identifierNames = list(set(identifierNames))
codeBodyString = storyboardNamesToConstantCodeString(strippedStoryboardNames) + "\n\n" + identifierNamesToConstantCodeString(identifierNames)
implementationFileString = buildImplementationFileStringFromCodeBody(codeBodyString)
with open('StoryboardIdentifiers.m', 'w+') as f:
f.truncate()
f.write(implementationFileString)
f.close()
codeExternString = storyboardNamesToExternConstantsString(strippedStoryboardNames) + "\n\n" + identifierNamesToExternConstantsString(identifierNames)
interfaceFileString = buildInterfaceFileStringFromCodeBody(codeExternString)
with open('StoryboardIdentifiers.h', 'w+') as f:
f.truncate()
f.write(interfaceFileString)
f.close()
print implementationFileString
print interfaceFileString