/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk

« back to all changes in this revision

Viewing changes to codeigniter/js/ace/mode-stylus.js

  • Committer: galaxyAbstractor
  • Date: 2013-04-10 15:49:32 UTC
  • mto: (19.1.5 lenasys)
  • mto: This revision was merged to the branch mainline in revision 23.
  • Revision ID: galaxyabstractor@gmail.com-20130410154932-4vizlzk0ar5gykvi
* Added an simple admin panel to the codeviewer-cmssy stuff
* Redesigned a bit like the mockups - still stuff to come
* Implemented the codeviewer + admin panel again using the Framework CodeIgniter instead 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ***** BEGIN LICENSE BLOCK *****
 
2
 * Distributed under the BSD license:
 
3
 *
 
4
 * Copyright (c) 2012, Ajax.org B.V.
 
5
 * All rights reserved.
 
6
 * 
 
7
 * Redistribution and use in source and binary forms, with or without
 
8
 * modification, are permitted provided that the following conditions are met:
 
9
 *     * Redistributions of source code must retain the above copyright
 
10
 *       notice, this list of conditions and the following disclaimer.
 
11
 *     * Redistributions in binary form must reproduce the above copyright
 
12
 *       notice, this list of conditions and the following disclaimer in the
 
13
 *       documentation and/or other materials provided with the distribution.
 
14
 *     * Neither the name of Ajax.org B.V. nor the
 
15
 *       names of its contributors may be used to endorse or promote products
 
16
 *       derived from this software without specific prior written permission.
 
17
 * 
 
18
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 
19
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
20
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
21
 * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
 
22
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
23
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 
25
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
26
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 
27
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
28
 *
 
29
 *
 
30
 * Contributor(s):
 
31
 * 
 
32
 *
 
33
 *
 
34
 * ***** END LICENSE BLOCK ***** */
 
35
 
 
36
define('ace/mode/stylus', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/stylus_highlight_rules', 'ace/mode/folding/coffee'], function(require, exports, module) {
 
37
 
 
38
 
 
39
var oop = require("../lib/oop");
 
40
var TextMode = require("./text").Mode;
 
41
var Tokenizer = require("../tokenizer").Tokenizer;
 
42
var StylusHighlightRules = require("./stylus_highlight_rules").StylusHighlightRules;
 
43
var FoldMode = require("./folding/coffee").FoldMode;
 
44
 
 
45
var Mode = function() {
 
46
    var highlighter = new StylusHighlightRules();
 
47
    this.foldingRules = new FoldMode();
 
48
    
 
49
    this.$tokenizer = new Tokenizer(highlighter.getRules());
 
50
};
 
51
oop.inherits(Mode, TextMode);
 
52
 
 
53
(function() {
 
54
}).call(Mode.prototype);
 
55
 
 
56
exports.Mode = Mode;
 
57
});
 
