code_sync 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. data/.rvmrc +1 -0
  2. data/CNAME +1 -0
  3. data/Gemfile +24 -0
  4. data/Gemfile.lock +117 -0
  5. data/LICENSE.md +22 -0
  6. data/ROADMAP.md +20 -0
  7. data/TODO.md +14 -0
  8. data/bin/codesync +11 -0
  9. data/code_sync.gemspec +30 -0
  10. data/config/routes.rb +26 -0
  11. data/lib/assets/javascripts/canvas.coffee +12 -0
  12. data/lib/assets/javascripts/canvas/editors.coffee +48 -0
  13. data/lib/assets/javascripts/canvas/index.coffee +15 -0
  14. data/lib/assets/javascripts/canvas/layer_controller.coffee +47 -0
  15. data/lib/assets/javascripts/code_sync.coffee +3 -0
  16. data/lib/assets/javascripts/code_sync/backends/gist.coffee +78 -0
  17. data/lib/assets/javascripts/code_sync/client/index.coffee +104 -0
  18. data/lib/assets/javascripts/code_sync/client/util.coffee +61 -0
  19. data/lib/assets/javascripts/code_sync/codemirror.coffee +12 -0
  20. data/lib/assets/javascripts/code_sync/config.js.coffee.erb +38 -0
  21. data/lib/assets/javascripts/code_sync/console/index.coffee +54 -0
  22. data/lib/assets/javascripts/code_sync/console/templates/console.jst.skim +10 -0
  23. data/lib/assets/javascripts/code_sync/dependencies.coffee +6 -0
  24. data/lib/assets/javascripts/code_sync/editor/advanced.coffee +0 -0
  25. data/lib/assets/javascripts/code_sync/editor/datasources/document.coffee +212 -0
  26. data/lib/assets/javascripts/code_sync/editor/datasources/gist_loader.coffee +7 -0
  27. data/lib/assets/javascripts/code_sync/editor/datasources/modes.coffee +117 -0
  28. data/lib/assets/javascripts/code_sync/editor/datasources/project_assets.coffee +14 -0
  29. data/lib/assets/javascripts/code_sync/editor/index.coffee +415 -0
  30. data/lib/assets/javascripts/code_sync/editor/plugins/asset_selector.coffee +106 -0
  31. data/lib/assets/javascripts/code_sync/editor/plugins/color_picker.coffee +83 -0
  32. data/lib/assets/javascripts/code_sync/editor/plugins/document_manager.coffee +55 -0
  33. data/lib/assets/javascripts/code_sync/editor/plugins/document_tabs.coffee +178 -0
  34. data/lib/assets/javascripts/code_sync/editor/plugins/element_sync.coffee +111 -0
  35. data/lib/assets/javascripts/code_sync/editor/plugins/keymap_selector.coffee +44 -0
  36. data/lib/assets/javascripts/code_sync/editor/plugins/mode_selector.coffee +53 -0
  37. data/lib/assets/javascripts/code_sync/editor/plugins/name_input.coffee +44 -0
  38. data/lib/assets/javascripts/code_sync/editor/plugins/preferences.coffee +71 -0
  39. data/lib/assets/javascripts/code_sync/editor/templates/asset_editor.jst.skim +2 -0
  40. data/lib/assets/javascripts/code_sync/editor/templates/asset_selector.jst.skim +5 -0
  41. data/lib/assets/javascripts/code_sync/editor/templates/document_manager_tab.jst.skim +15 -0
  42. data/lib/assets/javascripts/code_sync/editor/templates/element_sync.jst.skim +19 -0
  43. data/lib/assets/javascripts/code_sync/editor/templates/preferences_panel.jst.skim +38 -0
  44. data/lib/assets/javascripts/code_sync/editor/views/asset_selector.coffee +106 -0
  45. data/lib/assets/javascripts/code_sync/editor/views/color_picker.coffee +76 -0
  46. data/lib/assets/javascripts/code_sync/editor/views/document_manager.coffee +176 -0
  47. data/lib/assets/javascripts/code_sync/editor/views/keymap_selector.coffee +37 -0
  48. data/lib/assets/javascripts/code_sync/editor/views/mode_selector.coffee +47 -0
  49. data/lib/assets/javascripts/code_sync/editor/views/name_input.coffee +44 -0
  50. data/lib/assets/javascripts/code_sync/editor/views/preferences.coffee +71 -0
  51. data/lib/assets/javascripts/code_sync/index.coffee +4 -0
  52. data/lib/assets/javascripts/code_sync/reloader.coffee +2 -0
  53. data/lib/assets/javascripts/code_sync_basic.coffee +1 -0
  54. data/lib/assets/javascripts/demos.coffee +48 -0
  55. data/lib/assets/javascripts/demos/default-content.coffee +72 -0
  56. data/lib/assets/javascripts/demos/layout_selector.coffee +19 -0
  57. data/lib/assets/javascripts/demos/tour.coffee +70 -0
  58. data/lib/assets/javascripts/demos/tour.jst.skim +29 -0
  59. data/lib/assets/javascripts/marketing.coffee +0 -0
  60. data/lib/assets/javascripts/vendor/.DS_Store +0 -0
  61. data/lib/assets/javascripts/vendor/backbone-events.js +160 -0
  62. data/lib/assets/javascripts/vendor/backbone-min.js +4 -0
  63. data/lib/assets/javascripts/vendor/codemirror-coffeescript.js +346 -0
  64. data/lib/assets/javascripts/vendor/codemirror-css.js +570 -0
  65. data/lib/assets/javascripts/vendor/codemirror-haml.js +153 -0
  66. data/lib/assets/javascripts/vendor/codemirror-htmlmixed.js +104 -0
  67. data/lib/assets/javascripts/vendor/codemirror-javascript.js +468 -0
  68. data/lib/assets/javascripts/vendor/codemirror-markdown.js +526 -0
  69. data/lib/assets/javascripts/vendor/codemirror-ruby.js +194 -0
  70. data/lib/assets/javascripts/vendor/codemirror-sass.js +330 -0
  71. data/lib/assets/javascripts/vendor/codemirror-skim.js +330 -0
  72. data/lib/assets/javascripts/vendor/codemirror-vim.js +3159 -0
  73. data/lib/assets/javascripts/vendor/codemirror-xml.js +328 -0
  74. data/lib/assets/javascripts/vendor/console.js +339 -0
  75. data/lib/assets/javascripts/vendor/gisted.js +27 -0
  76. data/lib/assets/javascripts/vendor/jquery-ui-resize-drag.min.js +6 -0
  77. data/lib/assets/javascripts/vendor/jquery.js +5 -0
  78. data/lib/assets/javascripts/vendor/keylauncher.js +4 -0
  79. data/lib/assets/javascripts/vendor/keymaster.min.js +4 -0
  80. data/lib/assets/javascripts/vendor/spectrum.js +1868 -0
  81. data/lib/assets/javascripts/vendor/underscore-min.js +1 -0
  82. data/lib/assets/javascripts/vendor/underscore.string.min.js +1 -0
  83. data/lib/assets/javascripts/vendor/vendored_codemirror.js +5558 -0
  84. data/lib/assets/javascripts/vendor/zepto.js +2 -0
  85. data/lib/assets/stylesheets/canvas.css.scss +101 -0
  86. data/lib/assets/stylesheets/code_sync.css.scss +4 -0
  87. data/lib/assets/stylesheets/code_sync/codemirror.css +7 -0
  88. data/lib/assets/stylesheets/code_sync/console.css +86 -0
  89. data/lib/assets/stylesheets/code_sync/editor/asset-name-input.css.scss +12 -0
  90. data/lib/assets/stylesheets/code_sync/editor/asset-selector.css.scss +58 -0
  91. data/lib/assets/stylesheets/code_sync/editor/codesync-color-picker.css.sass +5 -0
  92. data/lib/assets/stylesheets/code_sync/editor/document-tabs.css.scss +61 -0
  93. data/lib/assets/stylesheets/code_sync/editor/element-sync.css.scss +72 -0
  94. data/lib/assets/stylesheets/code_sync/editor/mode-selector.css.scss +0 -0
  95. data/lib/assets/stylesheets/code_sync/editor/preferences-panel.css.scss +26 -0
  96. data/lib/assets/stylesheets/code_sync/index.css.scss +141 -0
  97. data/lib/assets/stylesheets/demos.css.scss +96 -0
  98. data/lib/assets/stylesheets/marketing.css.sass +46 -0
  99. data/lib/assets/stylesheets/marketing/syntax.css.scss +1 -0
  100. data/lib/assets/stylesheets/vendor/animate.css +1 -0
  101. data/lib/assets/stylesheets/vendor/codemirror-ambiance.css +75 -0
  102. data/lib/assets/stylesheets/vendor/codemirror-lesserdark.css +44 -0
  103. data/lib/assets/stylesheets/vendor/codemirror-monokai.css +28 -0
  104. data/lib/assets/stylesheets/vendor/codemirror-xq-light.css +43 -0
  105. data/lib/assets/stylesheets/vendor/grid-layout.css +1406 -0
  106. data/lib/assets/stylesheets/vendor/spectrum.css +481 -0
  107. data/lib/assets/stylesheets/vendor/vendored_codemirror.css +246 -0
  108. data/lib/code_sync.rb +41 -0
  109. data/lib/code_sync/cli.rb +73 -0
  110. data/lib/code_sync/manager.rb +238 -0
  111. data/lib/code_sync/processors.rb +18 -0
  112. data/lib/code_sync/processors/basic.rb +9 -0
  113. data/lib/code_sync/processors/jst_processor.rb +17 -0
  114. data/lib/code_sync/pry_console.rb +132 -0
  115. data/lib/code_sync/rails.rb +7 -0
  116. data/lib/code_sync/rails/engine.rb +12 -0
  117. data/lib/code_sync/server.rb +225 -0
  118. data/lib/code_sync/sprockets_adapter.rb +145 -0
  119. data/lib/code_sync/temp_asset.rb +20 -0
  120. data/lib/code_sync/version.rb +3 -0
  121. data/lib/middleman_extension.rb +43 -0
  122. data/readme.md +26 -0
  123. data/site/.gitignore +14 -0
  124. data/site/Gemfile +13 -0
  125. data/site/Gemfile.lock +183 -0
  126. data/site/config.rb +26 -0
  127. data/site/source/canvas.html.slim +21 -0
  128. data/site/source/codepen-style-demo.html.slim +21 -0
  129. data/site/source/demo.html.slim +30 -0
  130. data/site/source/index.html.slim +128 -0
  131. data/site/source/layouts/layout.slim +18 -0
  132. data/site/source/samples/_client.html.md +13 -0
  133. data/site/source/samples/_editor.html.md +19 -0
  134. data/site/source/samples/_hooks.html.md +8 -0
  135. data/site/source/samples/_middleman.html.md +7 -0
  136. data/site/source/samples/_rails.html.md +8 -0
  137. data/site/source/samples/_standalone.html.md +36 -0
  138. data/spec/lib/code_sync/sprockets_adapter_spec.rb +44 -0
  139. data/spec/spec_helper.rb +21 -0
  140. data/spec/support/.DS_Store +0 -0
  141. data/spec/support/dummy_middleman/.gitignore +14 -0
  142. data/spec/support/dummy_middleman/Gemfile +5 -0
  143. data/spec/support/dummy_middleman/Gemfile.lock +100 -0
  144. data/spec/support/dummy_middleman/config.rb +77 -0
  145. data/spec/support/dummy_middleman/source/images/background.png +0 -0
  146. data/spec/support/dummy_middleman/source/images/middleman.png +0 -0
  147. data/spec/support/dummy_middleman/source/index.html.erb +10 -0
  148. data/spec/support/dummy_middleman/source/javascripts/all.js +1 -0
  149. data/spec/support/dummy_middleman/source/layouts/layout.erb +19 -0
  150. data/spec/support/dummy_middleman/source/stylesheets/all.css +55 -0
  151. data/spec/support/dummy_middleman/source/stylesheets/normalize.css +375 -0
  152. data/spec/support/dummy_rails/.gitignore +15 -0
  153. data/spec/support/dummy_rails/Gemfile +38 -0
  154. data/spec/support/dummy_rails/Gemfile.lock +112 -0
  155. data/spec/support/dummy_rails/README.rdoc +261 -0
  156. data/spec/support/dummy_rails/Rakefile +7 -0
  157. data/spec/support/dummy_rails/app/assets/images/rails.png +0 -0
  158. data/spec/support/dummy_rails/app/assets/javascripts/application.js +15 -0
  159. data/spec/support/dummy_rails/app/assets/stylesheets/application.css +13 -0
  160. data/spec/support/dummy_rails/app/controllers/application_controller.rb +3 -0
  161. data/spec/support/dummy_rails/app/helpers/application_helper.rb +2 -0
  162. data/spec/support/dummy_rails/app/mailers/.gitkeep +0 -0
  163. data/spec/support/dummy_rails/app/models/.gitkeep +0 -0
  164. data/spec/support/dummy_rails/app/views/layouts/application.html.erb +14 -0
  165. data/spec/support/dummy_rails/config.ru +4 -0
  166. data/spec/support/dummy_rails/config/application.rb +62 -0
  167. data/spec/support/dummy_rails/config/boot.rb +6 -0
  168. data/spec/support/dummy_rails/config/database.yml +25 -0
  169. data/spec/support/dummy_rails/config/environment.rb +5 -0
  170. data/spec/support/dummy_rails/config/environments/development.rb +37 -0
  171. data/spec/support/dummy_rails/config/environments/production.rb +67 -0
  172. data/spec/support/dummy_rails/config/environments/test.rb +37 -0
  173. data/spec/support/dummy_rails/config/initializers/backtrace_silencers.rb +7 -0
  174. data/spec/support/dummy_rails/config/initializers/inflections.rb +15 -0
  175. data/spec/support/dummy_rails/config/initializers/mime_types.rb +5 -0
  176. data/spec/support/dummy_rails/config/initializers/secret_token.rb +7 -0
  177. data/spec/support/dummy_rails/config/initializers/session_store.rb +8 -0
  178. data/spec/support/dummy_rails/config/initializers/wrap_parameters.rb +14 -0
  179. data/spec/support/dummy_rails/config/locales/en.yml +5 -0
  180. data/spec/support/dummy_rails/config/routes.rb +58 -0
  181. data/spec/support/dummy_rails/db/seeds.rb +7 -0
  182. data/spec/support/dummy_rails/doc/README_FOR_APP +2 -0
  183. data/spec/support/dummy_rails/lib/assets/.gitkeep +0 -0
  184. data/spec/support/dummy_rails/lib/tasks/.gitkeep +0 -0
  185. data/spec/support/dummy_rails/log/.gitkeep +0 -0
  186. data/spec/support/dummy_rails/public/404.html +26 -0
  187. data/spec/support/dummy_rails/public/422.html +26 -0
  188. data/spec/support/dummy_rails/public/500.html +25 -0
  189. data/spec/support/dummy_rails/public/favicon.ico +0 -0
  190. data/spec/support/dummy_rails/public/index.html +241 -0
  191. data/spec/support/dummy_rails/public/robots.txt +5 -0
  192. data/spec/support/dummy_rails/script/rails +6 -0
  193. data/spec/support/dummy_rails/test/fixtures/.gitkeep +0 -0
  194. data/spec/support/dummy_rails/test/functional/.gitkeep +0 -0
  195. data/spec/support/dummy_rails/test/integration/.gitkeep +0 -0
  196. data/spec/support/dummy_rails/test/performance/browsing_test.rb +12 -0
  197. data/spec/support/dummy_rails/test/test_helper.rb +13 -0
  198. data/spec/support/dummy_rails/test/unit/.gitkeep +0 -0
  199. data/spec/support/dummy_rails/vendor/assets/javascripts/.gitkeep +0 -0
  200. data/spec/support/dummy_rails/vendor/assets/stylesheets/.gitkeep +0 -0
  201. data/spec/support/dummy_rails/vendor/plugins/.gitkeep +0 -0
  202. data/spec/support/dummy_static/.DS_Store +0 -0
  203. data/spec/support/dummy_static/app/.DS_Store +0 -0
  204. data/spec/support/dummy_static/app/assets/.DS_Store +0 -0
  205. data/spec/support/dummy_static/app/assets/javascripts/manifest.coffee +4 -0
  206. data/spec/support/dummy_static/app/assets/javascripts/spec_application_javascript.coffee +4 -0
  207. data/spec/support/dummy_static/app/assets/stylesheets/spec_application_stylesheet.css.scss +5 -0
  208. data/spec/support/dummy_static/lib/assets/javascripts/spec_library_javascript.coffee +3 -0
  209. data/spec/support/dummy_static/lib/assets/stylesheets/spec_library_stylesheet.css.scss +5 -0
  210. data/spec/support/dummy_static/vendor/assets/javascripts/spec_vendor_javascript.js +5 -0
  211. data/spec/support/dummy_static/vendor/assets/stylesheets/spec_vendor_stylesheets.css +3 -0
  212. data/vendor/assets/stylesheets/code_sync.css +1 -0
  213. metadata +492 -0
