codemirror-rails 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,30 +2,50 @@
2
2
  * Author: Koh Zi Han, based on implementation by Koh Zi Chun
3
3
  */
4
4
  CodeMirror.defineMode("scheme", function (config, mode) {
5
- var numRegex = /[0-9]/;
6
5
  var BUILTIN = "builtin", COMMENT = "comment", STRING = "string",
7
- ATOM = "atom", NUMBER = "number", BRACKET = "bracket";
6
+ ATOM = "atom", NUMBER = "number", BRACKET = "bracket", KEYWORD="keyword";
8
7
  var INDENT_WORD_SKIP = 2, KEYWORDS_SKIP = 1;
9
-
8
+
10
9
  function makeKeywords(str) {
11
10
  var obj = {}, words = str.split(" ");
12
11
  for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
13
12
  return obj;
14
13
  }
14
+
15
15
  var keywords = makeKeywords("λ case-lambda call/cc class define-class exit-handler field import inherit init-field interface let*-values let-values let/ec mixin opt-lambda override protect provide public rename require require-for-syntax syntax syntax-case syntax-error unit/sig unless when with-syntax and begin call-with-current-continuation call-with-input-file call-with-output-file case cond define define-syntax delay do dynamic-wind else for-each if lambda let let* let-syntax letrec letrec-syntax map or syntax-rules abs acos angle append apply asin assoc assq assv atan boolean? caar cadr call-with-input-file call-with-output-file call-with-values car cdddar cddddr cdr ceiling char->integer char-alphabetic? char-ci<=? char-ci<? char-ci=? char-ci>=? char-ci>? char-downcase char-lower-case? char-numeric? char-ready? char-upcase char-upper-case? char-whitespace? char<=? char<? char=? char>=? char>? char? close-input-port close-output-port complex? cons cos current-input-port current-output-port denominator display eof-object? eq? equal? eqv? eval even? exact->inexact exact? exp expt #f floor force gcd imag-part inexact->exact inexact? input-port? integer->char integer? interaction-environment lcm length list list->string list->vector list-ref list-tail list? load log magnitude make-polar make-rectangular make-string make-vector max member memq memv min modulo negative? newline not null-environment null? number->string number? numerator odd? open-input-file open-output-file output-port? pair? peek-char port? positive? procedure? quasiquote quote quotient rational? rationalize read read-char real-part real? remainder reverse round scheme-report-environment set! set-car! set-cdr! sin sqrt string string->list string->number string->symbol string-append string-ci<=? string-ci<? string-ci=? string-ci>=? string-ci>? string-copy string-fill! string-length string-ref string-set! string<=? string<? string=? string>=? string>? string? substring symbol->string symbol? #t tan transcript-off transcript-on truncate values vector vector->list vector-fill! vector-length vector-ref vector-set! with-input-from-file with-output-to-file write write-char zero?");
16
- var indentKeys = makeKeywords("define let letrec let* lambda begin");
16
+ var indentKeys = makeKeywords("define let letrec let* lambda");
17
+
17
18
 
18
19
  function stateStack(indent, type, prev) { // represents a state stack object
19
20
  this.indent = indent;
20
21
  this.type = type;
21
22
  this.prev = prev;
22
23
  }
24
+
23
25
  function pushStack(state, indent, type) {
24
26
  state.indentStack = new stateStack(indent, type, state.indentStack);
25
27
  }
28
+
26
29
  function popStack(state) {
27
30
  state.indentStack = state.indentStack.prev;
28
31
  }
32
+
33
+ /**
34
+ * Scheme numbers are complicated unfortunately.
35
+ * Checks if we're looking at a number, which might be possibly a fraction.
36
+ * Also checks that it is not part of a longer identifier. Returns true/false accordingly.
37
+ */
38
+ function isNumber(ch, stream){
39
+ if(/[0-9]/.exec(ch) != null){
40
+ stream.eatWhile(/[0-9]/);
41
+ stream.eat(/\//);
42
+ stream.eatWhile(/[0-9]/);
43
+ if (stream.eol() || !(/[a-zA-Z\-\_\/]/.exec(stream.peek()))) return true;
44
+ stream.backUp(stream.current().length - 1); // undo all the eating
45
+ }
46
+ return false;
47
+ }
48
+
29
49
  return {
30
50
  startState: function () {
31
51
  return {
@@ -35,23 +55,25 @@ CodeMirror.defineMode("scheme", function (config, mode) {
35
55
  sExprComment: false
36
56
  };
37
57
  },
58
+
38
59
  token: function (stream, state) {
39
60
  if (state.indentStack == null && stream.sol()) {
40
61
  // update indentation, but only if indentStack is empty
41
62
  state.indentation = stream.indentation();
42
63
  }
64
+
43
65
  // skip spaces
44
66
  if (stream.eatSpace()) {
45
67
  return null;
46
68
  }
47
69
  var returnType = null;
48
-
70
+
49
71
  switch(state.mode){
50
72
  case "string": // multi-line string parsing mode
51
73
  var next, escaped = false;
52
74
  while ((next = stream.next()) != null) {
53
75
  if (next == "\"" && !escaped) {
54
-
76
+
55
77
  state.mode = false;
56
78
  break;
57
79
  }
@@ -63,7 +85,7 @@ CodeMirror.defineMode("scheme", function (config, mode) {
63
85
  var next, maybeEnd = false;
64
86
  while ((next = stream.next()) != null) {
65
87
  if (next == "#" && maybeEnd) {
66
-
88
+
67
89
  state.mode = false;
68
90
  break;
69
91
  }
@@ -84,55 +106,52 @@ CodeMirror.defineMode("scheme", function (config, mode) {
84
106
  }
85
107
  default: // default parsing mode
86
108
  var ch = stream.next();
87
-
109
+
88
110
  if (ch == "\"") {
89
111
  state.mode = "string";
90
112
  returnType = STRING;
91
-
113
+
92
114
  } else if (ch == "'") {
93
115
  returnType = ATOM;
94
116
  } else if (ch == '#') {
95
- if (stream.eat("|")) { // Multi-line comment
117
+ if (stream.eat("|")) { // Multi-line comment
96
118
  state.mode = "comment"; // toggle to comment mode
97
119
  returnType = COMMENT;
98
- } else if (stream.eat(/[tf]/)) { // #t/#f (atom)
120
+ } else if (stream.eat(/[tf]/)) { // #t/#f (atom)
99
121
  returnType = ATOM;
100
- } else if (stream.eat(';')) { // S-Expr comment
122
+ } else if (stream.eat(';')) { // S-Expr comment
101
123
  state.mode = "s-expr-comment";
102
124
  returnType = COMMENT;
103
125
  }
104
-
126
+
105
127
  } else if (ch == ";") { // comment
106
128
  stream.skipToEnd(); // rest of the line is a comment
107
129
  returnType = COMMENT;
108
130
  } else if (ch == "-"){
109
-
110
- if(stream.eat(/\d/)) {
131
+
132
+ if(!isNaN(parseInt(stream.peek()))){
111
133
  stream.eatWhile(/[\/0-9]/);
112
134
  returnType = NUMBER;
113
- }else{
114
-
135
+ }else{
115
136
  returnType = null;
116
137
  }
117
- } else if (numRegex.exec(ch) != null) { // numbers
118
- stream.eatWhile(/[\/0-9]/);
138
+ } else if (isNumber(ch,stream)){
119
139
  returnType = NUMBER;
120
-
121
140
  } else if (ch == "(" || ch == "[") {
122
141
  var keyWord = ''; var indentTemp = stream.column();
123
142
  /**
124
- Either
143
+ Either
125
144
  (indent-word ..
126
145
  (non-indent-word ..
127
146
  (;something else, bracket, etc.
128
147
  */
129
-
148
+
130
149
  while ((letter = stream.eat(/[^\s\(\[\;\)\]]/)) != null) {
131
150
  keyWord += letter;
132
151
  }
133
-
152
+
134
153
  if (keyWord.length > 0 && indentKeys.propertyIsEnumerable(keyWord)) { // indent-word
135
-
154
+
136
155
  pushStack(state, indentTemp + INDENT_WORD_SKIP, ch);
137
156
  } else { // non-indent word
138
157
  // we continue eating the spaces
@@ -146,15 +165,15 @@ CodeMirror.defineMode("scheme", function (config, mode) {
146
165
  }
147
166
  }
148
167
  stream.backUp(stream.current().length - 1); // undo all the eating
149
-
168
+
150
169
  if(typeof state.sExprComment == "number") state.sExprComment++;
151
-
170
+
152
171
  returnType = BRACKET;
153
172
  } else if (ch == ")" || ch == "]") {
154
173
  returnType = BRACKET;
155
174
  if (state.indentStack != null && state.indentStack.type == (ch == ")" ? "(" : "[")) {
156
175
  popStack(state);
157
-
176
+
158
177
  if(typeof state.sExprComment == "number"){
159
178
  if(--state.sExprComment == 0){
160
179
  returnType = COMMENT; // final closing bracket
@@ -164,19 +183,20 @@ CodeMirror.defineMode("scheme", function (config, mode) {
164
183
  }
165
184
  } else {
166
185
  stream.eatWhile(/[\w\$_\-]/);
167
-
186
+
168
187
  if (keywords && keywords.propertyIsEnumerable(stream.current())) {
169
-
170
188
  returnType = BUILTIN;
171
- } else returnType = null;
189
+ }else returnType = null;
172
190
  }
173
191
  }
174
192
  return (typeof state.sExprComment == "number") ? COMMENT : returnType;
175
193
  },
194
+
176
195
  indent: function (state, textAfter) {
177
196
  if (state.indentStack == null) return state.indentation;
178
197
  return state.indentStack.indent;
179
198
  }
180
199
  };
181
200
  });
182
- CodeMirror.defineMIME("text/x-scheme", "scheme");
201
+
202
+ CodeMirror.defineMIME("text/x-scheme", "scheme");
@@ -132,7 +132,6 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
132
132
  var err = false;
133
133
  if (curState.context) {
134
134
  err = curState.context.tagName != tagName;
135
- popContext();
136
135
  } else {
137
136
  err = true;
138
137
  }
@@ -158,8 +157,9 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
158
157
  function endclosetag(err) {
159
158
  return function(type) {
160
159
  if (err) setStyle = "error";
161
- if (type == "endTag") return cont();
162
- return pass();
160
+ if (type == "endTag") { popContext(); return cont(); }
161
+ setStyle = "error";
162
+ return cont(arguments.callee);
163
163
  }
164
164
  }
165
165
 
@@ -216,7 +216,7 @@ CodeMirror.defineMode("xml", function(config, parserConfig) {
216
216
  },
217
217
 
218
218
  compareStates: function(a, b) {
219
- if (a.indented != b.indented || a.tagName != b.tagName) return false;
219
+ if (a.indented != b.indented) return false;
220
220
  for (var ca = a.context, cb = b.context; ; ca = ca.prev, cb = cb.prev) {
221
221
  if (!ca || !cb) return ca == cb;
222
222
  if (ca.tagName != cb.tagName) return false;
@@ -13,6 +13,7 @@
13
13
 
14
14
  .CodeMirror-gutter {
15
15
  position: absolute; left: 0; top: 0;
16
+ z-index: 10;
16
17
  background-color: #f7f7f7;
17
18
  border-right: 1px solid #eee;
18
19
  min-width: 2em;
@@ -0,0 +1,10 @@
1
+ .cm-s-default span.cm-header {color: #2f2f4f; font-weight:bold;}
2
+ .cm-s-default span.cm-code {color: #666;}
3
+ .cm-s-default span.cm-quote {color: #090;}
4
+ .cm-s-default span.cm-list {color: #a50;}
5
+ .cm-s-default span.cm-hr {color: #999;}
6
+ .cm-s-default span.cm-linktext {color: #00c; text-decoration: underline;}
7
+ .cm-s-default span.cm-linkhref {color: #00c;}
8
+ .cm-s-default span.cm-em {font-style: italic;}
9
+ .cm-s-default span.cm-strong {font-weight: bold;}
10
+ .cm-s-default span.cm-emstrong {font-style: italic; font-weight: bold;}
@@ -0,0 +1,17 @@
1
+ .cm-s-cobalt { background: #002240; color: white; }
2
+ .cm-s-cobalt span.CodeMirror-selected { background: #b36539 !important; }
3
+ .cm-s-cobalt .CodeMirror-gutter { background: #002240; border-right: 1px solid #aaa; }
4
+ .cm-s-cobalt .CodeMirror-gutter-text { color: #d0d0d0; }
5
+ .cm-s-cobalt .CodeMirror-cursor { border-left: 1px solid white !important; }
6
+
7
+ .cm-s-cobalt span.cm-comment { color: #08f; }
8
+ .cm-s-cobalt span.cm-atom { color: #845dc4; }
9
+ .cm-s-cobalt span.cm-number, .cm-s-cobalt span.cm-attribute { color: #ff80e1; }
10
+ .cm-s-cobalt span.cm-keyword { color: #ffee80; }
11
+ .cm-s-cobalt span.cm-string { color: #3ad900; }
12
+ .cm-s-cobalt span.cm-meta { color: #ff9d00; }
13
+ .cm-s-cobalt span.cm-variable-2, .cm-s-cobalt span.cm-tag { color: #9effff; }
14
+ .cm-s-cobalt span.cm-variable-3, .cm-s-cobalt span.cm-def { color: white; }
15
+ .cm-s-cobalt span.cm-error { color: #9d1e15; }
16
+ .cm-s-cobalt span.cm-bracket { color: #d8d8d8; }
17
+ .cm-s-cobalt span.cm-builtin, .cm-s-cobalt span.cm-special { color: #ff9e59; }
@@ -0,0 +1,24 @@
1
+ .cm-s-eclipse span.cm-meta {color: #FF1717;}
2
+ .cm-s-eclipse span.cm-keyword { font-weight: bold; color: #7F0055; }
3
+ .cm-s-eclipse span.cm-atom {color: #219;}
4
+ .cm-s-eclipse span.cm-number {color: #164;}
5
+ .cm-s-eclipse span.cm-def {color: #00f;}
6
+ .cm-s-eclipse span.cm-variable {color: black;}
7
+ .cm-s-eclipse span.cm-variable-2 {color: #0000C0;}
8
+ .cm-s-eclipse span.cm-variable-3 {color: #0000C0;}
9
+ .cm-s-eclipse span.cm-property {color: black;}
10
+ .cm-s-eclipse span.cm-operator {color: black;}
11
+ .cm-s-eclipse span.cm-comment {color: #3F7F5F;}
12
+ .cm-s-eclipse span.cm-string {color: #2A00FF;}
13
+ .cm-s-eclipse span.cm-string-2 {color: #f50;}
14
+ .cm-s-eclipse span.cm-error {color: #f00;}
15
+ .cm-s-eclipse span.cm-qualifier {color: #555;}
16
+ .cm-s-eclipse span.cm-builtin {color: #30a;}
17
+ .cm-s-eclipse span.cm-bracket {color: #cc7;}
18
+ .cm-s-eclipse span.cm-tag {color: #170;}
19
+ .cm-s-eclipse span.cm-attribute {color: #00c;}
20
+
21
+ .CodeMirror-matchingbracket{
22
+ border:1px solid grey;
23
+ color:black !important;;
24
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codemirror-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-23 00:00:00.000000000 -04:00
13
- default_executable:
12
+ date: 2011-10-04 00:00:00.000000000Z
14
13
  dependencies: []
15
14
  description: This gem provides CodeMirror assets for your Rails 3 application.
16
15
  email: nathan@fixler.org
@@ -25,18 +24,24 @@ files:
25
24
  - doc/CodeMirror-LICENSE
26
25
  - lib/codemirror-rails.rb
27
26
  - lib/codemirror/rails.rb
27
+ - lib/codemirror/rails/engine.rb
28
28
  - lib/codemirror/rails/railtie.rb
29
29
  - lib/codemirror/rails/version.rb
30
30
  - lib/generators/codemirror/install/install_generator.rb
31
31
  - vendor/assets/javascripts/codemirror.js
32
32
  - vendor/assets/javascripts/codemirror/modes/clike.js
33
+ - vendor/assets/javascripts/codemirror/modes/clojure.js
33
34
  - vendor/assets/javascripts/codemirror/modes/coffeescript.js
34
35
  - vendor/assets/javascripts/codemirror/modes/css.js
35
36
  - vendor/assets/javascripts/codemirror/modes/diff.js
36
37
  - vendor/assets/javascripts/codemirror/modes/haskell.js
37
38
  - vendor/assets/javascripts/codemirror/modes/htmlmixed.js
38
39
  - vendor/assets/javascripts/codemirror/modes/javascript.js
40
+ - vendor/assets/javascripts/codemirror/modes/jinja2.js
39
41
  - vendor/assets/javascripts/codemirror/modes/lua.js
42
+ - vendor/assets/javascripts/codemirror/modes/markdown.js
43
+ - vendor/assets/javascripts/codemirror/modes/ntriples.js
44
+ - vendor/assets/javascripts/codemirror/modes/pascal.js
40
45
  - vendor/assets/javascripts/codemirror/modes/php.js
41
46
  - vendor/assets/javascripts/codemirror/modes/plsql.js
42
47
  - vendor/assets/javascripts/codemirror/modes/python.js
@@ -56,12 +61,14 @@ files:
56
61
  - vendor/assets/stylesheets/codemirror.css
57
62
  - vendor/assets/stylesheets/codemirror/modes/clike.css
58
63
  - vendor/assets/stylesheets/codemirror/modes/diff.css
64
+ - vendor/assets/stylesheets/codemirror/modes/markdown.css
59
65
  - vendor/assets/stylesheets/codemirror/modes/rst.css
66
+ - vendor/assets/stylesheets/codemirror/themes/cobalt.css
60
67
  - vendor/assets/stylesheets/codemirror/themes/default.css
68
+ - vendor/assets/stylesheets/codemirror/themes/eclipse.css
61
69
  - vendor/assets/stylesheets/codemirror/themes/elegant.css
62
70
  - vendor/assets/stylesheets/codemirror/themes/neat.css
63
71
  - vendor/assets/stylesheets/codemirror/themes/night.css
64
- has_rdoc: true
65
72
  homepage: https://rubygems.org/gems/codemirror-rails
66
73
  licenses: []
67
74
  post_install_message:
@@ -82,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
89
  version: '0'
83
90
  requirements: []
84
91
  rubyforge_project:
85
- rubygems_version: 1.6.2
92
+ rubygems_version: 1.8.10
86
93
  signing_key:
87
94
  specification_version: 3
88
95
  summary: Use CodeMirror with Rails 3