liquid_cms 0.2.1.1 → 0.2.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. data/CHANGELOG.rdoc +7 -0
  2. data/README.rdoc +15 -1
  3. data/TODO.rdoc +0 -2
  4. data/app/controllers/cms/assets_controller.rb +20 -6
  5. data/app/controllers/cms/components_controller.rb +11 -3
  6. data/app/controllers/cms/pages_controller.rb +15 -4
  7. data/app/helpers/cms/common_helper.rb +31 -31
  8. data/app/liquid/cms_paperclip_extension.rb +75 -3
  9. data/app/models/cms/asset.rb +1 -1
  10. data/app/models/cms/component.rb +3 -3
  11. data/app/views/cms/assets/_form.html.erb +1 -1
  12. data/app/views/cms/assets/update.js.rjs +1 -0
  13. data/app/views/cms/components/update.js.rjs +1 -0
  14. data/app/views/cms/pages/_form.html.erb +1 -1
  15. data/app/views/cms/pages/update.js.rjs +1 -0
  16. data/app/views/layouts/cms.html.erb +4 -3
  17. data/generators/liquid_cms/liquid_cms_generator.rb +1 -0
  18. data/generators/liquid_cms/templates/config/locales/cms/en.yml +4 -0
  19. data/generators/liquid_cms/templates/migration_rev2.rb +13 -0
  20. data/generators/liquid_cms/templates/public/cms/codemirror/LICENSE +16 -20
  21. data/generators/liquid_cms/templates/public/cms/codemirror/lib/codemirror.css +68 -0
  22. data/generators/liquid_cms/templates/public/cms/codemirror/lib/codemirror.js +2197 -0
  23. data/generators/liquid_cms/templates/public/cms/codemirror/lib/overlay.js +51 -0
  24. data/generators/liquid_cms/templates/public/cms/codemirror/lib/runmode.js +27 -0
  25. data/generators/liquid_cms/templates/public/cms/codemirror/mode/clike/clike.js +247 -0
  26. data/generators/liquid_cms/templates/public/cms/codemirror/mode/clike/index.html +102 -0
  27. data/generators/liquid_cms/templates/public/cms/codemirror/mode/clojure/clojure.js +207 -0
  28. data/generators/liquid_cms/templates/public/cms/codemirror/mode/clojure/index.html +85 -0
  29. data/generators/liquid_cms/templates/public/cms/codemirror/mode/coffeescript/LICENSE +22 -0
  30. data/generators/liquid_cms/templates/public/cms/codemirror/mode/coffeescript/coffeescript.js +325 -0
  31. data/generators/liquid_cms/templates/public/cms/codemirror/mode/coffeescript/index.html +722 -0
  32. data/generators/liquid_cms/templates/public/cms/codemirror/mode/css/css.js +124 -0
  33. data/generators/liquid_cms/templates/public/cms/codemirror/mode/css/index.html +56 -0
  34. data/generators/liquid_cms/templates/public/cms/codemirror/mode/diff/diff.css +3 -0
  35. data/generators/liquid_cms/templates/public/cms/codemirror/mode/diff/diff.js +13 -0
  36. data/generators/liquid_cms/templates/public/cms/codemirror/mode/diff/index.html +99 -0
  37. data/generators/liquid_cms/templates/public/cms/codemirror/mode/haskell/haskell.js +242 -0
  38. data/generators/liquid_cms/templates/public/cms/codemirror/mode/haskell/index.html +60 -0
  39. data/generators/liquid_cms/templates/public/cms/codemirror/mode/htmlmixed/htmlmixed.js +79 -0
  40. data/generators/liquid_cms/templates/public/cms/codemirror/mode/htmlmixed/index.html +52 -0
  41. data/generators/liquid_cms/templates/public/cms/codemirror/mode/javascript/index.html +78 -0
  42. data/generators/liquid_cms/templates/public/cms/codemirror/mode/javascript/javascript.js +352 -0
  43. data/generators/liquid_cms/templates/public/cms/codemirror/mode/jinja2/index.html +38 -0
  44. data/generators/liquid_cms/templates/public/cms/codemirror/mode/jinja2/jinja2.js +42 -0
  45. data/generators/liquid_cms/templates/public/cms/codemirror/mode/lua/index.html +72 -0
  46. data/generators/liquid_cms/templates/public/cms/codemirror/mode/lua/lua.js +140 -0
  47. data/generators/liquid_cms/templates/public/cms/codemirror/mode/markdown/index.html +340 -0
  48. data/generators/liquid_cms/templates/public/cms/codemirror/mode/markdown/markdown.css +10 -0
  49. data/generators/liquid_cms/templates/public/cms/codemirror/mode/markdown/markdown.js +230 -0
  50. data/generators/liquid_cms/templates/public/cms/codemirror/mode/ntriples/index.html +33 -0
  51. data/generators/liquid_cms/templates/public/cms/codemirror/mode/ntriples/ntriples.js +172 -0
  52. data/generators/liquid_cms/templates/public/cms/codemirror/mode/pascal/LICENSE +7 -0
  53. data/generators/liquid_cms/templates/public/cms/codemirror/mode/pascal/index.html +49 -0
  54. data/generators/liquid_cms/templates/public/cms/codemirror/mode/pascal/pascal.js +138 -0
  55. data/generators/liquid_cms/templates/public/cms/codemirror/mode/php/index.html +49 -0
  56. data/generators/liquid_cms/templates/public/cms/codemirror/mode/php/php.js +116 -0
  57. data/generators/liquid_cms/templates/public/cms/codemirror/mode/plsql/index.html +63 -0
  58. data/generators/liquid_cms/templates/public/cms/codemirror/mode/plsql/plsql.js +217 -0
  59. data/generators/liquid_cms/templates/public/cms/codemirror/mode/python/LICENSE.txt +21 -0
  60. data/generators/liquid_cms/templates/public/cms/codemirror/mode/python/index.html +123 -0
  61. data/generators/liquid_cms/templates/public/cms/codemirror/mode/python/python.js +320 -0
  62. data/generators/liquid_cms/templates/public/cms/codemirror/mode/r/LICENSE +24 -0
  63. data/generators/liquid_cms/templates/public/cms/codemirror/mode/r/index.html +74 -0
  64. data/generators/liquid_cms/templates/public/cms/codemirror/mode/r/r.js +141 -0
  65. data/generators/liquid_cms/templates/public/cms/codemirror/mode/rst/index.html +526 -0
  66. data/generators/liquid_cms/templates/public/cms/codemirror/mode/rst/rst.css +75 -0
  67. data/generators/liquid_cms/templates/public/cms/codemirror/mode/rst/rst.js +333 -0
  68. data/generators/liquid_cms/templates/public/cms/codemirror/mode/ruby/LICENSE +24 -0
  69. data/generators/liquid_cms/templates/public/cms/codemirror/mode/ruby/index.html +172 -0
  70. data/generators/liquid_cms/templates/public/cms/codemirror/mode/ruby/ruby.js +195 -0
  71. data/generators/liquid_cms/templates/public/cms/codemirror/mode/scheme/index.html +65 -0
  72. data/generators/liquid_cms/templates/public/cms/codemirror/mode/scheme/scheme.js +202 -0
  73. data/generators/liquid_cms/templates/public/cms/codemirror/mode/smalltalk/index.html +56 -0
  74. data/generators/liquid_cms/templates/public/cms/codemirror/mode/smalltalk/smalltalk.js +122 -0
  75. data/generators/liquid_cms/templates/public/cms/codemirror/mode/sparql/index.html +41 -0
  76. data/generators/liquid_cms/templates/public/cms/codemirror/mode/sparql/sparql.js +143 -0
  77. data/generators/liquid_cms/templates/public/cms/codemirror/mode/stex/index.html +96 -0
  78. data/generators/liquid_cms/templates/public/cms/codemirror/mode/stex/stex.js +167 -0
  79. data/generators/liquid_cms/templates/public/cms/codemirror/mode/velocity/index.html +103 -0
  80. data/generators/liquid_cms/templates/public/cms/codemirror/mode/velocity/velocity.js +146 -0
  81. data/generators/liquid_cms/templates/public/cms/codemirror/mode/xml/index.html +42 -0
  82. data/generators/liquid_cms/templates/public/cms/codemirror/mode/xml/xml.js +231 -0
  83. data/generators/liquid_cms/templates/public/cms/codemirror/mode/xmlpure/index.html +60 -0
  84. data/generators/liquid_cms/templates/public/cms/codemirror/mode/xmlpure/xmlpure.js +481 -0
  85. data/generators/liquid_cms/templates/public/cms/codemirror/mode/yaml/index.html +68 -0
  86. data/generators/liquid_cms/templates/public/cms/codemirror/mode/yaml/yaml.js +95 -0
  87. data/generators/liquid_cms/templates/public/cms/codemirror/theme/cobalt.css +17 -0
  88. data/generators/liquid_cms/templates/public/cms/codemirror/theme/default.css +19 -0
  89. data/generators/liquid_cms/templates/public/cms/codemirror/theme/eclipse.css +24 -0
  90. data/generators/liquid_cms/templates/public/cms/codemirror/theme/elegant.css +9 -0
  91. data/generators/liquid_cms/templates/public/cms/codemirror/theme/neat.css +8 -0
  92. data/generators/liquid_cms/templates/public/cms/codemirror/theme/night.css +20 -0
  93. data/generators/liquid_cms/templates/public/cms/javascripts/cms.js +1 -1
  94. data/generators/liquid_cms/templates/public/cms/javascripts/codemirror_custom.js +96 -0
  95. data/generators/liquid_cms/templates/public/cms/stylesheets/codemirror_changes.css +26 -0
  96. data/generators/liquid_cms/templates/public/cms/stylesheets/liquid.css +7 -0
  97. data/generators/liquid_cms/templates/public/cms/stylesheets/simple_form.css +0 -8
  98. data/lib/liquid_cms/version.rb +1 -1
  99. data/liquid_cms.gemspec +0 -1
  100. data/test/functional/assets_controller_test.rb +35 -20
  101. data/test/functional/components_controller_test.rb +15 -5
  102. data/test/functional/pages_controller_test.rb +19 -6
  103. data/test/rails_app/config/environment.rb +1 -1
  104. data/test/rails_app/config/locales/cms/en.yml +19 -4
  105. data/test/rails_app/db/migrate/20110511161859_create_liquid_cms_upgrade_rev2.rb +13 -0
  106. data/test/unit/asset_test.rb +1 -1
  107. metadata +100 -58
  108. data/generators/liquid_cms/templates/public/cms/codemirror/css/csscolors.css +0 -55
  109. data/generators/liquid_cms/templates/public/cms/codemirror/css/docs.css +0 -158
  110. data/generators/liquid_cms/templates/public/cms/codemirror/css/font.js +0 -15
  111. data/generators/liquid_cms/templates/public/cms/codemirror/css/jscolors.css +0 -59
  112. data/generators/liquid_cms/templates/public/cms/codemirror/css/sparqlcolors.css +0 -43
  113. data/generators/liquid_cms/templates/public/cms/codemirror/css/xmlcolors.css +0 -55
  114. data/generators/liquid_cms/templates/public/cms/codemirror/js/codemirror.js +0 -582
  115. data/generators/liquid_cms/templates/public/cms/codemirror/js/editor.js +0 -1671
  116. data/generators/liquid_cms/templates/public/cms/codemirror/js/highlight.js +0 -68
  117. data/generators/liquid_cms/templates/public/cms/codemirror/js/mirrorframe.js +0 -81
  118. data/generators/liquid_cms/templates/public/cms/codemirror/js/parsecss.js +0 -161
  119. data/generators/liquid_cms/templates/public/cms/codemirror/js/parsedummy.js +0 -32
  120. data/generators/liquid_cms/templates/public/cms/codemirror/js/parsehtmlmixed.js +0 -93
  121. data/generators/liquid_cms/templates/public/cms/codemirror/js/parsejavascript.js +0 -359
  122. data/generators/liquid_cms/templates/public/cms/codemirror/js/parsesparql.js +0 -162
  123. data/generators/liquid_cms/templates/public/cms/codemirror/js/parsexml.js +0 -291
  124. data/generators/liquid_cms/templates/public/cms/codemirror/js/select.js +0 -699
  125. data/generators/liquid_cms/templates/public/cms/codemirror/js/stringstream.js +0 -159
  126. data/generators/liquid_cms/templates/public/cms/codemirror/js/tokenize.js +0 -57
  127. data/generators/liquid_cms/templates/public/cms/codemirror/js/tokenizejavascript.js +0 -174
  128. data/generators/liquid_cms/templates/public/cms/codemirror/js/undo.js +0 -413
  129. data/generators/liquid_cms/templates/public/cms/codemirror/js/unittests.js +0 -44
  130. data/generators/liquid_cms/templates/public/cms/codemirror/js/util.js +0 -133