58
 
 
59
define('ace/mode/stylus_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules', 'ace/mode/css_highlight_rules'], function(require, exports, module) {
 
60
 
 
61
 
 
62
var oop = require("../lib/oop");
 
63
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
 
64
var CssHighlightRules = require("./css_highlight_rules");
 
65
 
 
66
var StylusHighlightRules = function() {
 
67
 
 
68
    var keywordMapper = this.createKeywordMapper({
 
69
        "support.type": CssHighlightRules.supportType,
 
70
        "support.function": CssHighlightRules.supportFunction,
 
71
        "support.constant": CssHighlightRules.supportConstant,
 
72
        "support.constant.color": CssHighlightRules.supportConstantColor,
 
73
        "support.constant.fonts": CssHighlightRules.supportConstantFonts
 
74
    }, "text", true);
 
75
 
 
76
    this.$rules = {
 
77
    start: [
 
78
        {
 
79
            token : "comment",
 
80
            regex : /\/\/.*$/
 
81
        },
 
82
        {
 
83
            token : "comment", // multi line comment
 
84
            regex : /\/\*/,
 
85
            next : "comment"
 
86
        },
 
87
        {
 
88
            token: ["entity.name.function.stylus", "text"],
 
89
            regex: "^([-a-zA-Z_][-\\w]*)?(\\()"
 
90
        },
 
91
        {
 
92
            token: ["entity.other.attribute-name.class.stylus"],
 
93
            regex: "\\.-?[_a-zA-Z]+[_a-zA-Z0-9-]*"
 
94
        },
 
95
        {
 
96
            token: ["entity.language.stylus"],
 
97
            regex: "^ *&"
 
98
        },
 
99
        {
 
100
            token: ["variable.language.stylus"],
 
101
            regex: "(arguments)"
 
102
        },
 
103
        {
 
104
            token: ["keyword.stylus"],
 
105
            regex: "@[-\\w]+"
 
106
        },
 
107
        {
 
108
            token : ["punctuation", "entity.other.attribute-name.pseudo-element.css"],
 
109
            regex : CssHighlightRules.pseudoElements
 
110
        }, {
 
111
            token : ["punctuation", "entity.other.attribute-name.pseudo-class.css"],
 
112
            regex : CssHighlightRules.pseudoClasses
 
113
        }, 
 
114
        {
 
115
            token: ["entity.name.tag.stylus"],
 
116
            regex: "(?:\\b)(a|abbr|acronym|address|area|article|aside|audio|b|base|big|blockquote|body|br|button|canvas|caption|cite|code|col|colgroup|datalist|dd|del|details|dfn|dialog|div|dl|dt|em|eventsource|fieldset|figure|figcaption|footer|form|frame|frameset|(?:h[1-6])|head|header|hgroup|hr|html|i|iframe|img|input|ins|kbd|label|legend|li|link|map|mark|menu|meta|meter|nav|noframes|noscript|object|ol|optgroup|option|output|p|param|pre|progress|q|samp|script|section|select|small|span|strike|strong|style|sub|summary|sup|table|tbody|td|textarea|tfoot|th|thead|time|title|tr|tt|ul|var|video)(?:\\b)"
 
117
        },
 
118
        {
 
119
            token : "constant.numeric",  // hex6 color
 
120
            regex : "#[a-f0-9]{6}"
 
121
        }, 
 
122
        {
 
123
            token : "constant.numeric", // hex3 color
 
124
            regex : "#[a-f0-9]{3}"
 
125
        }, 
 
126
        {
 
127
            token: ["punctuation.definition.entity.stylus", "entity.other.attribute-name.id.stylus"],
 
128
            regex: "(#)([a-zA-Z][a-zA-Z0-9_-]*)"
 
129
        },
 
130
        {
 
131
            token: "meta.vendor-prefix.stylus",
 
132
            regex: "-webkit-|-moz\\-|-ms-|-o-"
 
133
        },
 
134
        {
 
135
            token: "keyword.control.stylus",
 
136
            regex: "(?:!important|for|in|return|true|false|null|if|else|unless|return)\\b"
 
137
        },
 
138
        {
 
139
            token: "keyword.operator.stylus",
 
140
            regex: "!|~|\\+|-|(?:\\*)?\\*|\\/|%|(?:\\.)\\.\\.|<|>|(?:=|:|\\?|\\+|-|\\*|\\/|%|<|>)?=|!="
 
141
        },
 
142
        {
 
143
            token: "keyword.operator.stylus",
 
144
            regex: "(?:in|is(?:nt)?|not)\\b"
 
145
        },
 
146
        {
 
147
            token : "string",
 
148
            regex : "'(?=.)",
 
149
            next  : "qstring"
 
150
        }, {
 
151
            token : "string",
 
152
            regex : '"(?=.)',
 
153
            next  : "qqstring"
 
154
        }, 
 
155
        {
 
156
            token : "constant.numeric",
 
157
            regex : CssHighlightRules.numRe
 
158
        }, 
 
159
        {
 
160
            token : "keyword",
 
161
            regex : "(?:ch|cm|deg|em|ex|fr|gd|grad|Hz|in|kHz|mm|ms|pc|pt|px|rad|rem|s|turn|vh|vm|vw|%)\\b"
 
162
        }, 
 
163
        {
 
164
            token : keywordMapper,
 
165
            regex : "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*"
 
166
        }
 
167
    ],
 
168
    "comment" : [
 
169
        {
 
170
            token : "comment", // closing comment
 
171
            regex : ".*?\\*\\/",
 
172
            next : "start"
 
173
        }, {
 
174
            token : "comment", // comment spanning whole line
 
175
            regex : ".+"
 
176
        }
 
177
    ],
 
178
    "qqstring" : [
 
179
        {
 
180
            token : "string",
 
181
            regex : '[^"\\\\]+'
 
182
        }, 
 
183
        {
 
184
            token : "string",
 
185
            regex : "\\\\$",
 
186
            next  : "qqstring"
 
187
        }, 
 
188
        {
 
189
            token : "string",
 
190
            regex : '"|$',
 
191
            next  : "start"
 
192
        }
 
193
    ],
 
194
    "qstring" : [
 
195
        {
 
196
            token : "string",
 
197
            regex : "[^'\\\\]+"
 
198
        }, 
 
199
        {
 
200
            token : "string",
 
201
            regex : "\\\\$",
 
202
            next  : "qstring"
 
203
        }, 
 
204
        {
 
205
            token : "string",
 
206
            regex : "'|$",
 
207
            next  : "start"
 
208
        }
 
209
    ]
 
210
}
 
211
 
 
212
};
 
213
 
 
214
oop.inherits(StylusHighlightRules, TextHighlightRules);
 
215
 
 
216
exports.StylusHighlightRules = StylusHighlightRules;
 
217
});
 
