forked from calimarkus/XcodeAutocompleteSnippets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.generateDescription.py
More file actions
57 lines (46 loc) · 2.06 KB
/
.generateDescription.py
File metadata and controls
57 lines (46 loc) · 2.06 KB
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
from xml.dom import minidom
import os
import glob
print ">> Updating README.md based on .codesnippet files"
file = open('README.md', 'w')
file.write('# CodeSnippets\n\n')
file.write('These are some useful Xcode 4 CodeSnippets. \n')
file.write('To use them, clone this repository into the following path:\n\n')
file.write(' cd ~/Library/Developer/Xcode/UserData/CodeSnippets\n')
file.write(' git clone git@github.com:nxtbgthng/CodeSnippets.git .\n\n')
file.write('(The folder must be empty, to clone the repository directly in it.) \n')
file.write('And you\'re ready to go.\n\n')
file.write('#### Installing the pre-commit hook \n')
file.write('This README is generated automatically using `.generateDescription.py`. \n')
file.write('To run this script automatically before each commit, install the pre-commit hook like this:\n\n')
file.write(' sh .install-precommit-hook.sh\n\n')
file.write('## Snippet Descriptions\n\n')
listing = os.listdir(".")
for fileName in listing:
if not fileName.endswith(".codesnippet"):
continue
xmldoc = minidom.parse(fileName)
keyslist = xmldoc.getElementsByTagName('key')
allChilds = xmldoc.getElementsByTagName('dict')[0].childNodes
for x in allChilds:
if not x.firstChild:
allChilds.remove(x)
title=""
summary=""
shortcut=""
contents=""
for key in keyslist:
value = key.firstChild.nodeValue
if (value == "IDECodeSnippetCompletionPrefix"):
shortcut = allChilds[allChilds.index(key)+1].firstChild.nodeValue
elif value == "IDECodeSnippetContents":
contents = allChilds[allChilds.index(key)+1].firstChild.nodeValue
elif value == "IDECodeSnippetSummary":
summary = allChilds[allChilds.index(key)+1].firstChild.nodeValue
elif value == "IDECodeSnippetTitle":
title = allChilds[allChilds.index(key)+1].firstChild.nodeValue
file.write('**' + fileName + '** (' + title + ') \n')
file.write('Shortcut: `' + shortcut + '` \n')
file.write(summary + '\n\n')
file.write(' ' + contents.replace('\n', '\n ') + '\n\n')
file.close()