corrade-nucleus-nucleons – Blame information for rev 24
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
20 | office | 1 | ace.define("ace/ext/beautify/php_rules",["require","exports","module","ace/token_iterator"], function(require, exports, module) { |
2 | "use strict"; |
||
3 | var TokenIterator = require("ace/token_iterator").TokenIterator; |
||
4 | exports.newLines = [{ |
||
5 | type: 'support.php_tag', |
||
6 | value: '<?php' |
||
7 | }, { |
||
8 | type: 'support.php_tag', |
||
9 | value: '<?' |
||
10 | }, { |
||
11 | type: 'support.php_tag', |
||
12 | value: '?>' |
||
13 | }, { |
||
14 | type: 'paren.lparen', |
||
15 | value: '{', |
||
16 | indent: true |
||
17 | }, { |
||
18 | type: 'paren.rparen', |
||
19 | breakBefore: true, |
||
20 | value: '}', |
||
21 | indent: false |
||
22 | }, { |
||
23 | type: 'paren.rparen', |
||
24 | breakBefore: true, |
||
25 | value: '})', |
||
26 | indent: false, |
||
27 | dontBreak: true |
||
28 | }, { |
||
29 | type: 'comment' |
||
30 | }, { |
||
31 | type: 'text', |
||
32 | value: ';' |
||
33 | }, { |
||
34 | type: 'text', |
||
35 | value: ':', |
||
36 | context: 'php' |
||
37 | }, { |
||
38 | type: 'keyword', |
||
39 | value: 'case', |
||
40 | indent: true, |
||
41 | dontBreak: true |
||
42 | }, { |
||
43 | type: 'keyword', |
||
44 | value: 'default', |
||
45 | indent: true, |
||
46 | dontBreak: true |
||
47 | }, { |
||
48 | type: 'keyword', |
||
49 | value: 'break', |
||
50 | indent: false, |
||
51 | dontBreak: true |
||
52 | }, { |
||
53 | type: 'punctuation.doctype.end', |
||
54 | value: '>' |
||
55 | }, { |
||
56 | type: 'meta.tag.punctuation.end', |
||
57 | value: '>' |
||
58 | }, { |
||
59 | type: 'meta.tag.punctuation.begin', |
||
60 | value: '<', |
||
61 | blockTag: true, |
||
62 | indent: true, |
||
63 | dontBreak: true |
||
64 | }, { |
||
65 | type: 'meta.tag.punctuation.begin', |
||
66 | value: '</', |
||
67 | indent: false, |
||
68 | breakBefore: true, |
||
69 | dontBreak: true |
||
70 | }, { |
||
71 | type: 'punctuation.operator', |
||
72 | value: ';' |
||
73 | }]; |
||
74 | |||
75 | exports.spaces = [{ |
||
76 | type: 'xml-pe', |
||
77 | prepend: true |
||
78 | },{ |
||
79 | type: 'entity.other.attribute-name', |
||
80 | prepend: true |
||
81 | }, { |
||
82 | type: 'storage.type', |
||
83 | value: 'var', |
||
84 | append: true |
||
85 | }, { |
||
86 | type: 'storage.type', |
||
87 | value: 'function', |
||
88 | append: true |
||
89 | }, { |
||
90 | type: 'keyword.operator', |
||
91 | value: '=' |
||
92 | }, { |
||
93 | type: 'keyword', |
||
94 | value: 'as', |
||
95 | prepend: true, |
||
96 | append: true |
||
97 | }, { |
||
98 | type: 'keyword', |
||
99 | value: 'function', |
||
100 | append: true |
||
101 | }, { |
||
102 | type: 'support.function', |
||
103 | next: /[^\(]/, |
||
104 | append: true |
||
105 | }, { |
||
106 | type: 'keyword', |
||
107 | value: 'or', |
||
108 | append: true, |
||
109 | prepend: true |
||
110 | }, { |
||
111 | type: 'keyword', |
||
112 | value: 'and', |
||
113 | append: true, |
||
114 | prepend: true |
||
115 | }, { |
||
116 | type: 'keyword', |
||
117 | value: 'case', |
||
118 | append: true |
||
119 | }, { |
||
120 | type: 'keyword.operator', |
||
121 | value: '||', |
||
122 | append: true, |
||
123 | prepend: true |
||
124 | }, { |
||
125 | type: 'keyword.operator', |
||
126 | value: '&&', |
||
127 | append: true, |
||
128 | prepend: true |
||
129 | }]; |
||
130 | exports.singleTags = ['!doctype','area','base','br','hr','input','img','link','meta']; |
||
131 | |||
132 | exports.transform = function(iterator, maxPos, context) { |
||
133 | var token = iterator.getCurrentToken(); |
||
134 | |||
135 | var newLines = exports.newLines; |
||
136 | var spaces = exports.spaces; |
||
137 | var singleTags = exports.singleTags; |
||
138 | |||
139 | var code = ''; |
||
140 | |||
141 | var indentation = 0; |
||
142 | var dontBreak = false; |
||
143 | var tag; |
||
144 | var lastTag; |
||
145 | var lastToken = {}; |
||
146 | var nextTag; |
||
147 | var nextToken = {}; |
||
148 | var breakAdded = false; |
||
149 | var value = ''; |
||
150 | |||
151 | while (token!==null) { |
||
152 | console.log(token); |
||
153 | |||
154 | if( !token ){ |
||
155 | token = iterator.stepForward(); |
||
156 | continue; |
||
157 | } |
||
158 | if( token.type == 'support.php_tag' && token.value != '?>' ){ |
||
159 | context = 'php'; |
||
160 | } |
||
161 | else if( token.type == 'support.php_tag' && token.value == '?>' ){ |
||
162 | context = 'html'; |
||
163 | } |
||
164 | else if( token.type == 'meta.tag.name.style' && context != 'css' ){ |
||
165 | context = 'css'; |
||
166 | } |
||
167 | else if( token.type == 'meta.tag.name.style' && context == 'css' ){ |
||
168 | context = 'html'; |
||
169 | } |
||
170 | else if( token.type == 'meta.tag.name.script' && context != 'js' ){ |
||
171 | context = 'js'; |
||
172 | } |
||
173 | else if( token.type == 'meta.tag.name.script' && context == 'js' ){ |
||
174 | context = 'html'; |
||
175 | } |
||
176 | |||
177 | nextToken = iterator.stepForward(); |
||
178 | if (nextToken && nextToken.type.indexOf('meta.tag.name') == 0) { |
||
179 | nextTag = nextToken.value; |
||
180 | } |
||
181 | if ( lastToken.type == 'support.php_tag' && lastToken.value == '<?=') { |
||
182 | dontBreak = true; |
||
183 | } |
||
184 | if (token.type == 'meta.tag.name') { |
||
185 | token.value = token.value.toLowerCase(); |
||
186 | } |
||
187 | if (token.type == 'text') { |
||
188 | token.value = token.value.trim(); |
||
189 | } |
||
190 | if (!token.value) { |
||
191 | token = nextToken; |
||
192 | continue; |
||
193 | } |
||
194 | value = token.value; |
||
195 | for (var i in spaces) { |
||
196 | if ( |
||
197 | token.type == spaces[i].type && |
||
198 | (!spaces[i].value || token.value == spaces[i].value) && |
||
199 | ( |
||
200 | nextToken && |
||
201 | (!spaces[i].next || spaces[i].next.test(nextToken.value)) |
||
202 | ) |
||
203 | ) { |
||
204 | if (spaces[i].prepend) { |
||
205 | value = ' ' + token.value; |
||
206 | } |
||
207 | |||
208 | if (spaces[i].append) { |
||
209 | value += ' '; |
||
210 | } |
||
211 | } |
||
212 | } |
||
213 | if (token.type.indexOf('meta.tag.name') == 0) { |
||
214 | tag = token.value; |
||
215 | } |
||
216 | breakAdded = false; |
||
217 | for (i in newLines) { |
||
218 | if ( |
||
219 | token.type == newLines[i].type && |
||
220 | ( |
||
221 | !newLines[i].value || |
||
222 | token.value == newLines[i].value |
||
223 | ) && |
||
224 | ( |
||
225 | !newLines[i].blockTag || |
||
226 | singleTags.indexOf(nextTag) === -1 |
||
227 | ) && |
||
228 | ( |
||
229 | !newLines[i].context || |
||
230 | newLines[i].context === context |
||
231 | ) |
||
232 | ) { |
||
233 | if (newLines[i].indent === false) { |
||
234 | indentation--; |
||
235 | } |
||
236 | |||
237 | if ( |
||
238 | newLines[i].breakBefore && |
||
239 | ( !newLines[i].prev || newLines[i].prev.test(lastToken.value) ) |
||
240 | ) { |
||
241 | code += "\n"; |
||
242 | breakAdded = true; |
||
243 | for (i = 0; i < indentation; i++) { |
||
244 | code += "\t"; |
||
245 | } |
||
246 | } |
||
247 | |||
248 | break; |
||
249 | } |
||
250 | } |
||
251 | |||
252 | if (dontBreak===false) { |
||
253 | for (i in newLines) { |
||
254 | if ( |
||
255 | lastToken.type == newLines[i].type && |
||
256 | ( |
||
257 | !newLines[i].value || lastToken.value == newLines[i].value |
||
258 | ) && |
||
259 | ( |
||
260 | !newLines[i].blockTag || |
||
261 | singleTags.indexOf(tag) === -1 |
||
262 | ) && |
||
263 | ( |
||
264 | !newLines[i].context || |
||
265 | newLines[i].context === context |
||
266 | ) |
||
267 | ) { |
||
268 | if (newLines[i].indent === true) { |
||
269 | indentation++; |
||
270 | } |
||
271 | |||
272 | if (!newLines[i].dontBreak && !breakAdded) { |
||
273 | code += "\n"; |
||
274 | for (i = 0; i < indentation; i++) { |
||
275 | code += "\t"; |
||
276 | } |
||
277 | } |
||
278 | |||
279 | break; |
||
280 | } |
||
281 | } |
||
282 | } |
||
283 | |||
284 | code += value; |
||
285 | if ( lastToken.type == 'support.php_tag' && lastToken.value == '?>' ) { |
||
286 | dontBreak = false; |
||
287 | } |
||
288 | lastTag = tag; |
||
289 | |||
290 | lastToken = token; |
||
291 | |||
292 | token = nextToken; |
||
293 | |||
294 | if (token===null) { |
||
295 | break; |
||
296 | } |
||
297 | } |
||
298 | |||
299 | return code; |
||
300 | }; |
||
301 | |||
302 | |||
303 | |||
304 | }); |
||
305 | |||
306 | ace.define("ace/ext/beautify",["require","exports","module","ace/token_iterator","ace/ext/beautify/php_rules"], function(require, exports, module) { |
||
307 | "use strict"; |
||
308 | var TokenIterator = require("ace/token_iterator").TokenIterator; |
||
309 | |||
310 | var phpTransform = require("./beautify/php_rules").transform; |
||
311 | |||
312 | exports.beautify = function(session) { |
||
313 | var iterator = new TokenIterator(session, 0, 0); |
||
314 | var token = iterator.getCurrentToken(); |
||
315 | |||
316 | var context = session.$modeId.split("/").pop(); |
||
317 | |||
318 | var code = phpTransform(iterator, context); |
||
319 | session.doc.setValue(code); |
||
320 | }; |
||
321 | |||
322 | exports.commands = [{ |
||
323 | name: "beautify", |
||
324 | exec: function(editor) { |
||
325 | exports.beautify(editor.session); |
||
326 | }, |
||
327 | bindKey: "Ctrl-Shift-B" |
||
328 | }] |
||
329 | |||
330 | }); |
||
331 | (function() { |
||
332 | ace.require(["ace/ext/beautify"], function() {}); |
||
333 | })(); |
||
334 |