218
 
 
219
define('ace/mode/css_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/lang', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
 
220
 
 
221
 
 
222
var oop = require("../lib/oop");
 
223
var lang = require("../lib/lang");
 
224
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
 
225
var supportType = exports.supportType = "animation-fill-mode|alignment-adjust|alignment-baseline|animation-delay|animation-direction|animation-duration|animation-iteration-count|animation-name|animation-play-state|animation-timing-function|animation|appearance|azimuth|backface-visibility|background-attachment|background-break|background-clip|background-color|background-image|background-origin|background-position|background-repeat|background-size|background|baseline-shift|binding|bleed|bookmark-label|bookmark-level|bookmark-state|bookmark-target|border-bottom|border-bottom-color|border-bottom-left-radius|border-bottom-right-radius|border-bottom-style|border-bottom-width|border-collapse|border-color|border-image|border-image-outset|border-image-repeat|border-image-slice|border-image-source|border-image-width|border-left|border-left-color|border-left-style|border-left-width|border-radius|border-right|border-right-color|border-right-style|border-right-width|border-spacing|border-style|border-top|border-top-color|border-top-left-radius|border-top-right-radius|border-top-style|border-top-width|border-width|border|bottom|box-align|box-decoration-break|box-direction|box-flex-group|box-flex|box-lines|box-ordinal-group|box-orient|box-pack|box-shadow|box-sizing|break-after|break-before|break-inside|caption-side|clear|clip|color-profile|color|column-count|column-fill|column-gap|column-rule|column-rule-color|column-rule-style|column-rule-width|column-span|column-width|columns|content|counter-increment|counter-reset|crop|cue-after|cue-before|cue|cursor|direction|display|dominant-baseline|drop-initial-after-adjust|drop-initial-after-align|drop-initial-before-adjust|drop-initial-before-align|drop-initial-size|drop-initial-value|elevation|empty-cells|fit|fit-position|float-offset|float|font-family|font-size|font-size-adjust|font-stretch|font-style|font-variant|font-weight|font|grid-columns|grid-rows|hanging-punctuation|height|hyphenate-after|hyphenate-before|hyphenate-character|hyphenate-lines|hyphenate-resource|hyphens|icon|image-orientation|image-rendering|image-resolution|inline-box-align|left|letter-spacing|line-height|line-stacking-ruby|line-stacking-shift|line-stacking-strategy|line-stacking|list-style-image|list-style-position|list-style-type|list-style|margin-bottom|margin-left|margin-right|margin-top|margin|mark-after|mark-before|mark|marks|marquee-direction|marquee-play-count|marquee-speed|marquee-style|max-height|max-width|min-height|min-width|move-to|nav-down|nav-index|nav-left|nav-right|nav-up|opacity|orphans|outline-color|outline-offset|outline-style|outline-width|outline|overflow-style|overflow-x|overflow-y|overflow|padding-bottom|padding-left|padding-right|padding-top|padding|page-break-after|page-break-before|page-break-inside|page-policy|page|pause-after|pause-before|pause|perspective-origin|perspective|phonemes|pitch-range|pitch|play-during|position|presentation-level|punctuation-trim|quotes|rendering-intent|resize|rest-after|rest-before|rest|richness|right|rotation-point|rotation|ruby-align|ruby-overhang|ruby-position|ruby-span|size|speak-header|speak-numeral|speak-punctuation|speak|speech-rate|stress|string-set|table-layout|target-name|target-new|target-position|target|text-align-last|text-align|text-decoration|text-emphasis|text-height|text-indent|text-justify|text-outline|text-shadow|text-transform|text-wrap|top|transform-origin|transform-style|transform|transition-delay|transition-duration|transition-property|transition-timing-function|transition|unicode-bidi|vertical-align|visibility|voice-balance|voice-duration|voice-family|voice-pitch-range|voice-pitch|voice-rate|voice-stress|voice-volume|volume|white-space-collapse|white-space|widows|width|word-break|word-spacing|word-wrap|z-index";
 
226
var supportFunction = exports.supportFunction = "rgb|rgba|url|attr|counter|counters";
 
227
var supportConstant = exports.supportConstant = "absolute|after-edge|after|all-scroll|all|alphabetic|always|antialiased|armenian|auto|avoid-column|avoid-page|avoid|balance|baseline|before-edge|before|below|bidi-override|block-line-height|block|bold|bolder|border-box|both|bottom|box|break-all|break-word|capitalize|caps-height|caption|center|central|char|circle|cjk-ideographic|clone|close-quote|col-resize|collapse|column|consider-shifts|contain|content-box|cover|crosshair|cubic-bezier|dashed|decimal-leading-zero|decimal|default|disabled|disc|disregard-shifts|distribute-all-lines|distribute-letter|distribute-space|distribute|dotted|double|e-resize|ease-in|ease-in-out|ease-out|ease|ellipsis|end|exclude-ruby|fill|fixed|georgian|glyphs|grid-height|groove|hand|hanging|hebrew|help|hidden|hiragana-iroha|hiragana|horizontal|icon|ideograph-alpha|ideograph-numeric|ideograph-parenthesis|ideograph-space|ideographic|inactive|include-ruby|inherit|initial|inline-block|inline-box|inline-line-height|inline-table|inline|inset|inside|inter-ideograph|inter-word|invert|italic|justify|katakana-iroha|katakana|keep-all|last|left|lighter|line-edge|line-through|line|linear|list-item|local|loose|lower-alpha|lower-greek|lower-latin|lower-roman|lowercase|lr-tb|ltr|mathematical|max-height|max-size|medium|menu|message-box|middle|move|n-resize|ne-resize|newspaper|no-change|no-close-quote|no-drop|no-open-quote|no-repeat|none|normal|not-allowed|nowrap|nw-resize|oblique|open-quote|outset|outside|overline|padding-box|page|pointer|pre-line|pre-wrap|pre|preserve-3d|progress|relative|repeat-x|repeat-y|repeat|replaced|reset-size|ridge|right|round|row-resize|rtl|s-resize|scroll|se-resize|separate|slice|small-caps|small-caption|solid|space|square|start|static|status-bar|step-end|step-start|steps|stretch|strict|sub|super|sw-resize|table-caption|table-cell|table-column-group|table-column|table-footer-group|table-header-group|table-row-group|table-row|table|tb-rl|text-after-edge|text-before-edge|text-bottom|text-size|text-top|text|thick|thin|transparent|underline|upper-alpha|upper-latin|upper-roman|uppercase|use-script|vertical-ideographic|vertical-text|visible|w-resize|wait|whitespace|z-index|zero";
 
228
var supportConstantColor = exports.supportConstantColor = "aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow";
 
229
var supportConstantFonts = exports.supportConstantFonts = "arial|century|comic|courier|garamond|georgia|helvetica|impact|lucida|symbol|system|tahoma|times|trebuchet|utopia|verdana|webdings|sans-serif|serif|monospace";
 
230
 
 
231
var numRe = exports.numRe = "\\-?(?:(?:[0-9]+)|(?:[0-9]*\\.[0-9]+))";
 
232
var pseudoElements = exports.pseudoElements = "(\\:+)\\b(after|before|first-letter|first-line|moz-selection|selection)\\b";
 
233
var pseudoClasses  = exports.pseudoClasses =  "(:)\\b(active|checked|disabled|empty|enabled|first-child|first-of-type|focus|hover|indeterminate|invalid|last-child|last-of-type|link|not|nth-child|nth-last-child|nth-last-of-type|nth-of-type|only-child|only-of-type|required|root|target|valid|visited)\\b";
 
234
 
 
235
var CssHighlightRules = function() {
 
236
 
 
237
    var keywordMapper = this.createKeywordMapper({
 
238
        "support.function": supportFunction,
 
239
        "support.constant": supportConstant,
 
240
        "support.type": supportType,
 
241
        "support.constant.color": supportConstantColor,
 
242
        "support.constant.fonts": supportConstantFonts
 
243
    }, "text", true);
 
244
 
 
245
    var base_ruleset = [
 
246
        {
 
247
            token : "comment", // multi line comment
 
248
            regex : "\\/\\*",
 
249
            next : "ruleset_comment"
 
250
        }, {
 
251
            token : "string", // single line
 
252
            regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
 
253
        }, {
 
254
            token : "string", // single line
 
255
            regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
 
256
        }, {
 
257
            token : ["constant.numeric", "keyword"],
 
258
            regex : "(" + numRe + ")(ch|cm|deg|em|ex|fr|gd|grad|Hz|in|kHz|mm|ms|pc|pt|px|rad|rem|s|turn|vh|vm|vw|%)"
 
259
        }, {
 
260
            token : "constant.numeric",
 
261
            regex : numRe
 
262
        }, {
 
263
            token : "constant.numeric",  // hex6 color
 
264
            regex : "#[a-f0-9]{6}"
 
265
        }, {
 
266
            token : "constant.numeric", // hex3 color
 
267
            regex : "#[a-f0-9]{3}"
 
268
        }, {
 
269
            token : ["punctuation", "entity.other.attribute-name.pseudo-element.css"],
 
270
            regex : pseudoElements
 
271
        }, {
 
272
            token : ["punctuation", "entity.other.attribute-name.pseudo-class.css"],
 
273
            regex : pseudoClasses
 
274
        }, {
 
275
            token : ["support.function", "string", "support.function"],
 
276
            regex : "(url\\()(.*)(\\))"
 
277
        }, {
 
278
            token : keywordMapper,
 
279
            regex : "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*"
 
280
        }, {
 
281
            caseInsensitive: true
 
282
        }
 
283
      ];
 
284
 
 
285
    var ruleset = lang.copyArray(base_ruleset);
 
286
    ruleset.unshift({
 
287
        token : "paren.rparen",
 
288
        regex : "\\}",
 
289
        next:   "start"
 
290
    });
 
291
 
 
292
    var media_ruleset = lang.copyArray( base_ruleset );
 
293
    media_ruleset.unshift({
 
294
        token : "paren.rparen",
 
295
        regex : "\\}",
 
296
        next:   "media"
 
297
    });
 
298
 
 
299
    var base_comment = [{
 
300
          token : "comment", // comment spanning whole line
 
301
          regex : ".+"
 
302
    }];
 
303
 
 
304
    var comment = lang.copyArray(base_comment);
 
305
    comment.unshift({
 
306
          token : "comment", // closing comment
 
307
          regex : ".*?\\*\\/",
 
308
          next : "start"
 
309
    });
 
310
 
 
311
    var media_comment = lang.copyArray(base_comment);
 
312
    media_comment.unshift({
 
313
          token : "comment", // closing comment
 
314
          regex : ".*?\\*\\/",
 
315
          next : "media"
 
316
    });
 
317
 
 
318
    var ruleset_comment = lang.copyArray(base_comment);
 
319
    ruleset_comment.unshift({
 
320
          token : "comment", // closing comment
 
321
          regex : ".*?\\*\\/",
 
322
          next : "ruleset"
 
323
    });
 
324
 
 
325
    this.$rules = {
 
326
        "start" : [{
 
327
            token : "comment", // multi line comment
 
328
            regex : "\\/\\*",
 
329
            next : "comment"
 
330
        }, {
 
331
            token: "paren.lparen",
 
332
            regex: "\\{",
 
333
            next:  "ruleset"
 
334
        }, {
 
335
            token: "string",
 
336
            regex: "@.*?{",
 
337
            next:  "media"
 
338
        },{
 
339
            token: "keyword",
 
340
            regex: "#[a-z0-9-_]+"
 
341
        },{
 
342
            token: "variable",
 
343
            regex: "\\.[a-z0-9-_]+"
 
344
        },{
 
345
            token: "string",
 
346
            regex: ":[a-z0-9-_]+"
 
347
        },{
 
348
            token: "constant",
 
349
            regex: "[a-z0-9-_]+"
 
350
        },{
 
351
            caseInsensitive: true
 
352
        }],
 
353
 
 
354
        "media" : [ {
 
355
            token : "comment", // multi line comment
 
356
            regex : "\\/\\*",
 
357
            next : "media_comment"
 
358
        }, {
 
359
            token: "paren.lparen",
 
360
            regex: "\\{",
 
361
            next:  "media_ruleset"
 
362
        },{
 
363
            token: "string",
 
364
            regex: "\\}",
 
365
            next:  "start"
 
366
        },{
 
367
            token: "keyword",
 
368
            regex: "#[a-z0-9-_]+"
 
369
        },{
 
370
            token: "variable",
 
371
            regex: "\\.[a-z0-9-_]+"
 
372
        },{
 
373
            token: "string",
 
374
            regex: ":[a-z0-9-_]+"
 
375
        },{
 
376
            token: "constant",
 
377
            regex: "[a-z0-9-_]+"
 
378
        },{
 
379
            caseInsensitive: true
 
380
        }],
 
381
 
 
382
        "comment" : comment,
 
383
 
 
384
        "ruleset" : ruleset,
 
385
        "ruleset_comment" : ruleset_comment,
 
386
 
 
387
        "media_ruleset" : media_ruleset,
 
388
        "media_comment" : media_comment
 
389
    };
 
390
};
 
391
 
 
392
oop.inherits(CssHighlightRules, TextHighlightRules);
 
393
 
 
394
exports.CssHighlightRules = CssHighlightRules;
 
395
 
 
396
});
 
