##// END OF EJS Templates
codemirror: added simple mode plugin required for certain code modes.
marcink -
r2127:d6d01315 default
parent child Browse files
Show More
@@ -0,0 +1,216 b''
1 // CodeMirror, copyright (c) by Marijn Haverbeke and others
2 // Distributed under an MIT license: http://codemirror.net/LICENSE
3
4 (function(mod) {
5 if (typeof exports == "object" && typeof module == "object") // CommonJS
6 mod(require("../../lib/codemirror"));
7 else if (typeof define == "function" && define.amd) // AMD
8 define(["../../lib/codemirror"], mod);
9 else // Plain browser env
10 mod(CodeMirror);
11 })(function(CodeMirror) {
12 "use strict";
13
14 CodeMirror.defineSimpleMode = function(name, states) {
15 CodeMirror.defineMode(name, function(config) {
16 return CodeMirror.simpleMode(config, states);
17 });
18 };
19
20 CodeMirror.simpleMode = function(config, states) {
21 ensureState(states, "start");
22 var states_ = {}, meta = states.meta || {}, hasIndentation = false;
23 for (var state in states) if (state != meta && states.hasOwnProperty(state)) {
24 var list = states_[state] = [], orig = states[state];
25 for (var i = 0; i < orig.length; i++) {
26 var data = orig[i];
27 list.push(new Rule(data, states));
28 if (data.indent || data.dedent) hasIndentation = true;
29 }
30 }
31 var mode = {
32 startState: function() {
33 return {state: "start", pending: null,
34 local: null, localState: null,
35 indent: hasIndentation ? [] : null};
36 },
37 copyState: function(state) {
38 var s = {state: state.state, pending: state.pending,
39 local: state.local, localState: null,
40 indent: state.indent && state.indent.slice(0)};
41 if (state.localState)
42 s.localState = CodeMirror.copyState(state.local.mode, state.localState);
43 if (state.stack)
44 s.stack = state.stack.slice(0);
45 for (var pers = state.persistentStates; pers; pers = pers.next)
46 s.persistentStates = {mode: pers.mode,
47 spec: pers.spec,
48 state: pers.state == state.localState ? s.localState : CodeMirror.copyState(pers.mode, pers.state),
49 next: s.persistentStates};
50 return s;
51 },
52 token: tokenFunction(states_, config),
53 innerMode: function(state) { return state.local && {mode: state.local.mode, state: state.localState}; },
54 indent: indentFunction(states_, meta)
55 };
56 if (meta) for (var prop in meta) if (meta.hasOwnProperty(prop))
57 mode[prop] = meta[prop];
58 return mode;
59 };
60
61 function ensureState(states, name) {
62 if (!states.hasOwnProperty(name))
63 throw new Error("Undefined state " + name + " in simple mode");
64 }
65
66 function toRegex(val, caret) {
67 if (!val) return /(?:)/;
68 var flags = "";
69 if (val instanceof RegExp) {
70 if (val.ignoreCase) flags = "i";
71 val = val.source;
72 } else {
73 val = String(val);
74 }
75 return new RegExp((caret === false ? "" : "^") + "(?:" + val + ")", flags);
76 }
77
78 function asToken(val) {
79 if (!val) return null;
80 if (val.apply) return val
81 if (typeof val == "string") return val.replace(/\./g, " ");
82 var result = [];
83 for (var i = 0; i < val.length; i++)
84 result.push(val[i] && val[i].replace(/\./g, " "));
85 return result;
86 }
87
88 function Rule(data, states) {
89 if (data.next || data.push) ensureState(states, data.next || data.push);
90 this.regex = toRegex(data.regex);
91 this.token = asToken(data.token);
92 this.data = data;
93 }
94
95 function tokenFunction(states, config) {
96 return function(stream, state) {
97 if (state.pending) {
98 var pend = state.pending.shift();
99 if (state.pending.length == 0) state.pending = null;
100 stream.pos += pend.text.length;
101 return pend.token;
102 }
103
104 if (state.local) {
105 if (state.local.end && stream.match(state.local.end)) {
106 var tok = state.local.endToken || null;
107 state.local = state.localState = null;
108 return tok;
109 } else {
110 var tok = state.local.mode.token(stream, state.localState), m;
111 if (state.local.endScan && (m = state.local.endScan.exec(stream.current())))
112 stream.pos = stream.start + m.index;
113 return tok;
114 }
115 }
116
117 var curState = states[state.state];
118 for (var i = 0; i < curState.length; i++) {
119 var rule = curState[i];
120 var matches = (!rule.data.sol || stream.sol()) && stream.match(rule.regex);
121 if (matches) {
122 if (rule.data.next) {
123 state.state = rule.data.next;
124 } else if (rule.data.push) {
125 (state.stack || (state.stack = [])).push(state.state);
126 state.state = rule.data.push;
127 } else if (rule.data.pop && state.stack && state.stack.length) {
128 state.state = state.stack.pop();
129 }
130
131 if (rule.data.mode)
132 enterLocalMode(config, state, rule.data.mode, rule.token);
133 if (rule.data.indent)
134 state.indent.push(stream.indentation() + config.indentUnit);
135 if (rule.data.dedent)
136 state.indent.pop();
137 var token = rule.token
138 if (token && token.apply) token = token(matches)
139 if (matches.length > 2 && rule.token && typeof rule.token != "string") {
140 state.pending = [];
141 for (var j = 2; j < matches.length; j++)
142 if (matches[j])
143 state.pending.push({text: matches[j], token: rule.token[j - 1]});
144 stream.backUp(matches[0].length - (matches[1] ? matches[1].length : 0));
145 return token[0];
146 } else if (token && token.join) {
147 return token[0];
148 } else {
149 return token;
150 }
151 }
152 }
153 stream.next();
154 return null;
155 };
156 }
157
158 function cmp(a, b) {
159 if (a === b) return true;
160 if (!a || typeof a != "object" || !b || typeof b != "object") return false;
161 var props = 0;
162 for (var prop in a) if (a.hasOwnProperty(prop)) {
163 if (!b.hasOwnProperty(prop) || !cmp(a[prop], b[prop])) return false;
164 props++;
165 }
166 for (var prop in b) if (b.hasOwnProperty(prop)) props--;
167 return props == 0;
168 }
169
170 function enterLocalMode(config, state, spec, token) {
171 var pers;
172 if (spec.persistent) for (var p = state.persistentStates; p && !pers; p = p.next)
173 if (spec.spec ? cmp(spec.spec, p.spec) : spec.mode == p.mode) pers = p;
174 var mode = pers ? pers.mode : spec.mode || CodeMirror.getMode(config, spec.spec);
175 var lState = pers ? pers.state : CodeMirror.startState(mode);
176 if (spec.persistent && !pers)
177 state.persistentStates = {mode: mode, spec: spec.spec, state: lState, next: state.persistentStates};
178
179 state.localState = lState;
180 state.local = {mode: mode,
181 end: spec.end && toRegex(spec.end),
182 endScan: spec.end && spec.forceEnd !== false && toRegex(spec.end, false),
183 endToken: token && token.join ? token[token.length - 1] : token};
184 }
185
186 function indexOf(val, arr) {
187 for (var i = 0; i < arr.length; i++) if (arr[i] === val) return true;
188 }
189
190 function indentFunction(states, meta) {
191 return function(state, textAfter, line) {
192 if (state.local && state.local.mode.indent)
193 return state.local.mode.indent(state.localState, textAfter, line);
194 if (state.indent == null || state.local || meta.dontIndentStates && indexOf(state.state, meta.dontIndentStates) > -1)
195 return CodeMirror.Pass;
196
197 var pos = state.indent.length - 1, rules = states[state.state];
198 scan: for (;;) {
199 for (var i = 0; i < rules.length; i++) {
200 var rule = rules[i];
201 if (rule.data.dedent && rule.data.dedentIfLineStart !== false) {
202 var m = rule.regex.exec(textAfter);
203 if (m && m[0]) {
204 pos--;
205 if (rule.next || rule.push) rules = states[rule.next || rule.push];
206 textAfter = textAfter.slice(m[0].length);
207 continue scan;
208 }
209 }
210 }
211 break;
212 }
213 return pos < 0 ? 0 : state.indent[pos];
214 };
215 }
216 }); No newline at end of file
@@ -1,193 +1,194 b''
1 {
1 {
2 "dirs": {
2 "dirs": {
3 "css": {
3 "css": {
4 "src":"rhodecode/public/css",
4 "src":"rhodecode/public/css",
5 "dest":"rhodecode/public/css"
5 "dest":"rhodecode/public/css"
6 },
6 },
7 "js": {
7 "js": {
8 "src": "rhodecode/public/js/src",
8 "src": "rhodecode/public/js/src",
9 "src_rc": "rhodecode/public/js/rhodecode",
9 "src_rc": "rhodecode/public/js/rhodecode",
10 "dest": "rhodecode/public/js",
10 "dest": "rhodecode/public/js",
11 "bower": "bower_components",
11 "bower": "bower_components",
12 "node_modules": "node_modules"
12 "node_modules": "node_modules"
13 }
13 }
14 },
14 },
15 "copy": {
15 "copy": {
16 "main": {
16 "main": {
17 "expand": true,
17 "expand": true,
18 "cwd": "bower_components",
18 "cwd": "bower_components",
19 "src": "webcomponentsjs/webcomponents-lite.js",
19 "src": "webcomponentsjs/webcomponents-lite.js",
20 "dest": "<%= dirs.js.dest %>/vendors"
20 "dest": "<%= dirs.js.dest %>/vendors"
21 }
21 }
22 },
22 },
23 "concat": {
23 "concat": {
24 "polymercss": {
24 "polymercss": {
25 "src": [
25 "src": [
26 "<%= dirs.js.src %>/components/root-styles-prefix.html",
26 "<%= dirs.js.src %>/components/root-styles-prefix.html",
27 "<%= dirs.css.src %>/style-polymer.css",
27 "<%= dirs.css.src %>/style-polymer.css",
28 "<%= dirs.js.src %>/components/root-styles-suffix.html"
28 "<%= dirs.js.src %>/components/root-styles-suffix.html"
29 ],
29 ],
30 "dest": "<%= dirs.js.dest %>/src/components/root-styles.gen.html",
30 "dest": "<%= dirs.js.dest %>/src/components/root-styles.gen.html",
31 "nonull": true
31 "nonull": true
32 },
32 },
33 "dist": {
33 "dist": {
34 "src": [
34 "src": [
35 "<%= dirs.js.node_modules %>/jquery/dist/jquery.min.js",
35 "<%= dirs.js.node_modules %>/jquery/dist/jquery.min.js",
36 "<%= dirs.js.node_modules %>/mousetrap/mousetrap.min.js",
36 "<%= dirs.js.node_modules %>/mousetrap/mousetrap.min.js",
37 "<%= dirs.js.node_modules %>/moment/min/moment.min.js",
37 "<%= dirs.js.node_modules %>/moment/min/moment.min.js",
38 "<%= dirs.js.node_modules %>/clipboard/dist/clipboard.min.js",
38 "<%= dirs.js.node_modules %>/clipboard/dist/clipboard.min.js",
39 "<%= dirs.js.node_modules %>/favico.js/favico-0.3.10.min.js",
39 "<%= dirs.js.node_modules %>/favico.js/favico-0.3.10.min.js",
40 "<%= dirs.js.node_modules %>/appenlight-client/appenlight-client.min.js",
40 "<%= dirs.js.node_modules %>/appenlight-client/appenlight-client.min.js",
41 "<%= dirs.js.src %>/logging.js",
41 "<%= dirs.js.src %>/logging.js",
42 "<%= dirs.js.src %>/bootstrap.js",
42 "<%= dirs.js.src %>/bootstrap.js",
43 "<%= dirs.js.src %>/i18n_utils.js",
43 "<%= dirs.js.src %>/i18n_utils.js",
44 "<%= dirs.js.src %>/deform.js",
44 "<%= dirs.js.src %>/deform.js",
45 "<%= dirs.js.src %>/plugins/jquery.pjax.js",
45 "<%= dirs.js.src %>/plugins/jquery.pjax.js",
46 "<%= dirs.js.src %>/plugins/jquery.dataTables.js",
46 "<%= dirs.js.src %>/plugins/jquery.dataTables.js",
47 "<%= dirs.js.src %>/plugins/flavoured_checkbox.js",
47 "<%= dirs.js.src %>/plugins/flavoured_checkbox.js",
48 "<%= dirs.js.src %>/plugins/jquery.auto-grow-input.js",
48 "<%= dirs.js.src %>/plugins/jquery.auto-grow-input.js",
49 "<%= dirs.js.src %>/plugins/jquery.autocomplete.js",
49 "<%= dirs.js.src %>/plugins/jquery.autocomplete.js",
50 "<%= dirs.js.src %>/plugins/jquery.debounce.js",
50 "<%= dirs.js.src %>/plugins/jquery.debounce.js",
51 "<%= dirs.js.src %>/plugins/jquery.mark.js",
51 "<%= dirs.js.src %>/plugins/jquery.mark.js",
52 "<%= dirs.js.src %>/plugins/jquery.timeago.js",
52 "<%= dirs.js.src %>/plugins/jquery.timeago.js",
53 "<%= dirs.js.src %>/plugins/jquery.timeago-extension.js",
53 "<%= dirs.js.src %>/plugins/jquery.timeago-extension.js",
54 "<%= dirs.js.src %>/select2/select2.js",
54 "<%= dirs.js.src %>/select2/select2.js",
55 "<%= dirs.js.src %>/codemirror/codemirror.js",
55 "<%= dirs.js.src %>/codemirror/codemirror.js",
56 "<%= dirs.js.src %>/codemirror/codemirror_loadmode.js",
56 "<%= dirs.js.src %>/codemirror/codemirror_loadmode.js",
57 "<%= dirs.js.src %>/codemirror/codemirror_hint.js",
57 "<%= dirs.js.src %>/codemirror/codemirror_hint.js",
58 "<%= dirs.js.src %>/codemirror/codemirror_overlay.js",
58 "<%= dirs.js.src %>/codemirror/codemirror_overlay.js",
59 "<%= dirs.js.src %>/codemirror/codemirror_placeholder.js",
59 "<%= dirs.js.src %>/codemirror/codemirror_placeholder.js",
60 "<%= dirs.js.src %>/codemirror/codemirror_simplemode.js",
60 "<%= dirs.js.dest %>/mode/meta.js",
61 "<%= dirs.js.dest %>/mode/meta.js",
61 "<%= dirs.js.dest %>/mode/meta_ext.js",
62 "<%= dirs.js.dest %>/mode/meta_ext.js",
62 "<%= dirs.js.src_rc %>/i18n/select2/translations.js",
63 "<%= dirs.js.src_rc %>/i18n/select2/translations.js",
63 "<%= dirs.js.src %>/rhodecode/utils/array.js",
64 "<%= dirs.js.src %>/rhodecode/utils/array.js",
64 "<%= dirs.js.src %>/rhodecode/utils/string.js",
65 "<%= dirs.js.src %>/rhodecode/utils/string.js",
65 "<%= dirs.js.src %>/rhodecode/utils/pyroutes.js",
66 "<%= dirs.js.src %>/rhodecode/utils/pyroutes.js",
66 "<%= dirs.js.src %>/rhodecode/utils/ajax.js",
67 "<%= dirs.js.src %>/rhodecode/utils/ajax.js",
67 "<%= dirs.js.src %>/rhodecode/utils/autocomplete.js",
68 "<%= dirs.js.src %>/rhodecode/utils/autocomplete.js",
68 "<%= dirs.js.src %>/rhodecode/utils/colorgenerator.js",
69 "<%= dirs.js.src %>/rhodecode/utils/colorgenerator.js",
69 "<%= dirs.js.src %>/rhodecode/utils/ie.js",
70 "<%= dirs.js.src %>/rhodecode/utils/ie.js",
70 "<%= dirs.js.src %>/rhodecode/utils/os.js",
71 "<%= dirs.js.src %>/rhodecode/utils/os.js",
71 "<%= dirs.js.src %>/rhodecode/utils/topics.js",
72 "<%= dirs.js.src %>/rhodecode/utils/topics.js",
72 "<%= dirs.js.src %>/rhodecode/init.js",
73 "<%= dirs.js.src %>/rhodecode/init.js",
73 "<%= dirs.js.src %>/rhodecode/changelog.js",
74 "<%= dirs.js.src %>/rhodecode/changelog.js",
74 "<%= dirs.js.src %>/rhodecode/codemirror.js",
75 "<%= dirs.js.src %>/rhodecode/codemirror.js",
75 "<%= dirs.js.src %>/rhodecode/comments.js",
76 "<%= dirs.js.src %>/rhodecode/comments.js",
76 "<%= dirs.js.src %>/rhodecode/constants.js",
77 "<%= dirs.js.src %>/rhodecode/constants.js",
77 "<%= dirs.js.src %>/rhodecode/files.js",
78 "<%= dirs.js.src %>/rhodecode/files.js",
78 "<%= dirs.js.src %>/rhodecode/followers.js",
79 "<%= dirs.js.src %>/rhodecode/followers.js",
79 "<%= dirs.js.src %>/rhodecode/menus.js",
80 "<%= dirs.js.src %>/rhodecode/menus.js",
80 "<%= dirs.js.src %>/rhodecode/notifications.js",
81 "<%= dirs.js.src %>/rhodecode/notifications.js",
81 "<%= dirs.js.src %>/rhodecode/permissions.js",
82 "<%= dirs.js.src %>/rhodecode/permissions.js",
82 "<%= dirs.js.src %>/rhodecode/pjax.js",
83 "<%= dirs.js.src %>/rhodecode/pjax.js",
83 "<%= dirs.js.src %>/rhodecode/pullrequests.js",
84 "<%= dirs.js.src %>/rhodecode/pullrequests.js",
84 "<%= dirs.js.src %>/rhodecode/settings.js",
85 "<%= dirs.js.src %>/rhodecode/settings.js",
85 "<%= dirs.js.src %>/rhodecode/select2_widgets.js",
86 "<%= dirs.js.src %>/rhodecode/select2_widgets.js",
86 "<%= dirs.js.src %>/rhodecode/tooltips.js",
87 "<%= dirs.js.src %>/rhodecode/tooltips.js",
87 "<%= dirs.js.src %>/rhodecode/users.js",
88 "<%= dirs.js.src %>/rhodecode/users.js",
88 "<%= dirs.js.src %>/rhodecode/appenlight.js",
89 "<%= dirs.js.src %>/rhodecode/appenlight.js",
89 "<%= dirs.js.src %>/rhodecode.js"
90 "<%= dirs.js.src %>/rhodecode.js"
90 ],
91 ],
91 "dest": "<%= dirs.js.dest %>/scripts.js",
92 "dest": "<%= dirs.js.dest %>/scripts.js",
92 "nonull": true
93 "nonull": true
93 }
94 }
94 },
95 },
95 "crisper": {
96 "crisper": {
96 "dist": {
97 "dist": {
97 "options": {
98 "options": {
98 "cleanup": false,
99 "cleanup": false,
99 "onlySplit": true
100 "onlySplit": true
100 },
101 },
101 "src": "<%= dirs.js.dest %>/rhodecode-components.html",
102 "src": "<%= dirs.js.dest %>/rhodecode-components.html",
102 "dest": "<%= dirs.js.dest %>/rhodecode-components.js"
103 "dest": "<%= dirs.js.dest %>/rhodecode-components.js"
103 }
104 }
104 },
105 },
105 "less": {
106 "less": {
106 "development": {
107 "development": {
107 "options": {
108 "options": {
108 "compress": false,
109 "compress": false,
109 "yuicompress": false,
110 "yuicompress": false,
110 "optimization": 0
111 "optimization": 0
111 },
112 },
112 "files": {
113 "files": {
113 "<%= dirs.css.dest %>/style.css": "<%= dirs.css.src %>/main.less",
114 "<%= dirs.css.dest %>/style.css": "<%= dirs.css.src %>/main.less",
114 "<%= dirs.css.dest %>/style-polymer.css": "<%= dirs.css.src %>/polymer.less"
115 "<%= dirs.css.dest %>/style-polymer.css": "<%= dirs.css.src %>/polymer.less"
115 }
116 }
116 },
117 },
117 "production": {
118 "production": {
118 "options": {
119 "options": {
119 "compress": true,
120 "compress": true,
120 "yuicompress": true,
121 "yuicompress": true,
121 "optimization": 2
122 "optimization": 2
122 },
123 },
123 "files": {
124 "files": {
124 "<%= dirs.css.dest %>/style.css": "<%= dirs.css.src %>/main.less",
125 "<%= dirs.css.dest %>/style.css": "<%= dirs.css.src %>/main.less",
125 "<%= dirs.css.dest %>/style-polymer.css": "<%= dirs.css.src %>/polymer.less"
126 "<%= dirs.css.dest %>/style-polymer.css": "<%= dirs.css.src %>/polymer.less"
126 }
127 }
127 },
128 },
128 "components": {
129 "components": {
129 "files": [
130 "files": [
130 {
131 {
131 "cwd": "<%= dirs.js.src %>/components/",
132 "cwd": "<%= dirs.js.src %>/components/",
132 "dest": "<%= dirs.js.src %>/components/",
133 "dest": "<%= dirs.js.src %>/components/",
133 "src": [
134 "src": [
134 "**/*.less"
135 "**/*.less"
135 ],
136 ],
136 "expand": true,
137 "expand": true,
137 "ext": ".css"
138 "ext": ".css"
138 }
139 }
139 ]
140 ]
140 }
141 }
141 },
142 },
142 "watch": {
143 "watch": {
143 "less": {
144 "less": {
144 "files": [
145 "files": [
145 "<%= dirs.css.src %>/**/*.less",
146 "<%= dirs.css.src %>/**/*.less",
146 "<%= dirs.js.src %>/components/**/*.less"
147 "<%= dirs.js.src %>/components/**/*.less"
147 ],
148 ],
148 "tasks": [
149 "tasks": [
149 "less:development",
150 "less:development",
150 "less:components",
151 "less:components",
151 "concat:polymercss",
152 "concat:polymercss",
152 "vulcanize",
153 "vulcanize",
153 "crisper",
154 "crisper",
154 "concat:dist"
155 "concat:dist"
155 ]
156 ]
156 },
157 },
157 "js": {
158 "js": {
158 "files": [
159 "files": [
159 "!<%= dirs.js.src %>/components/root-styles.gen.html",
160 "!<%= dirs.js.src %>/components/root-styles.gen.html",
160 "<%= dirs.js.src %>/**/*.js",
161 "<%= dirs.js.src %>/**/*.js",
161 "<%= dirs.js.src %>/components/**/*.html"
162 "<%= dirs.js.src %>/components/**/*.html"
162 ],
163 ],
163 "tasks": [
164 "tasks": [
164 "less:components",
165 "less:components",
165 "concat:polymercss",
166 "concat:polymercss",
166 "vulcanize",
167 "vulcanize",
167 "crisper",
168 "crisper",
168 "concat:dist"
169 "concat:dist"
169 ]
170 ]
170 }
171 }
171 },
172 },
172 "jshint": {
173 "jshint": {
173 "rhodecode": {
174 "rhodecode": {
174 "src": "<%= dirs.js.src %>/rhodecode/**/*.js",
175 "src": "<%= dirs.js.src %>/rhodecode/**/*.js",
175 "options": {
176 "options": {
176 "jshintrc": ".jshintrc"
177 "jshintrc": ".jshintrc"
177 }
178 }
178 }
179 }
179 },
180 },
180 "vulcanize": {
181 "vulcanize": {
181 "default": {
182 "default": {
182 "options": {
183 "options": {
183 "abspath": "",
184 "abspath": "",
184 "inlineScripts": true,
185 "inlineScripts": true,
185 "inlineCss": true,
186 "inlineCss": true,
186 "stripComments": true
187 "stripComments": true
187 },
188 },
188 "files": {
189 "files": {
189 "<%= dirs.js.dest %>/rhodecode-components.html": "<%= dirs.js.src %>/components/shared-components.html"
190 "<%= dirs.js.dest %>/rhodecode-components.html": "<%= dirs.js.src %>/components/shared-components.html"
190 }
191 }
191 }
192 }
192 }
193 }
193 }
194 }
General Comments 0
You need to be logged in to leave comments. Login now