@@ -0,0 +1,328 @@
1
+ CodeMirror.defineMode("xml", function(config, parserConfig) {
2
+ var indentUnit = config.indentUnit;
3
+ var multilineTagIndentFactor = parserConfig.multilineTagIndentFactor || 1;
4
+
5
+ var Kludges = parserConfig.htmlMode ? {
6
+ autoSelfClosers: {'area': true, 'base': true, 'br': true, 'col': true, 'command': true,
7
+ 'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true,
8
+ 'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true,
9
+ 'track': true, 'wbr': true},
10
+ implicitlyClosed: {'dd': true, 'li': true, 'optgroup': true, 'option': true, 'p': true,
11
+ 'rp': true, 'rt': true, 'tbody': true, 'td': true, 'tfoot': true,
12
+ 'th': true, 'tr': true},
13
+ contextGrabbers: {
14
+ 'dd': {'dd': true, 'dt': true},
15
+ 'dt': {'dd': true, 'dt': true},
16
+ 'li': {'li': true},
17
+ 'option': {'option': true, 'optgroup': true},
18
+ 'optgroup': {'optgroup': true},
19
+ 'p': {'address': true, 'article': true, 'aside': true, 'blockquote': true, 'dir': true,
20
+ 'div': true, 'dl': true, 'fieldset': true, 'footer': true, 'form': true,
21
+ 'h1': true, 'h2': true, 'h3': true, 'h4': true, 'h5': true, 'h6': true,
22
+ 'header': true, 'hgroup': true, 'hr': true, 'menu': true, 'nav': true, 'ol': true,
23
+ 'p': true, 'pre': true, 'section': true, 'table': true, 'ul': true},
24
+ 'rp': {'rp': true, 'rt': true},
25
+ 'rt': {'rp': true, 'rt': true},
26
+ 'tbody': {'tbody': true, 'tfoot': true},
27
+ 'td': {'td': true, 'th': true},
28
+ 'tfoot': {'tbody': true},
29
+ 'th': {'td': true, 'th': true},
30
+ 'thead': {'tbody': true, 'tfoot': true},
31
+ 'tr': {'tr': true}
32
+ },
33
+ doNotIndent: {"pre": true},
34
+ allowUnquoted: true,
35
+ allowMissing: true
36
+ } : {
37
+ autoSelfClosers: {},
38
+ implicitlyClosed: {},
39
+ contextGrabbers: {},
40
+ doNotIndent: {},
41
+ allowUnquoted: false,
42
+ allowMissing: false
43
+ };
44
+ var alignCDATA = parserConfig.alignCDATA;
45
+
46
+ // Return variables for tokenizers
47
+ var tagName, type;
48
+
49
+ function inText(stream, state) {
50
+ function chain(parser) {
51
+ state.tokenize = parser;
52
+ return parser(stream, state);
53
+ }
54
+
55
+ var ch = stream.next();
56
+ if (ch == "<") {
57
+ if (stream.eat("!")) {
58
+ if (stream.eat("[")) {
59
+ if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));
60
+ else return null;
61
+ }
62
+ else if (stream.match("--")) return chain(inBlock("comment", "-->"));
63
+ else if (stream.match("DOCTYPE", true, true)) {
64
+ stream.eatWhile(/[\w\._\-]/);
65
+ return chain(doctype(1));
66
+ }
67
+ else return null;
68
+ }
69
+ else if (stream.eat("?")) {
70
+ stream.eatWhile(/[\w\._\-]/);
71
+ state.tokenize = inBlock("meta", "?>");
72
+ return "meta";
73
+ }
74
+ else {
75
+ var isClose = stream.eat("/");
76
+ tagName = "";
77
+ var c;
78
+ while ((c = stream.eat(/[^\s\u00a0=<>\"\'\/?]/))) tagName += c;
79
+ if (!tagName) return "error";
80
+ type = isClose ? "closeTag" : "openTag";
81
+ state.tokenize = inTag;
82
+ return "tag";
83
+ }
84
+ }
85
+ else if (ch == "&") {
86
+ var ok;
87
+ if (stream.eat("#")) {
88
+ if (stream.eat("x")) {
89
+ ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";");
90
+ } else {
91
+ ok = stream.eatWhile(/[\d]/) && stream.eat(";");
92
+ }
93
+ } else {
94
+ ok = stream.eatWhile(/[\w\.\-:]/) && stream.eat(";");
95
+ }
96
+ return ok ? "atom" : "error";
97
+ }
98
+ else {
99
+ stream.eatWhile(/[^&<]/);
100
+ return null;
101
+ }
102
+ }
103
+
104
+ function inTag(stream, state) {
105
+ var ch = stream.next();
106
+ if (ch == ">" || (ch == "/" && stream.eat(">"))) {
107
+ state.tokenize = inText;
108
+ type = ch == ">" ? "endTag" : "selfcloseTag";
109
+ return "tag";
110
+ }
111
+ else if (ch == "=") {
112
+ type = "equals";
113
+ return null;
114
+ }
115
+ else if (/[\'\"]/.test(ch)) {
116
+ state.tokenize = inAttribute(ch);
117
+ return state.tokenize(stream, state);
118
+ }
119
+ else {
120
+ stream.eatWhile(/[^\s\u00a0=<>\"\']/);
121
+ return "word";
122
+ }
123
+ }
124
+
125
+ function inAttribute(quote) {
126
+ return function(stream, state) {
127
+ while (!stream.eol()) {
128
+ if (stream.next() == quote) {
129
+ state.tokenize = inTag;
130
+ break;
131
+ }
132
+ }
133
+ return "string";
134
+ };
135
+ }
136
+
137
+ function inBlock(style, terminator) {
138
+ return function(stream, state) {
139
+ while (!stream.eol()) {
140
+ if (stream.match(terminator)) {
141
+ state.tokenize = inText;
142
+ break;
143
+ }
144
+ stream.next();
145
+ }
146
+ return style;
147
+ };
148
+ }
149
+ function doctype(depth) {
150
+ return function(stream, state) {
151
+ var ch;
152
+ while ((ch = stream.next()) != null) {
153
+ if (ch == "<") {
154
+ state.tokenize = doctype(depth + 1);
155
+ return state.tokenize(stream, state);
156
+ } else if (ch == ">") {
157
+ if (depth == 1) {
158
+ state.tokenize = inText;
159
+ break;
160
+ } else {
161
+ state.tokenize = doctype(depth - 1);
162
+ return state.tokenize(stream, state);
163
+ }
164
+ }
165
+ }
166
+ return "meta";
167
+ };
168
+ }
169
+
170
+ var curState, curStream, setStyle;
171
+ function pass() {
172
+ for (var i = arguments.length - 1; i >= 0; i--) curState.cc.push(arguments[i]);
173
+ }
174
+ function cont() {
175
+ pass.apply(null, arguments);
176
+ return true;
177
+ }
178
+
179
+ function pushContext(tagName, startOfLine) {
180
+ var noIndent = Kludges.doNotIndent.hasOwnProperty(tagName) || (curState.context && curState.context.noIndent);
181
+ curState.context = {
182
+ prev: curState.context,
183
+ tagName: tagName,
184
+ indent: curState.indented,
185
+ startOfLine: startOfLine,
186
+ noIndent: noIndent
187
+ };
188
+ }
189
+ function popContext() {
190
+ if (curState.context) curState.context = curState.context.prev;
191
+ }
192
+
193
+ function element(type) {
194
+ if (type == "openTag") {
195
+ curState.tagName = tagName;
196
+ curState.tagStart = curStream.column();
197
+ return cont(attributes, endtag(curState.startOfLine));
198
+ } else if (type == "closeTag") {
199
+ var err = false;
200
+ if (curState.context) {
201
+ if (curState.context.tagName != tagName) {
202
+ if (Kludges.implicitlyClosed.hasOwnProperty(curState.context.tagName.toLowerCase())) {
203
+ popContext();
204
+ }
205
+ err = !curState.context || curState.context.tagName != tagName;
206
+ }
207
+ } else {
208
+ err = true;
209
+ }
210
+ if (err) setStyle = "error";
211
+ return cont(endclosetag(err));
212
+ }
213
+ return cont();
214
+ }
215
+ function endtag(startOfLine) {
216
+ return function(type) {
217
+ var tagName = curState.tagName;
218
+ curState.tagName = curState.tagStart = null;
219
+ if (type == "selfcloseTag" ||
220
+ (type == "endTag" && Kludges.autoSelfClosers.hasOwnProperty(tagName.toLowerCase()))) {
221
+ maybePopContext(tagName.toLowerCase());
222
+ return cont();
223
+ }
224
+ if (type == "endTag") {
225
+ maybePopContext(tagName.toLowerCase());
226
+ pushContext(tagName, startOfLine);
227
+ return cont();
228
+ }
229
+ return cont();
230
+ };
231
+ }
232
+ function endclosetag(err) {
233
+ return function(type) {
234
+ if (err) setStyle = "error";
235
+ if (type == "endTag") { popContext(); return cont(); }
236
+ setStyle = "error";
237
+ return cont(arguments.callee);
238
+ };
239
+ }
240
+ function maybePopContext(nextTagName) {
241
+ var parentTagName;
242
+ while (true) {
243
+ if (!curState.context) {
244
+ return;
245
+ }
246
+ parentTagName = curState.context.tagName.toLowerCase();
247
+ if (!Kludges.contextGrabbers.hasOwnProperty(parentTagName) ||
248
+ !Kludges.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) {
249
+ return;
250
+ }
251
+ popContext();
252
+ }
253
+ }
254
+
255
+ function attributes(type) {
256
+ if (type == "word") {setStyle = "attribute"; return cont(attribute, attributes);}
257
+ if (type == "endTag" || type == "selfcloseTag") return pass();
258
+ setStyle = "error";
259
+ return cont(attributes);
260
+ }
261
+ function attribute(type) {
262
+ if (type == "equals") return cont(attvalue, attributes);
263
+ if (!Kludges.allowMissing) setStyle = "error";
264
+ else if (type == "word") setStyle = "attribute";
265
+ return (type == "endTag" || type == "selfcloseTag") ? pass() : cont();
266
+ }
267
+ function attvalue(type) {
268
+ if (type == "string") return cont(attvaluemaybe);
269
+ if (type == "word" && Kludges.allowUnquoted) {setStyle = "string"; return cont();}
270
+ setStyle = "error";
271
+ return (type == "endTag" || type == "selfCloseTag") ? pass() : cont();
272
+ }
273
+ function attvaluemaybe(type) {
274
+ if (type == "string") return cont(attvaluemaybe);
275
+ else return pass();
276
+ }
277
+
278
+ return {
279
+ startState: function() {
280
+ return {tokenize: inText, cc: [], indented: 0, startOfLine: true, tagName: null, tagStart: null, context: null};
281
+ },
282
+
283
+ token: function(stream, state) {
284
+ if (!state.tagName && stream.sol()) {
285
+ state.startOfLine = true;
286
+ state.indented = stream.indentation();
287
+ }
288
+ if (stream.eatSpace()) return null;
289
+
290
+ setStyle = type = tagName = null;
291
+ var style = state.tokenize(stream, state);
292
+ state.type = type;
293
+ if ((style || type) && style != "comment") {
294
+ curState = state; curStream = stream;
295
+ while (true) {
296
+ var comb = state.cc.pop() || element;
297
+ if (comb(type || style)) break;
298
+ }
299
+ }
300
+ state.startOfLine = false;
301
+ return setStyle || style;
302
+ },
303
+
304
+ indent: function(state, textAfter, fullLine) {
305
+ var context = state.context;
306
+ if ((state.tokenize != inTag && state.tokenize != inText) ||
307
+ context && context.noIndent)
308
+ return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0;
309
+ if (state.tagName) return state.tagStart + indentUnit * multilineTagIndentFactor;
310
+ if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
311
+ if (context && /^<\//.test(textAfter))
312
+ context = context.prev;
313
+ while (context && !context.startOfLine)
314
+ context = context.prev;
315
+ if (context) return context.indent + indentUnit;
316
+ else return 0;
317
+ },
318
+
319
+ electricChars: "/",
320
+
321
+ configuration: parserConfig.htmlMode ? "html" : "xml"
322
+ };
323
+ });
324
+
325
+ CodeMirror.defineMIME("text/xml", "xml");
326
+ CodeMirror.defineMIME("application/xml", "xml");
327
+ if (!CodeMirror.mimeModes.hasOwnProperty("text/html"))
328
+ CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});
@@ -0,0 +1,339 @@
1
+ (function($) {
2
+
3
+ /* AnsiParse */
4
+ ansiparse = function (str) {
5
+ //
6
+ // I'm terrible at writing parsers.
7
+ //
8
+ var matchingControl = null,
9
+ matchingData = null,
10
+ matchingText = '',
11
+ ansiState = [],
12
+ result = [],
13
+ state = {},
14
+ eraseChar;
15
+
16
+ //
17
+ // General workflow for this thing is:
18
+ // \033\[33mText
19
+ // | | |
20
+ // | | matchingText
21
+ // | matchingData
22
+ // matchingControl
23
+ //
24
+ // In further steps we hope it's all going to be fine. It usually is.
25
+ //
26
+
27
+ //
28
+ // Erases a char from the output
29
+ //
30
+ eraseChar = function () {
31
+ var index, text;
32
+ if (matchingText.length) {
33
+ matchingText = matchingText.substr(0, matchingText.length - 1);
34
+ }
35
+ else if (result.length) {
36
+ index = result.length - 1;
37
+ text = result[index].text;
38
+ if (text.length === 1) {
39
+ //
40
+ // A result bit was fully deleted, pop it out to simplify the final output
41
+ //
42
+ result.pop();
43
+ }
44
+ else {
45
+ result[index].text = text.substr(0, text.length - 1);
46
+ }
47
+ }
48
+ };
49
+
50
+ for (var i = 0; i < str.length; i++) {
51
+ if (matchingControl != null) {
52
+ if (matchingControl == '\u001B' && str[i] == '\[') {
53
+ //
54
+ // We've matched full control code. Lets start matching formating data.
55
+ //
56
+
57
+ //
58
+ // "emit" matched text with correct state
59
+ //
60
+ if (matchingText) {
61
+ state.text = matchingText;
62
+ result.push(state);
63
+ state = {};
64
+ matchingText = "";
65
+ }
66
+
67
+ matchingControl = null;
68
+ matchingData = '';
69
+ }
70
+ else {
71
+ //
72
+ // We failed to match anything - most likely a bad control code. We
73
+ // go back to matching regular strings.
74
+ //
75
+ matchingText += matchingControl + str[i];
76
+ matchingControl = null;
77
+ }
78
+ continue;
79
+ }
80
+ else if (matchingData != null) {
81
+ if (str[i] == ';') {
82
+ //
83
+ // `;` separates many formatting codes, for example: `\033[33;43m`
84
+ // means that both `33` and `43` should be applied.
85
+ //
86
+ // TODO: this can be simplified by modifying state here.
87
+ //
88
+ ansiState.push(matchingData);
89
+ matchingData = '';
90
+ }
91
+ else if (str[i] == 'm') {
92
+ //
93
+ // `m` finished whole formatting code. We can proceed to matching
94
+ // formatted text.
95
+ //
96
+ ansiState.push(matchingData);
97
+ matchingData = null;
98
+ matchingText = '';
99
+
100
+ //
101
+ // Convert matched formatting data into user-friendly state object.
102
+ //
103
+ // TODO: DRY.
104
+ //
105
+ ansiState.forEach(function (ansiCode) {
106
+ if (ansiparse.foregroundColors[ansiCode]) {
107
+ state.foreground = ansiparse.foregroundColors[ansiCode];
108
+ }
109
+ else if (ansiparse.backgroundColors[ansiCode]) {
110
+ state.background = ansiparse.backgroundColors[ansiCode];
111
+ }
112
+ else if (ansiCode == 39) {
113
+ delete state.foreground;
114
+ }
115
+ else if (ansiCode == 49) {
116
+ delete state.background;
117
+ }
118
+ else if (ansiparse.styles[ansiCode]) {
119
+ state[ansiparse.styles[ansiCode]] = true;
120
+ }
121
+ else if (ansiCode == 22) {
122
+ state.bold = false;
123
+ }
124
+ else if (ansiCode == 23) {
125
+ state.italic = false;
126
+ }
127
+ else if (ansiCode == 24) {
128
+ state.underline = false;
129
+ }
130
+ });
131
+ ansiState = [];
132
+ }
133
+ else {
134
+ matchingData += str[i];
135
+ }
136
+ continue;
137
+ }
138
+
139
+ if (str[i] == '\u001B') {
140
+ matchingControl = str[i];
141
+ }
142
+ else if (str[i] == '\u0008') {
143
+ eraseChar();
144
+ }
145
+ else {
146
+ matchingText += str[i];
147
+ }
148
+ }
149
+
150
+ if (matchingText) {
151
+ state.text = matchingText + (matchingControl ? matchingControl : '');
152
+ result.push(state);
153
+ }
154
+ return result;
155
+ }
156
+
157
+ ansiparse.foregroundColors = {
158
+ '30': 'black',
159
+ '31': 'red',
160
+ '32': 'green',
161
+ '33': 'yellow',
162
+ '34': 'blue',
163
+ '35': 'magenta',
164
+ '36': 'cyan',
165
+ '37': 'white',
166
+ '90': 'grey'
167
+ };
168
+
169
+ ansiparse.backgroundColors = {
170
+ '40': 'black',
171
+ '41': 'red',
172
+ '42': 'green',
173
+ '43': 'yellow',
174
+ '44': 'blue',
175
+ '45': 'magenta',
176
+ '46': 'cyan',
177
+ '47': 'white'
178
+ };
179
+
180
+ ansiparse.styles = {
181
+ '1': 'bold',
182
+ '3': 'italic',
183
+ '4': 'underline'
184
+ };
185
+
186
+ if (typeof module == "object" && typeof window == "undefined") {
187
+ module.exports = ansiparse;
188
+ }
189
+
190
+ /* app */
191
+ var webconsole = {
192
+ history:[],
193
+ pointer:0,
194
+ query:$('#webconsole_query')
195
+ }
196
+
197
+ $('#rack-webconsole form').submit(function(e){
198
+ console.log("prevent default submit on for")
199
+ e.preventDefault();
200
+ });
201
+
202
+ // colors
203
+ var colors = {
204
+ 'black': "#eeeeee",
205
+ 'red': "#ff6c60",
206
+ 'green': "#a8ff60",
207
+ 'yellow': "#ffffb6",
208
+ 'blue': "#96cbfe",
209
+ 'magenta': "#ff73fd",
210
+ 'cyan': "#c6c5fe",
211
+ 'white': "#eeeeee"
212
+ }
213
+ var boldColors = {
214
+ 'black': "#7c7c7c",
215
+ 'red': "#ffb6b0",
216
+ 'green': "#ceffac",
217
+ 'yellow': "#ffffcb",
218
+ 'blue': "#b5dcfe",
219
+ 'magenta': "#ff9cfe",
220
+ 'cyan': "#dfdffe",
221
+ 'white': "#ffffff"
222
+ }
223
+
224
+ function subColor(color, elem)
225
+ {
226
+ if (color == undefined) color = 'white';
227
+ if (elem.bold && boldColors[color] != undefined) {
228
+ color = boldColors[color];
229
+ } else if (!elem.bold && colors[color] != undefined) {
230
+ color = colors[color];
231
+ }
232
+ return color;
233
+ }
234
+ function parseBashString(str, into)
235
+ {
236
+ $.each(ansiparse(str), function(idx, elem) {
237
+ if (elem.text.length == 1 && elem.text[0] == '\n') {
238
+ into.append("<br>");
239
+ return true;
240
+ }
241
+ var domElem = $('<span></span>');
242
+ domElem.text(elem.text);
243
+ domElem.html(domElem.text().replace(/\n/g, "<br>"));
244
+ domElem.css('color', subColor(elem.foreground, elem));
245
+ if (elem.bold)
246
+ domElem.css('font-weight', 'bold');
247
+ if (elem.italic)
248
+ domElem.css('font-style', 'italic');
249
+ if (elem.underline)
250
+ domElem.css('text-decoration', 'underline');
251
+ if (elem.background)
252
+ domElem.css('background-color', subColor(elem.background, elem));
253
+ into.append(domElem);
254
+ });
255
+ }
256
+ $("#rack-webconsole form input").keyup(function(event) {
257
+ function escapeHTML(string) {
258
+ return(string.replace(/&/g,'&amp;').
259
+ replace(/>/g,'&gt;').
260
+ replace(/</g,'&lt;').
261
+ replace(/"/g,'&quot;')
262
+ );
263
+ };
264
+
265
+ // enter
266
+ if (event.which == 13) {
267
+ webconsole.history.push(webconsole.query.val());
268
+ webconsole.pointer = webconsole.history.length - 1;
269
+ $.ajax({
270
+ url: CodeSync.get("consolePath"),
271
+ type: 'POST',
272
+ dataType: 'json',
273
+ data: ({query: webconsole.query.val(), token: "$TOKEN"}),
274
+ success: function (data) {
275
+ console.log("data",data);
276
+ var query_class = data.previous_multi_line ? 'query_multiline' : 'query';
277
+ var result = $("<div class='" + query_class + "'></div>");
278
+ parseBashString(escapeHTML(data.prompt), result);
279
+ if (!data.multi_line) {
280
+ var mresult = $("<div class='result'></div>");
281
+ parseBashString(escapeHTML(data.result), mresult);
282
+ result.append(mresult);
283
+ }
284
+ $("#rack-webconsole .results").append(result);
285
+ $("#rack-webconsole .results_wrapper").scrollTop(
286
+ $("#rack-webconsole .results").height()
287
+ );
288
+ }
289
+ });
290
+ webconsole.query.val('');
291
+ }
292
+
293
+ // up
294
+ if (event.which == 38) {
295
+ if (webconsole.pointer < 0) {
296
+ webconsole.query.val('');
297
+ } else {
298
+ if (webconsole.pointer == webconsole.history.length) {
299
+ webconsole.pointer = webconsole.history.length - 1;
300
+ }
301
+ webconsole.query.val(webconsole.history[webconsole.pointer]);
302
+ webconsole.pointer--;
303
+ }
304
+ }
305
+
306
+ // down
307
+ if (event.which == 40) {
308
+ if (webconsole.pointer == webconsole.history.length) {
309
+ webconsole.query.val('');
310
+ } else {
311
+ if (webconsole.pointer < 0) {
312
+ webconsole.pointer = 0;
313
+ }
314
+ webconsole.query.val(webconsole.history[webconsole.pointer]);
315
+ webconsole.pointer++;
316
+ }
317
+ }
318
+
319
+ });
320
+
321
+ $(document).ready(function() {
322
+ $(this).keypress(function(event) {
323
+
324
+ if ($KEY_CODE.indexOf(event.which) >= 0) {
325
+ $("#rack-webconsole").slideToggle('fast', function() {
326
+ if ($(this).is(':visible')) {
327
+ $("#rack-webconsole form input").focus();
328
+ $("#rack-webconsole .results_wrapper").scrollTop(
329
+ $("#rack-webconsole .results").height()
330
+ );
331
+ } else {
332
+ $("#rack-webconsole form input").blur();
333
+ }
334
+ });
335
+ event.preventDefault();
336
+ }
337
+ });
338
+ });
339
+ })(jQuery);