@@ -0,0 +1,124 @@
1
+ CodeMirror.defineMode("css", function(config) {
2
+ var indentUnit = config.indentUnit, type;
3
+ function ret(style, tp) {type = tp; return style;}
4
+
5
+ function tokenBase(stream, state) {
6
+ var ch = stream.next();
7
+ if (ch == "@") {stream.eatWhile(/[\w\\\-]/); return ret("meta", stream.current());}
8
+ else if (ch == "/" && stream.eat("*")) {
9
+ state.tokenize = tokenCComment;
10
+ return tokenCComment(stream, state);
11
+ }
12
+ else if (ch == "<" && stream.eat("!")) {
13
+ state.tokenize = tokenSGMLComment;
14
+ return tokenSGMLComment(stream, state);
15
+ }
16
+ else if (ch == "=") ret(null, "compare");
17
+ else if ((ch == "~" || ch == "|") && stream.eat("=")) return ret(null, "compare");
18
+ else if (ch == "\"" || ch == "'") {
19
+ state.tokenize = tokenString(ch);
20
+ return state.tokenize(stream, state);
21
+ }
22
+ else if (ch == "#") {
23
+ stream.eatWhile(/[\w\\\-]/);
24
+ return ret("atom", "hash");
25
+ }
26
+ else if (ch == "!") {
27
+ stream.match(/^\s*\w*/);
28
+ return ret("keyword", "important");
29
+ }
30
+ else if (/\d/.test(ch)) {
31
+ stream.eatWhile(/[\w.%]/);
32
+ return ret("number", "unit");
33
+ }
34
+ else if (/[,.+>*\/]/.test(ch)) {
35
+ return ret(null, "select-op");
36
+ }
37
+ else if (/[;{}:\[\]]/.test(ch)) {
38
+ return ret(null, ch);
39
+ }
40
+ else {
41
+ stream.eatWhile(/[\w\\\-]/);
42
+ return ret("variable", "variable");
43
+ }
44
+ }
45
+
46
+ function tokenCComment(stream, state) {
47
+ var maybeEnd = false, ch;
48
+ while ((ch = stream.next()) != null) {
49
+ if (maybeEnd && ch == "/") {
50
+ state.tokenize = tokenBase;
51
+ break;
52
+ }
53
+ maybeEnd = (ch == "*");
54
+ }
55
+ return ret("comment", "comment");
56
+ }
57
+
58
+ function tokenSGMLComment(stream, state) {
59
+ var dashes = 0, ch;
60
+ while ((ch = stream.next()) != null) {
61
+ if (dashes >= 2 && ch == ">") {
62
+ state.tokenize = tokenBase;
63
+ break;
64
+ }
65
+ dashes = (ch == "-") ? dashes + 1 : 0;
66
+ }
67
+ return ret("comment", "comment");
68
+ }
69
+
70
+ function tokenString(quote) {
71
+ return function(stream, state) {
72
+ var escaped = false, ch;
73
+ while ((ch = stream.next()) != null) {
74
+ if (ch == quote && !escaped)
75
+ break;
76
+ escaped = !escaped && ch == "\\";
77
+ }
78
+ if (!escaped) state.tokenize = tokenBase;
79
+ return ret("string", "string");
80
+ };
81
+ }
82
+
83
+ return {
84
+ startState: function(base) {
85
+ return {tokenize: tokenBase,
86
+ baseIndent: base || 0,
87
+ stack: []};
88
+ },
89
+
90
+ token: function(stream, state) {
91
+ if (stream.eatSpace()) return null;
92
+ var style = state.tokenize(stream, state);
93
+
94
+ var context = state.stack[state.stack.length-1];
95
+ if (type == "hash" && context == "rule") style = "atom";
96
+ else if (style == "variable") {
97
+ if (context == "rule") style = "number";
98
+ else if (!context || context == "@media{") style = "tag";
99
+ }
100
+
101
+ if (context == "rule" && /^[\{\};]$/.test(type))
102
+ state.stack.pop();
103
+ if (type == "{") {
104
+ if (context == "@media") state.stack[state.stack.length-1] = "@media{";
105
+ else state.stack.push("{");
106
+ }
107
+ else if (type == "}") state.stack.pop();
108
+ else if (type == "@media") state.stack.push("@media");
109
+ else if (context == "{" && type != "comment") state.stack.push("rule");
110
+ return style;
111
+ },
112
+
113
+ indent: function(state, textAfter) {
114
+ var n = state.stack.length;
115
+ if (/^\}/.test(textAfter))
116
+ n -= state.stack[state.stack.length-1] == "rule" ? 2 : 1;
117
+ return state.baseIndent + n * indentUnit;
118
+ },
119
+
120
+ electricChars: "}"
121
+ };
122
+ });
123
+
124
+ CodeMirror.defineMIME("text/css", "css");
@@ -0,0 +1,56 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>CodeMirror 2: CSS mode</title>
5
+ <link rel="stylesheet" href="../../lib/codemirror.css">
6
+ <script src="../../lib/codemirror.js"></script>
7
+ <script src="css.js"></script>
8
+ <link rel="stylesheet" href="../../theme/default.css">
9
+ <style>.CodeMirror {background: #f8f8f8;}</style>
10
+ <link rel="stylesheet" href="../../css/docs.css">
11
+ </head>
12
+ <body>
13
+ <h1>CodeMirror 2: CSS mode</h1>
14
+ <form><textarea id="code" name="code">
15
+ /* Some example CSS */
16
+
17
+ @import url("something.css");
18
+
19
+ body {
20
+ margin: 0;
21
+ padding: 3em 6em;
22
+ font-family: tahoma, arial, sans-serif;
23
+ color: #000;
24
+ }
25
+
26
+ #navigation a {
27
+ font-weight: bold;
28
+ text-decoration: none !important;
29
+ }
30
+
31
+ h1 {
32
+ font-size: 2.5em;
33
+ }
34
+
35
+ h2 {
36
+ font-size: 1.7em;
37
+ }
38
+
39
+ h1:before, h2:before {
40
+ content: "::";
41
+ }
42
+
43
+ code {
44
+ font-family: courier, monospace;
45
+ font-size: 80%;
46
+ color: #418A8A;
47
+ }
48
+ </textarea></form>
49
+ <script>
50
+ var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
51
+ </script>
52
+
53
+ <p><strong>MIME types defined:</strong> <code>text/css</code>.</p>
54
+
55
+ </body>
56
+ </html>
@@ -0,0 +1,3 @@
1
+ .cm-s-default span.cm-rangeinfo {color: #a0b;}
2
+ .cm-s-default span.cm-minus {color: #a22;}
3
+ .cm-s-default span.cm-plus {color: #2b2;}
@@ -0,0 +1,13 @@
1
+ CodeMirror.defineMode("diff", function() {
2
+ return {
3
+ token: function(stream) {
4
+ var ch = stream.next();
5
+ stream.skipToEnd();
6
+ if (ch == "+") return "plus";
7
+ if (ch == "-") return "minus";
8
+ if (ch == "@") return "rangeinfo";
9
+ }
10
+ };
11
+ });
12
+
13
+ CodeMirror.defineMIME("text/x-diff", "diff");
@@ -0,0 +1,99 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>CodeMirror 2: Diff mode</title>
5
+ <link rel="stylesheet" href="../../lib/codemirror.css">
6
+ <script src="../../lib/codemirror.js"></script>
7
+ <script src="diff.js"></script>
8
+ <link rel="stylesheet" href="diff.css">
9
+ <style>.CodeMirror {border-top: 1px solid #ddd; border-bottom: 1px solid #ddd;}</style>
10
+ <link rel="stylesheet" href="../../css/docs.css">
11
+ </head>
12
+ <body>
13
+ <h1>CodeMirror 2: Diff mode</h1>
14
+ <form><textarea id="code" name="code">
15
+ diff --git a/index.html b/index.html
16
+ index c1d9156..7764744 100644
17
+ --- a/index.html
18
+ +++ b/index.html
19
+ @@ -95,7 +95,8 @@ StringStream.prototype = {
20
+ <script>
21
+ var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
22
+ lineNumbers: true,
23
+ - autoMatchBrackets: true
24
+ + autoMatchBrackets: true,
25
+ + onGutterClick: function(x){console.log(x);}
26
+ });
27
+ </script>
28
+ </body>
29
+ diff --git a/lib/codemirror.js b/lib/codemirror.js
30
+ index 04646a9..9a39cc7 100644
31
+ --- a/lib/codemirror.js
32
+ +++ b/lib/codemirror.js
33
+ @@ -399,10 +399,16 @@ var CodeMirror = (function() {
34
+ }
35
+
36
+ function onMouseDown(e) {
37
+ - var start = posFromMouse(e), last = start;
38
+ + var start = posFromMouse(e), last = start, target = e.target();
39
+ if (!start) return;
40
+ setCursor(start.line, start.ch, false);
41
+ if (e.button() != 1) return;
42
+ + if (target.parentNode == gutter) {
43
+ + if (options.onGutterClick)
44
+ + options.onGutterClick(indexOf(gutter.childNodes, target) + showingFrom);
45
+ + return;
46
+ + }
47
+ +
48
+ if (!focused) onFocus();
49
+
50
+ e.stop();
51
+ @@ -808,7 +814,7 @@ var CodeMirror = (function() {
52
+ for (var i = showingFrom; i < showingTo; ++i) {
53
+ var marker = lines[i].gutterMarker;
54
+ if (marker) html.push('<div class="' + marker.style + '">' + htmlEscape(marker.text) + '</div>');
55
+ - else html.push("<div>" + (options.lineNumbers ? i + 1 : "\u00a0") + "</div>");
56
+ + else html.push("<div>" + (options.lineNumbers ? i + options.firstLineNumber : "\u00a0") + "</div>");
57
+ }
58
+ gutter.style.display = "none"; // TODO test whether this actually helps
59
+ gutter.innerHTML = html.join("");
60
+ @@ -1371,10 +1377,8 @@ var CodeMirror = (function() {
61
+ if (option == "parser") setParser(value);
62
+ else if (option === "lineNumbers") setLineNumbers(value);
63
+ else if (option === "gutter") setGutter(value);
64
+ - else if (option === "readOnly") options.readOnly = value;
65
+ - else if (option === "indentUnit") {options.indentUnit = indentUnit = value; setParser(options.parser);}
66
+ - else if (/^(?:enterMode|tabMode|indentWithTabs|readOnly|autoMatchBrackets|undoDepth)$/.test(option)) options[option] = value;
67
+ - else throw new Error("Can't set option " + option);
68
+ + else if (option === "indentUnit") {options.indentUnit = value; setParser(options.parser);}
69
+ + else options[option] = value;
70
+ },
71
+ cursorCoords: cursorCoords,
72
+ undo: operation(undo),
73
+ @@ -1402,7 +1406,8 @@ var CodeMirror = (function() {
74
+ replaceRange: operation(replaceRange),
75
+
76
+ operation: function(f){return operation(f)();},
77
+ - refresh: function(){updateDisplay([{from: 0, to: lines.length}]);}
78
+ + refresh: function(){updateDisplay([{from: 0, to: lines.length}]);},
79
+ + getInputField: function(){return input;}
80
+ };
81
+ return instance;
82
+ }
83
+ @@ -1420,6 +1425,7 @@ var CodeMirror = (function() {
84
+ readOnly: false,
85
+ onChange: null,
86
+ onCursorActivity: null,
87
+ + onGutterClick: null,
88
+ autoMatchBrackets: false,
89
+ workTime: 200,
90
+ workDelay: 300,
91
+ </textarea></form>
92
+ <script>
93
+ var editor = CodeMirror.fromTextArea(document.getElementById("code"), {});
94
+ </script>
95
+
96
+ <p><strong>MIME types defined:</strong> <code>text/x-diff</code>.</p>
97
+
98
+ </body>
99
+ </html>
@@ -0,0 +1,242 @@
1
+ CodeMirror.defineMode("haskell", function(cmCfg, modeCfg) {
2
+
3
+ function switchState(source, setState, f) {
4
+ setState(f);
5
+ return f(source, setState);
6
+ }
7
+
8
+ // These should all be Unicode extended, as per the Haskell 2010 report
9
+ var smallRE = /[a-z_]/;
10
+ var largeRE = /[A-Z]/;
11
+ var digitRE = /[0-9]/;
12
+ var hexitRE = /[0-9A-Fa-f]/;
13
+ var octitRE = /[0-7]/;
14
+ var idRE = /[a-z_A-Z0-9']/;
15
+ var symbolRE = /[-!#$%&*+.\/<=>?@\\^|~:]/;
16
+ var specialRE = /[(),;[\]`{}]/;
17
+ var whiteCharRE = /[ \t\v\f]/; // newlines are handled in tokenizer
18
+
19
+ function normal(source, setState) {
20
+ if (source.eatWhile(whiteCharRE)) {
21
+ return null;
22
+ }
23
+
24
+ var ch = source.next();
25
+ if (specialRE.test(ch)) {
26
+ if (ch == '{' && source.eat('-')) {
27
+ var t = "comment";
28
+ if (source.eat('#')) {
29
+ t = "meta";
30
+ }
31
+ return switchState(source, setState, ncomment(t, 1));
32
+ }
33
+ return null;
34
+ }
35
+
36
+ if (ch == '\'') {
37
+ if (source.eat('\\')) {
38
+ source.next(); // should handle other escapes here
39
+ }
40
+ else {
41
+ source.next();
42
+ }
43
+ if (source.eat('\'')) {
44
+ return "string";
45
+ }
46
+ return "error";
47
+ }
48
+
49
+ if (ch == '"') {
50
+ return switchState(source, setState, stringLiteral);
51
+ }
52
+
53
+ if (largeRE.test(ch)) {
54
+ source.eatWhile(idRE);
55
+ if (source.eat('.')) {
56
+ return "qualifier";
57
+ }
58
+ return "variable-2";
59
+ }
60
+
61
+ if (smallRE.test(ch)) {
62
+ source.eatWhile(idRE);
63
+ return "variable";
64
+ }
65
+
66
+ if (digitRE.test(ch)) {
67
+ if (ch == '0') {
68
+ if (source.eat(/[xX]/)) {
69
+ source.eatWhile(hexitRE); // should require at least 1
70
+ return "integer";
71
+ }
72
+ if (source.eat(/[oO]/)) {
73
+ source.eatWhile(octitRE); // should require at least 1
74
+ return "number";
75
+ }
76
+ }
77
+ source.eatWhile(digitRE);
78
+ var t = "number";
79
+ if (source.eat('.')) {
80
+ t = "number";
81
+ source.eatWhile(digitRE); // should require at least 1
82
+ }
83
+ if (source.eat(/[eE]/)) {
84
+ t = "number";
85
+ source.eat(/[-+]/);
86
+ source.eatWhile(digitRE); // should require at least 1
87
+ }
88
+ return t;
89
+ }
90
+
91
+ if (symbolRE.test(ch)) {
92
+ if (ch == '-' && source.eat(/-/)) {
93
+ source.eatWhile(/-/);
94
+ if (!source.eat(symbolRE)) {
95
+ source.skipToEnd();
96
+ return "comment";
97
+ }
98
+ }
99
+ var t = "variable";
100
+ if (ch == ':') {
101
+ t = "variable-2";
102
+ }
103
+ source.eatWhile(symbolRE);
104
+ return t;
105
+ }
106
+
107
+ return "error";
108
+ }
109
+
110
+ function ncomment(type, nest) {
111
+ if (nest == 0) {
112
+ return normal;
113
+ }
114
+ return function(source, setState) {
115
+ var currNest = nest;
116
+ while (!source.eol()) {
117
+ var ch = source.next();
118
+ if (ch == '{' && source.eat('-')) {
119
+ ++currNest;
120
+ }
121
+ else if (ch == '-' && source.eat('}')) {
122
+ --currNest;
123
+ if (currNest == 0) {
124
+ setState(normal);
125
+ return type;
126
+ }
127
+ }
128
+ }
129
+ setState(ncomment(type, currNest));
130
+ return type;
131
+ }
132
+ }
133
+
134
+ function stringLiteral(source, setState) {
135
+ while (!source.eol()) {
136
+ var ch = source.next();
137
+ if (ch == '"') {
138
+ setState(normal);
139
+ return "string";
140
+ }
141
+ if (ch == '\\') {
142
+ if (source.eol() || source.eat(whiteCharRE)) {
143
+ setState(stringGap);
144
+ return "string";
145
+ }
146
+ if (source.eat('&')) {
147
+ }
148
+ else {
149
+ source.next(); // should handle other escapes here
150
+ }
151
+ }
152
+ }
153
+ setState(normal);
154
+ return "error";
155
+ }
156
+
157
+ function stringGap(source, setState) {
158
+ if (source.eat('\\')) {
159
+ return switchState(source, setState, stringLiteral);
160
+ }
161
+ source.next();
162
+ setState(normal);
163
+ return "error";
164
+ }
165
+
166
+
167
+ var wellKnownWords = (function() {
168
+ var wkw = {};
169
+ function setType(t) {
170
+ return function () {
171
+ for (var i = 0; i < arguments.length; i++)
172
+ wkw[arguments[i]] = t;
173
+ }
174
+ }
175
+
176
+ setType("keyword")(
177
+ "case", "class", "data", "default", "deriving", "do", "else", "foreign",
178
+ "if", "import", "in", "infix", "infixl", "infixr", "instance", "let",
179
+ "module", "newtype", "of", "then", "type", "where", "_");
180
+
181
+ setType("keyword")(
182
+ "\.\.", ":", "::", "=", "\\", "\"", "<-", "->", "@", "~", "=>");
183
+
184
+ setType("builtin")(
185
+ "!!", "$!", "$", "&&", "+", "++", "-", ".", "/", "/=", "<", "<=", "=<<",
186
+ "==", ">", ">=", ">>", ">>=", "^", "^^", "||", "*", "**");
187
+
188
+ setType("builtin")(
189
+ "Bool", "Bounded", "Char", "Double", "EQ", "Either", "Enum", "Eq",
190
+ "False", "FilePath", "Float", "Floating", "Fractional", "Functor", "GT",
191
+ "IO", "IOError", "Int", "Integer", "Integral", "Just", "LT", "Left",
192
+ "Maybe", "Monad", "Nothing", "Num", "Ord", "Ordering", "Rational", "Read",
193
+ "ReadS", "Real", "RealFloat", "RealFrac", "Right", "Show", "ShowS",
194
+ "String", "True");
195
+
196
+ setType("builtin")(
197
+ "abs", "acos", "acosh", "all", "and", "any", "appendFile", "asTypeOf",
198
+ "asin", "asinh", "atan", "atan2", "atanh", "break", "catch", "ceiling",
199
+ "compare", "concat", "concatMap", "const", "cos", "cosh", "curry",
200
+ "cycle", "decodeFloat", "div", "divMod", "drop", "dropWhile", "either",
201
+ "elem", "encodeFloat", "enumFrom", "enumFromThen", "enumFromThenTo",
202
+ "enumFromTo", "error", "even", "exp", "exponent", "fail", "filter",
203
+ "flip", "floatDigits", "floatRadix", "floatRange", "floor", "fmap",
204
+ "foldl", "foldl1", "foldr", "foldr1", "fromEnum", "fromInteger",
205
+ "fromIntegral", "fromRational", "fst", "gcd", "getChar", "getContents",
206
+ "getLine", "head", "id", "init", "interact", "ioError", "isDenormalized",
207
+ "isIEEE", "isInfinite", "isNaN", "isNegativeZero", "iterate", "last",
208
+ "lcm", "length", "lex", "lines", "log", "logBase", "lookup", "map",
209
+ "mapM", "mapM_", "max", "maxBound", "maximum", "maybe", "min", "minBound",
210
+ "minimum", "mod", "negate", "not", "notElem", "null", "odd", "or",
211
+ "otherwise", "pi", "pred", "print", "product", "properFraction",
212
+ "putChar", "putStr", "putStrLn", "quot", "quotRem", "read", "readFile",
213
+ "readIO", "readList", "readLn", "readParen", "reads", "readsPrec",
214
+ "realToFrac", "recip", "rem", "repeat", "replicate", "return", "reverse",
215
+ "round", "scaleFloat", "scanl", "scanl1", "scanr", "scanr1", "seq",
216
+ "sequence", "sequence_", "show", "showChar", "showList", "showParen",
217
+ "showString", "shows", "showsPrec", "significand", "signum", "sin",
218
+ "sinh", "snd", "span", "splitAt", "sqrt", "subtract", "succ", "sum",
219
+ "tail", "take", "takeWhile", "tan", "tanh", "toEnum", "toInteger",
220
+ "toRational", "truncate", "uncurry", "undefined", "unlines", "until",
221
+ "unwords", "unzip", "unzip3", "userError", "words", "writeFile", "zip",
222
+ "zip3", "zipWith", "zipWith3");
223
+
224
+ return wkw;
225
+ })();
226
+
227
+
228
+
229
+ return {
230
+ startState: function () { return { f: normal }; },
231
+ copyState: function (s) { return { f: s.f }; },
232
+
233
+ token: function(stream, state) {
234
+ var t = state.f(stream, function(s) { state.f = s; });
235
+ var w = stream.current();
236
+ return (w in wellKnownWords) ? wellKnownWords[w] : t;
237
+ }
238
+ };
239
+
240
+ });
241
+
242
+ CodeMirror.defineMIME("text/x-haskell", "haskell");
@@ -0,0 +1,60 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>CodeMirror 2: Haskell mode</title>
5
+ <link rel="stylesheet" href="../../lib/codemirror.css">
6
+ <script src="../../lib/codemirror.js"></script>
7
+ <script src="haskell.js"></script>
8
+ <link rel="stylesheet" href="../../theme/elegant.css">
9
+ <style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
10
+ <link rel="stylesheet" href="../../css/docs.css">
11
+ </head>
12
+ <body>
13
+ <h1>CodeMirror 2: Haskell mode</h1>
14
+
15
+ <form><textarea id="code" name="code">
16
+ module UniquePerms (
17
+ uniquePerms
18
+ )
19
+ where
20
+
21
+ -- | Find all unique permutations of a list where there might be duplicates.
22
+ uniquePerms :: (Eq a) => [a] -> [[a]]
23
+ uniquePerms = permBag . makeBag
24
+
25
+ -- | An unordered collection where duplicate values are allowed,
26
+ -- but represented with a single value and a count.
27
+ type Bag a = [(a, Int)]
28
+
29
+ makeBag :: (Eq a) => [a] -> Bag a
30
+ makeBag [] = []
31
+ makeBag (a:as) = mix a $ makeBag as
32
+ where
33
+ mix a [] = [(a,1)]
34
+ mix a (bn@(b,n):bs) | a == b = (b,n+1):bs
35
+ | otherwise = bn : mix a bs
36
+
37
+ permBag :: Bag a -> [[a]]
38
+ permBag [] = [[]]
39
+ permBag bs = concatMap (\(f,cs) -> map (f:) $ permBag cs) . oneOfEach $ bs
40
+ where
41
+ oneOfEach [] = []
42
+ oneOfEach (an@(a,n):bs) =
43
+ let bs' = if n == 1 then bs else (a,n-1):bs
44
+ in (a,bs') : mapSnd (an:) (oneOfEach bs)
45
+
46
+ apSnd f (a,b) = (a, f b)
47
+ mapSnd = map . apSnd
48
+ </textarea></form>
49
+
50
+ <script>
51
+ var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
52
+ lineNumbers: true,
53
+ matchBrackets: true,
54
+ theme: "elegant"
55
+ });
56
+ </script>
57
+
58
+ <p><strong>MIME types defined:</strong> <code>text/x-haskell</code>.</p>
59
+ </body>
60
+ </html>
@@ -0,0 +1,79 @@
1
+ CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
2
+ var htmlMode = CodeMirror.getMode(config, {name: "xml", htmlMode: true});
3
+ var jsMode = CodeMirror.getMode(config, "javascript");
4
+ var cssMode = CodeMirror.getMode(config, "css");
5
+
6
+ function html(stream, state) {
7
+ var style = htmlMode.token(stream, state.htmlState);
8
+ if (style == "tag" && stream.current() == ">" && state.htmlState.context) {
9
+ if (/^script$/i.test(state.htmlState.context.tagName)) {
10
+ state.token = javascript;
11
+ state.localState = jsMode.startState(htmlMode.indent(state.htmlState, ""));
12
+ state.mode = "javascript";
13
+ }
14
+ else if (/^style$/i.test(state.htmlState.context.tagName)) {
15
+ state.token = css;
16
+ state.localState = cssMode.startState(htmlMode.indent(state.htmlState, ""));
17
+ state.mode = "css";
18
+ }
19
+ }
20
+ return style;
21
+ }
22
+ function maybeBackup(stream, pat, style) {
23
+ var cur = stream.current();
24
+ var close = cur.search(pat);
25
+ if (close > -1) stream.backUp(cur.length - close);
26
+ return style;
27
+ }
28
+ function javascript(stream, state) {
29
+ if (stream.match(/^<\/\s*script\s*>/i, false)) {
30
+ state.token = html;
31
+ state.curState = null;
32
+ state.mode = "html";
33
+ return html(stream, state);
34
+ }
35
+ return maybeBackup(stream, /<\/\s*script\s*>/,
36
+ jsMode.token(stream, state.localState));
37
+ }
38
+ function css(stream, state) {
39
+ if (stream.match(/^<\/\s*style\s*>/i, false)) {
40
+ state.token = html;
41
+ state.localState = null;
42
+ state.mode = "html";
43
+ return html(stream, state);
44
+ }
45
+ return maybeBackup(stream, /<\/\s*style\s*>/,
46
+ cssMode.token(stream, state.localState));
47
+ }
48
+
49
+ return {
50
+ startState: function() {
51
+ var state = htmlMode.startState();
52
+ return {token: html, localState: null, mode: "html", htmlState: state};
53
+ },
54
+
55
+ copyState: function(state) {
56
+ if (state.localState)
57
+ var local = CodeMirror.copyState(state.token == css ? cssMode : jsMode, state.localState);
58
+ return {token: state.token, localState: local, mode: state.mode,
59
+ htmlState: CodeMirror.copyState(htmlMode, state.htmlState)};
60
+ },
61
+
62
+ token: function(stream, state) {
63
+ return state.token(stream, state);
64
+ },
65
+
66
+ indent: function(state, textAfter) {
67
+ if (state.token == html || /^\s*<\//.test(textAfter))
68
+ return htmlMode.indent(state.htmlState, textAfter);
69
+ else if (state.token == javascript)
70
+ return jsMode.indent(state.localState, textAfter);
71
+ else
72
+ return cssMode.indent(state.localState, textAfter);
73
+ },
74
+
75
+ electricChars: "/{}:"
76
+ }
77
+ });
78
+
79
+ CodeMirror.defineMIME("text/html", "htmlmixed");