1+ ##
2+ ## https://github.com/ColibriApps/MonokaiJsonPlus
3+ ##
4+
5+ import itertools
6+ import xml .dom .minidom
7+ from itertools import permutations
8+
9+ # Define Colors for the 10 Levels
10+ colors = [
11+ "#66D9EF" , # Level 1 - Blue
12+ "#AE81FF" , # Level 2 - Purple
13+ "#F92672" , # Level 3 - Magenta
14+ "#A6E22E" , # Level 4 - Green
15+ "#FD971F" , # Level 5 - Orange
16+ "#E6DB74" , # Level 6 - Yellow
17+ "#66D9EF" , # Level 7 - Blue
18+ "#A6E22E" , # Level 8 - Green
19+ "#E6DB74" , # Level 9 - Yellow
20+
21+ "#66D9EF" , # Level 1 - Blue
22+ "#AE81FF" , # Level 2 - Purple
23+ "#F92672" , # Level 3 - Magenta
24+ "#A6E22E" , # Level 4 - Green
25+ "#FD971F" , # Level 5 - Orange
26+ "#E6DB74" , # Level 6 - Yellow
27+ "#66D9EF" , # Level 7 - Blue
28+ "#A6E22E" , # Level 8 - Green
29+ "#E6DB74" # Level 9 - Yellow
30+
31+ ]
32+
33+ colors_val = [
34+ "#999999" , # Level 1
35+ "#999999" , # Level 2
36+ "#999999" , # Level 3
37+ "#999999" , # Level 4
38+ "#999999" , # Level 5
39+ "#999999" , # Level 6
40+ "#999999" , # Level 7
41+ "#999999" , # Level 8
42+ "#999999" ,
43+ "#999999" ,
44+ "#999999" , # Level 1
45+ "#999999" , # Level 2
46+ "#999999" , # Level 3
47+ "#999999" , # Level 4
48+ "#999999" , # Level 5
49+ "#999999" , # Level 6
50+ "#999999" , # Level 7
51+ "#999999" , # Level 8
52+ "#999999" ,
53+ "#999999"
54+ ]
55+
56+ # defines the placeholder values
57+ prefix1 = "<dict><key>name</key><string>"
58+ prefix2 = "</string><key>scope</key><string>source.json "
59+ postfix1 = "string.quoted.double.json</string><key>settings</key><dict><key>foreground</key><string>"
60+ postfix2 = "</string></dict></dict>"
61+ d = "meta.structure.dictionary.json "
62+ v = "meta.structure.dictionary.value.json "
63+ a = "meta.structure.array.json "
64+
65+ # Logic to generate the required schema of dictionary key and values
66+ def getSequenceArray (items ):
67+ result = []
68+ for item in items :
69+ tmp_item = item [:- 1 ]
70+ s = 'dv' + tmp_item .replace ('d' , 'dv' ) + item [- 1 :]
71+ result .append (s )
72+ if item [- 1 :] == 'd' :
73+ result .append (s + 'v' )
74+ return result
75+
76+ # Generate Levels
77+ # Level 1 & 2
78+ levels = [
79+ [
80+ "d" ,
81+ "dv"
82+ ],
83+ [
84+ "dvd" ,
85+ "dvdv" ,
86+ "dva"
87+ ]
88+ ]
89+
90+ # Level 3
91+ s = set ()
92+ s .update (['' .join (p ) for p in permutations ('dd' )])
93+ s .update (['' .join (p ) for p in permutations ('da' )])
94+ s .update (['' .join (p ) for p in permutations ('aa' )])
95+ levels .append (getSequenceArray (s ))
96+
97+ # Level 4
98+ s = set ()
99+ s .update (['' .join (p ) for p in permutations ('ddd' )])
100+ s .update (['' .join (p ) for p in permutations ('dda' )])
101+ s .update (['' .join (p ) for p in permutations ('daa' )])
102+ s .update (['' .join (p ) for p in permutations ('aaa' )])
103+ levels .append (getSequenceArray (s ))
104+
105+ # Level 5
106+ s = set ()
107+ s .update (['' .join (p ) for p in permutations ('dddd' )])
108+ s .update (['' .join (p ) for p in permutations ('ddda' )])
109+ s .update (['' .join (p ) for p in permutations ('ddaa' )])
110+ s .update (['' .join (p ) for p in permutations ('daaa' )])
111+ s .update (['' .join (p ) for p in permutations ('aaaa' )])
112+ levels .append (getSequenceArray (s ))
113+
114+ # Level 6
115+ s = set ()
116+ s .update (['' .join (p ) for p in permutations ('ddddd' )])
117+ s .update (['' .join (p ) for p in permutations ('dddda' )])
118+ s .update (['' .join (p ) for p in permutations ('dddaa' )])
119+ s .update (['' .join (p ) for p in permutations ('ddaaa' )])
120+ s .update (['' .join (p ) for p in permutations ('daaaa' )])
121+ s .update (['' .join (p ) for p in permutations ('aaaaa' )])
122+ levels .append (getSequenceArray (s ))
123+
124+ # Level 7
125+ s = set ()
126+ s .update (['' .join (p ) for p in permutations ('dddddd' )])
127+ s .update (['' .join (p ) for p in permutations ('ddddda' )])
128+ s .update (['' .join (p ) for p in permutations ('ddddaa' )])
129+ s .update (['' .join (p ) for p in permutations ('dddaaa' )])
130+ s .update (['' .join (p ) for p in permutations ('ddaaaa' )])
131+ s .update (['' .join (p ) for p in permutations ('daaaaa' )])
132+ s .update (['' .join (p ) for p in permutations ('aaaaaa' )])
133+ levels .append (getSequenceArray (s ))
134+
135+ # Level 8
136+ s = set ()
137+ s .update (['' .join (p ) for p in permutations ('ddddddd' )])
138+ s .update (['' .join (p ) for p in permutations ('dddddda' )])
139+ s .update (['' .join (p ) for p in permutations ('dddddaa' )])
140+ s .update (['' .join (p ) for p in permutations ('ddddaaa' )])
141+ s .update (['' .join (p ) for p in permutations ('dddaaaa' )])
142+ s .update (['' .join (p ) for p in permutations ('ddaaaaa' )])
143+ s .update (['' .join (p ) for p in permutations ('daaaaaa' )])
144+ s .update (['' .join (p ) for p in permutations ('aaaaaaa' )])
145+ levels .append (getSequenceArray (s ))
146+
147+ # Level 9
148+ s = set ()
149+ s .update (['' .join (p ) for p in permutations ('dddddddd' )])
150+ s .update (['' .join (p ) for p in permutations ('ddddddda' )])
151+ s .update (['' .join (p ) for p in permutations ('ddddddaa' )])
152+ s .update (['' .join (p ) for p in permutations ('dddddaaa' )])
153+ s .update (['' .join (p ) for p in permutations ('ddddaaaa' )])
154+ s .update (['' .join (p ) for p in permutations ('dddaaaaa' )])
155+ s .update (['' .join (p ) for p in permutations ('ddaaaaaa' )])
156+ s .update (['' .join (p ) for p in permutations ('daaaaaaa' )])
157+ s .update (['' .join (p ) for p in permutations ('aaaaaaaa' )])
158+ levels .append (getSequenceArray (s ))
159+
160+ # Level 10+
161+ s = set ()
162+ s .update (['' .join (p ) for p in permutations ('ddddddddd' )])
163+ s .update (['' .join (p ) for p in permutations ('dddddddda' )])
164+ s .update (['' .join (p ) for p in permutations ('dddddddaa' )])
165+ s .update (['' .join (p ) for p in permutations ('ddddddaaa' )])
166+ s .update (['' .join (p ) for p in permutations ('dddddaaaa' )])
167+ s .update (['' .join (p ) for p in permutations ('ddddaaaaa' )])
168+ s .update (['' .join (p ) for p in permutations ('dddaaaaaa' )])
169+ s .update (['' .join (p ) for p in permutations ('ddaaaaaaa' )])
170+ s .update (['' .join (p ) for p in permutations ('daaaaaaaa' )])
171+ s .update (['' .join (p ) for p in permutations ('aaaaaaaaa' )])
172+ levels .append (getSequenceArray (s ))
173+
174+ # Generate XML output
175+ output = ""
176+ for i in xrange (len (levels ) - 1 , - 1 , - 1 ):
177+ level = levels [i ]
178+ for items in level :
179+ result = prefix1 + "JSON - Level " + str (i + 1 ) + prefix2
180+ for item in list (items ):
181+ if item == "d" :
182+ result = result + d
183+ elif item == "v" :
184+ result = result + v
185+ elif item == "a" :
186+ result = result + a
187+ if item == "v" or item == "a" :
188+ result = result + postfix1 + colors_val [i ] + postfix2
189+ else :
190+ result = result + postfix1 + colors [i ] + postfix2
191+ output = output + xml .dom .minidom .parseString (result ).toprettyxml (
192+ indent = "\t " ).replace ("<?xml version=\" 1.0\" ?>\n " , "" )
193+
194+ print output
0 commit comments