397
 
 
398
define('ace/mode/folding/coffee', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/folding/fold_mode', 'ace/range'], function(require, exports, module) {
 
399
 
 
400
 
 
401
var oop = require("../../lib/oop");
 
402
var BaseFoldMode = require("./fold_mode").FoldMode;
 
403
var Range = require("../../range").Range;
 
404
 
 
405
var FoldMode = exports.FoldMode = function() {};
 
406
oop.inherits(FoldMode, BaseFoldMode);
 
407
 
 
408
(function() {
 
409
 
 
410
    this.getFoldWidgetRange = function(session, foldStyle, row) {
 
411
        var range = this.indentationBlock(session, row);
 
412
        if (range)
 
413
            return range;
 
414
 
 
415
        var re = /\S/;
 
416
        var line = session.getLine(row);
 
417
        var startLevel = line.search(re);
 
418
        if (startLevel == -1 || line[startLevel] != "#")
 
419
            return;
 
420
 
 
421
        var startColumn = line.length;
 
422
        var maxRow = session.getLength();
 
423
        var startRow = row;
 
424
        var endRow = row;
 
425
 
 
426
        while (++row < maxRow) {
 
427
            line = session.getLine(row);
 
428
            var level = line.search(re);
 
429
 
 
430
            if (level == -1)
 
431
                continue;
 
432
 
 
433
            if (line[level] != "#")
 
434
                break;
 
435
 
 
436
            endRow = row;
 
437
        }
 
438
 
 
439
        if (endRow > startRow) {
 
440
            var endColumn = session.getLine(endRow).length;
 
441
            return new Range(startRow, startColumn, endRow, endColumn);
 
442
        }
 
443
    };
 
444
    this.getFoldWidget = function(session, foldStyle, row) {
 
445
        var line = session.getLine(row);
 
446
        var indent = line.search(/\S/);
 
447
        var next = session.getLine(row + 1);
 
448
        var prev = session.getLine(row - 1);
 
449
        var prevIndent = prev.search(/\S/);
 
450
        var nextIndent = next.search(/\S/);
 
451
 
 
452
        if (indent == -1) {
 
453
            session.foldWidgets[row - 1] = prevIndent!= -1 && prevIndent < nextIndent ? "start" : "";
 
454
            return "";
 
455
        }
 
456
        if (prevIndent == -1) {
 
457
            if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
 
458
                session.foldWidgets[row - 1] = "";
 
459
                session.foldWidgets[row + 1] = "";
 
460
                return "start";
 
461
            }
 
462
        } else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
 
463
            if (session.getLine(row - 2).search(/\S/) == -1) {
 
464
                session.foldWidgets[row - 1] = "start";
 
465
                session.foldWidgets[row + 1] = "";
 
466
                return "";
 
467
            }
 
468
        }
 
469
 
 
470
        if (prevIndent!= -1 && prevIndent < indent)
 
471
            session.foldWidgets[row - 1] = "start";
 
472
        else
 
473
            session.foldWidgets[row - 1] = "";
 
474
 
 
475
        if (indent < nextIndent)
 
476
            return "start";
 
477
        else
 
478
            return "";
 
479
    };
 
480
 
 
481
}).call(FoldMode.prototype);
 
482
 
 
483
});