luca 0.9.9 → 0.9.42

Sign up to get free protection for your applications and to get access to all the features.
Files changed (604) hide show
  1. data/CHANGELOG +9 -153
  2. data/Gemfile +1 -10
  3. data/Gemfile.lock +40 -113
  4. data/Guardfile +25 -3
  5. data/README.md +57 -54
  6. data/ROADMAP +32 -15
  7. data/Rakefile +75 -24
  8. data/app.rb +46 -12
  9. data/{app/assets → assets}/images/glyphicons-halflings-white.png +0 -0
  10. data/{app/assets → assets}/images/glyphicons-halflings.png +0 -0
  11. data/assets/javascripts/dependencies/backbone-min.js +37 -0
  12. data/assets/javascripts/dependencies/backbone-query.min.js +1 -0
  13. data/assets/javascripts/dependencies/bootstrap.min.js +7 -0
  14. data/{vendor/assets/javascripts → assets/javascripts/dependencies}/codemirror-coffeescript.js +0 -0
  15. data/{vendor/assets/javascripts → assets/javascripts/dependencies}/codemirror-css.js +0 -0
  16. data/{vendor/assets/javascripts → assets/javascripts/dependencies}/codemirror-html.js +0 -0
  17. data/{vendor/assets/javascripts → assets/javascripts/dependencies}/codemirror-javascript.js +0 -0
  18. data/{vendor/assets/javascripts → assets/javascripts/dependencies}/codemirror-less.js +0 -0
  19. data/{vendor/assets/javascripts → assets/javascripts/dependencies}/codemirror-vim.js +0 -0
  20. data/{vendor/assets/javascripts → assets/javascripts/dependencies}/codemirror.js +0 -0
  21. data/assets/javascripts/dependencies/coffee-script.js +12189 -0
  22. data/{spec → assets}/javascripts/dependencies/jasmine-html.js +0 -0
  23. data/{spec → assets}/javascripts/dependencies/jasmine.js +0 -0
  24. data/assets/javascripts/dependencies/jquery.js +4 -0
  25. data/{vendor/assets/javascripts → assets/javascripts/dependencies}/modal.js +0 -0
  26. data/{vendor/assets/javascripts → assets/javascripts/dependencies}/modernizr.min.js +0 -0
  27. data/{vendor/assets/javascripts → assets/javascripts/dependencies}/prettify.js +0 -0
  28. data/{spec → assets}/javascripts/dependencies/sinon.js +0 -0
  29. data/{vendor/assets/javascripts → assets/javascripts/dependencies}/spin-min.js +0 -0
  30. data/assets/javascripts/dependencies/underscore-min.js +31 -0
  31. data/assets/javascripts/dependencies/underscore-string.min.js +14 -0
  32. data/assets/javascripts/dependencies.coffee +5 -0
  33. data/assets/javascripts/luca/index.coffee +1 -0
  34. data/assets/javascripts/luca-templates.js +1 -0
  35. data/assets/javascripts/luca-ui-base.coffee +1 -0
  36. data/assets/javascripts/luca-ui-bootstrap.js +1 -0
  37. data/assets/javascripts/luca-ui-development-tools.coffee +9 -0
  38. data/assets/javascripts/luca-ui-full.js +3 -0
  39. data/assets/javascripts/luca-ui-spec.coffee +2 -0
  40. data/assets/javascripts/luca-ui.js +3 -0
  41. data/assets/javascripts/sandbox/application.coffee +57 -0
  42. data/assets/javascripts/sandbox/config.coffee +7 -0
  43. data/assets/javascripts/sandbox/router.coffee +24 -0
  44. data/assets/javascripts/sandbox/templates/builder/component_list.luca +1 -0
  45. data/assets/javascripts/sandbox/templates/builder.luca +2 -0
  46. data/assets/javascripts/sandbox/templates/main.luca +53 -0
  47. data/assets/javascripts/sandbox/templates/sandbox/docs_index.luca +1 -0
  48. data/assets/javascripts/sandbox/templates/sandbox/navigation.luca +8 -0
  49. data/assets/javascripts/sandbox/templates/sandbox/readme.luca +30 -0
  50. data/assets/javascripts/sandbox/templates/sandbox.luca +1 -0
  51. data/assets/javascripts/sandbox/views/builder/builder_canvas.coffee +3 -0
  52. data/assets/javascripts/sandbox/views/builder/builder_editor.coffee +6 -0
  53. data/assets/javascripts/sandbox/views/builder/component_list.coffee +38 -0
  54. data/assets/javascripts/sandbox/views/builder/project_browser.coffee +14 -0
  55. data/assets/javascripts/sandbox/views/builder.coffee +133 -0
  56. data/assets/javascripts/sandbox/views/docs_controller.coffee +7 -0
  57. data/assets/javascripts/sandbox/views/inspector/instance_filter.coffee +18 -0
  58. data/{app/assets/stylesheets/luca/containers/modal_view.scss → assets/javascripts/sandbox/views/inspector/instance_list.coffee} +0 -0
  59. data/assets/javascripts/sandbox/views/inspector.coffee +11 -0
  60. data/assets/javascripts/sandbox/views/top_navigation.coffee +4 -0
  61. data/assets/javascripts/sandbox.coffee +7 -0
  62. data/assets/javascripts/spec-dependencies.coffee +4 -0
  63. data/assets/stylesheets/bootstrap-responsive.min.css +2 -0
  64. data/assets/stylesheets/bootstrap.min.css +727 -0
  65. data/{vendor/assets → assets}/stylesheets/codemirror-blackboard.css +0 -0
  66. data/{vendor/assets → assets}/stylesheets/codemirror-monokai.css +0 -0
  67. data/{vendor/assets → assets}/stylesheets/codemirror.css +0 -0
  68. data/{vendor/assets → assets}/stylesheets/jasmine.css +0 -0
  69. data/assets/stylesheets/luca-ui-bootstrap.css +4 -0
  70. data/assets/stylesheets/luca-ui-development-tools.css +5 -0
  71. data/assets/stylesheets/luca-ui-full.css +3 -0
  72. data/assets/stylesheets/luca-ui-spec.css +3 -0
  73. data/assets/stylesheets/luca-ui.css +3 -0
  74. data/assets/stylesheets/prettify.css +40 -0
  75. data/assets/stylesheets/sandbox/builder.scss +79 -0
  76. data/assets/stylesheets/sandbox/sandbox.scss +18 -0
  77. data/assets/stylesheets/sandbox.css +3 -0
  78. data/assets/stylesheets/themes/amelia-bootstrap.css +826 -0
  79. data/assets/stylesheets/themes/slate-bootstrap.css +797 -0
  80. data/assets/stylesheets/themes/superhero-bootstrap.css +830 -0
  81. data/config.ru +2 -1
  82. data/docs/{old/application.md → application.md} +0 -0
  83. data/docs/{old/collection.md → collection.md} +0 -0
  84. data/docs/{old/collection_manager.md → collection_manager.md} +0 -0
  85. data/docs/{old/container_philosophy.md → container_philosophy.md} +0 -0
  86. data/docs/{old/event_binding_helpers.md → event_binding_helpers.md} +0 -0
  87. data/docs/{old/method_caching_and_computed_properties.md → method_caching_and_computed_properties.md} +0 -0
  88. data/docs/{old/view.md → view.md} +0 -0
  89. data/lib/luca/code_browser.rb +55 -0
  90. data/lib/luca/command_line.rb +69 -0
  91. data/lib/luca/rails/engine.rb +0 -12
  92. data/lib/luca/rails/version.rb +2 -1
  93. data/lib/luca/rails.rb +3 -5
  94. data/lib/luca/template.rb +0 -2
  95. data/lib/luca.rb +1 -25
  96. data/luca.gemspec +7 -16
  97. data/site/assets/bootstrap.min.js +7 -0
  98. data/site/assets/dependencies.js +94 -0
  99. data/site/assets/glyphicons-halflings-white.png +0 -0
  100. data/site/assets/glyphicons-halflings.png +0 -0
  101. data/site/assets/luca-ui-bootstrap.css +1331 -0
  102. data/site/assets/luca-ui-bootstrap.js +9 -0
  103. data/site/assets/luca-ui-development-tools.css +234 -0
  104. data/site/assets/luca-ui-development-tools.js +18561 -0
  105. data/site/assets/luca-ui-development-tools.min.js +15 -0
  106. data/site/assets/luca-ui-full.min.js +8 -0
  107. data/site/assets/luca-ui.min.js +4 -0
  108. data/site/assets/sandbox.css +62 -0
  109. data/site/assets/sandbox.js +469 -0
  110. data/site/docs/application.html +41 -0
  111. data/site/docs/caching.html +43 -0
  112. data/site/docs/collection.html +75 -0
  113. data/site/docs/collection_manager.html +71 -0
  114. data/site/docs/containers.html +118 -0
  115. data/site/docs/events.html +153 -0
  116. data/site/docs/view.html +128 -0
  117. data/site/img/glyphicons-halflings-white.png +0 -0
  118. data/site/img/glyphicons-halflings.png +0 -0
  119. data/site/index.html +20 -0
  120. data/site/source-map.js +1 -0
  121. data/spec/{javascripts/components → components}/application_spec.coffee +0 -0
  122. data/spec/{javascripts/components → components}/collection_loader_view_spec.coffee +0 -0
  123. data/{site/source/app/assets/javascripts/docs/lib/util.coffee → spec/components/controller_spec.coffee} +0 -0
  124. data/spec/{javascripts/components → components}/fields/checkbox_array_spec.coffee +0 -0
  125. data/spec/components/form_view_spec.coffee +80 -0
  126. data/spec/{javascripts/components → components}/grid_view_spec.coffee +0 -0
  127. data/spec/{javascripts/components → components}/record_manager_spec.coffee +0 -0
  128. data/spec/{javascripts/components → components}/template_spec.coffee +0 -0
  129. data/spec/containers/card_view_spec.coffee +50 -0
  130. data/{site/source/app/assets/javascripts/docs/views/components/code_editor/index.coffee → spec/containers/column_view_spec.coffee} +0 -0
  131. data/spec/{javascripts/containers → containers}/modal_view_spec.coffee +0 -0
  132. data/spec/{javascripts/containers → containers}/panel_view_spec.coffee +0 -0
  133. data/spec/{javascripts/components/pagination_control_spec.coffee → containers/split_view_spec.coffee} +0 -0
  134. data/spec/{javascripts/containers → containers}/tab_view_spec.coffee +0 -0
  135. data/spec/{javascripts/containers → containers}/viewport_spec.coffee +0 -0
  136. data/spec/{javascripts/core → core}/collection_spec.coffee +1 -26
  137. data/spec/core/container_spec.coffee +66 -0
  138. data/spec/{javascripts/concerns/paginatable_spec.coffee → core/field_spec.coffee} +0 -0
  139. data/spec/{javascripts/core → core}/model_spec.coffee +3 -26
  140. data/spec/{javascripts/core → core}/observer_spec.coffee +0 -0
  141. data/spec/{javascripts/core → core}/view_spec.coffee +38 -114
  142. data/spec/{javascripts/core/framework_spec.coffee → framework_spec.coffee} +2 -31
  143. data/spec/{javascripts/helper.coffee → helper.coffee} +0 -0
  144. data/spec/{javascripts/managers → managers}/collection_manager_spec.coffee +0 -0
  145. data/spec/{javascripts/managers → managers}/socket_manager_spec.coffee +0 -0
  146. data/src/components/application.coffee +318 -0
  147. data/src/components/base_toolbar.coffee +15 -0
  148. data/{app/assets/javascripts/luca → src}/components/collection_loader_view.coffee +1 -3
  149. data/src/components/collection_view.coffee +131 -0
  150. data/src/components/controller.coffee +63 -0
  151. data/src/components/fields/button_field.coffee +38 -0
  152. data/{app/assets/javascripts/luca → src}/components/fields/checkbox_array.coffee +7 -18
  153. data/{app/assets/javascripts/luca → src}/components/fields/checkbox_field.coffee +10 -19
  154. data/{app/assets/javascripts/luca → src}/components/fields/file_upload_field.coffee +4 -5
  155. data/src/components/fields/hidden_field.coffee +12 -0
  156. data/src/components/fields/label_field.coffee +14 -0
  157. data/src/components/fields/select_field.coffee +97 -0
  158. data/src/components/fields/text_area_field.coffee +40 -0
  159. data/{app/assets/javascripts/luca → src}/components/fields/text_field.coffee +5 -16
  160. data/src/components/fields/type_ahead_field.coffee +22 -0
  161. data/src/components/form_button_toolbar.coffee +25 -0
  162. data/src/components/form_view.coffee +275 -0
  163. data/src/components/grid_view.coffee +269 -0
  164. data/src/components/index.coffee +1 -0
  165. data/src/components/load_mask.coffee +3 -0
  166. data/src/components/nav_bar.coffee +22 -0
  167. data/src/components/page_controller.coffee +2 -0
  168. data/{app/assets/javascripts/luca → src}/components/record_manager.coffee +0 -0
  169. data/{app/assets/javascripts/luca → src}/components/router.coffee +1 -6
  170. data/src/components/table_view.coffee +53 -0
  171. data/src/components/template.coffee +5 -0
  172. data/src/components/toolbar_dialog.coffee +25 -0
  173. data/src/containers/card_view.coffee +93 -0
  174. data/src/containers/column_view.coffee +42 -0
  175. data/{app/assets/javascripts/luca → src}/containers/modal_view.coffee +9 -9
  176. data/src/containers/page_view.coffee +2 -0
  177. data/{app/assets/javascripts/luca → src}/containers/panel_toolbar.coffee +84 -89
  178. data/src/containers/panel_view.coffee +23 -0
  179. data/src/containers/split_view.coffee +8 -0
  180. data/{app/assets/javascripts/luca → src}/containers/tab_view.coffee +21 -27
  181. data/{app/assets/javascripts/luca → src}/containers/viewport.coffee +18 -14
  182. data/{app/assets/javascripts/luca → src}/core/collection.coffee +51 -97
  183. data/src/core/container.coffee +374 -0
  184. data/{tutorials/component-definitions.md → src/core/core.coffee} +0 -0
  185. data/src/core/field.coffee +79 -0
  186. data/src/core/model.coffee +43 -0
  187. data/{app/assets/javascripts/luca → src}/core/observer.coffee +0 -0
  188. data/src/core/panel.coffee +118 -0
  189. data/{app/assets/javascripts/luca/core/registry → src/core}/registry.coffee +43 -63
  190. data/{app/assets/javascripts/luca/util → src/core}/script_loader.coffee +0 -0
  191. data/src/core/view.coffee +264 -0
  192. data/src/define.coffee +110 -0
  193. data/{app/assets/javascripts/luca → src}/framework.coffee +103 -98
  194. data/src/index.coffee +23 -0
  195. data/{app/assets/javascripts/luca → src}/managers/collection_manager.coffee +13 -37
  196. data/src/managers/socket_manager.coffee +54 -0
  197. data/{app/assets/javascripts/luca/concerns → src/modules}/deferrable.coffee +4 -5
  198. data/src/modules/grid_layout.coffee +3 -0
  199. data/{app/assets/javascripts/luca/concerns/loadmaskable.coffee → src/modules/load_mask.coffee} +11 -23
  200. data/{app/assets/javascripts/luca/concerns → src/modules}/local_storage.coffee +0 -0
  201. data/src/plugins/development_tool_helpers.coffee +21 -0
  202. data/src/plugins/events.coffee +54 -0
  203. data/src/samples/definition.coffee +49 -0
  204. data/{tutorials/component-definitions/01_intro.md → src/stylesheets/base.scss} +0 -0
  205. data/{app/assets/stylesheets/luca → src/stylesheets}/components/checkbox_array.scss +1 -1
  206. data/src/stylesheets/components/form_view.scss +59 -0
  207. data/{app/assets/stylesheets/luca → src/stylesheets}/components/grid_view.scss +0 -0
  208. data/{app/assets/stylesheets/luca → src/stylesheets}/components/load_mask.scss +0 -0
  209. data/src/stylesheets/components/toolbar.scss +0 -0
  210. data/{app/assets/stylesheets/luca → src/stylesheets}/components/viewport.scss +4 -1
  211. data/src/stylesheets/containers/container.scss +16 -0
  212. data/src/stylesheets/containers/modal_view.scss +0 -0
  213. data/{app/assets/stylesheets/luca → src/stylesheets}/containers/panels.scss +0 -0
  214. data/{app/assets/stylesheets/luca → src/stylesheets}/containers/tab_view.scss +5 -5
  215. data/{app/assets/stylesheets/luca → src/stylesheets}/normalize.scss +0 -0
  216. data/src/stylesheets/tools/class_browser.scss +32 -0
  217. data/src/stylesheets/tools/code_editor.scss +24 -0
  218. data/src/stylesheets/tools/component_tester.scss +26 -0
  219. data/{app/assets/stylesheets/luca/development → src/stylesheets/tools}/console.scss +0 -0
  220. data/src/templates/components/bootstrap_form_controls.luca +7 -0
  221. data/src/templates/components/collection_loader_view.luca +5 -0
  222. data/src/templates/components/form_alert +0 -0
  223. data/src/templates/components/form_alert.luca +3 -0
  224. data/src/templates/components/grid_view.luca +7 -0
  225. data/src/templates/components/grid_view_empty_text.luca +3 -0
  226. data/src/templates/components/load_mask.luca +3 -0
  227. data/src/templates/components/nav_bar.luca +2 -0
  228. data/src/templates/containers/basic.luca +1 -0
  229. data/src/templates/containers/tab_selector_container.luca +8 -0
  230. data/src/templates/containers/tab_view.luca +2 -0
  231. data/src/templates/containers/toolbar_wrapper.luca +1 -0
  232. data/src/templates/fields/button_field.luca +2 -0
  233. data/src/templates/fields/button_field_link.luca +5 -0
  234. data/src/templates/fields/checkbox_array.luca +4 -0
  235. data/src/templates/fields/checkbox_array_item.luca +4 -0
  236. data/src/templates/fields/checkbox_field.luca +9 -0
  237. data/src/templates/fields/file_upload_field.luca +8 -0
  238. data/src/templates/fields/hidden_field.luca +1 -0
  239. data/src/templates/fields/select_field.luca +8 -0
  240. data/src/templates/fields/text_area_field.luca +8 -0
  241. data/src/templates/fields/text_field.luca +17 -0
  242. data/src/templates/sample/contents.luca +1 -0
  243. data/src/templates/sample/welcome.luca +1 -0
  244. data/src/templates/table_view.luca +4 -0
  245. data/src/tools/application_inspector.coffee +2 -0
  246. data/src/tools/code_editor.coffee +258 -0
  247. data/{app/assets/javascripts/luca/development → src/tools}/code_mirror_field.coffee +1 -2
  248. data/src/tools/coffee_script_editor.coffee +82 -0
  249. data/src/tools/collection_inspector.coffee +4 -0
  250. data/src/tools/collections/components.coffee +59 -0
  251. data/src/tools/collections/instances.coffee +15 -0
  252. data/src/tools/component_tester.coffee +462 -0
  253. data/{app/assets/javascripts/luca/development → src/tools}/console.coffee +24 -55
  254. data/src/tools/models/components.coffee +25 -0
  255. data/src/tools/models/instance.coffee +2 -0
  256. data/src/tools/templates/component_tester/help.luca +14 -0
  257. data/{app/assets/javascripts/luca/util/luca.coffee → src/util.coffee} +6 -90
  258. data/vendor/assets/javascripts/luca-ui-development-tools.js +18533 -0
  259. data/vendor/assets/javascripts/luca-ui-development-tools.min.js +15 -0
  260. data/vendor/assets/javascripts/luca-ui-full.js +4806 -0
  261. data/vendor/assets/javascripts/luca-ui-full.min.js +8 -0
  262. data/vendor/assets/javascripts/luca-ui-templates.js +24 -0
  263. data/vendor/assets/javascripts/luca-ui.js +1703 -4394
  264. data/vendor/assets/javascripts/luca-ui.min.js +4 -5
  265. data/vendor/assets/luca-ui/base.css +85 -0
  266. data/vendor/assets/luca-ui/components/application.js +91 -0
  267. data/vendor/assets/luca-ui/components/base_toolbar.js +23 -0
  268. data/vendor/assets/luca-ui/components/controller.js +38 -0
  269. data/vendor/assets/luca-ui/components/fields/button_field.js +45 -0
  270. data/vendor/assets/luca-ui/components/fields/checkbox_field.js +43 -0
  271. data/vendor/assets/luca-ui/components/fields/file_upload_field.js +20 -0
  272. data/vendor/assets/luca-ui/components/fields/hidden_field.js +20 -0
  273. data/vendor/assets/luca-ui/components/fields/select_field.js +97 -0
  274. data/vendor/assets/luca-ui/components/fields/text_area_field.js +48 -0
  275. data/vendor/assets/luca-ui/components/fields/text_field.js +46 -0
  276. data/vendor/assets/luca-ui/components/fields/type_ahead_field.js +13 -0
  277. data/vendor/assets/luca-ui/components/form_button_toolbar.js +32 -0
  278. data/vendor/assets/luca-ui/components/form_view.css +32 -0
  279. data/vendor/assets/luca-ui/components/form_view.js +207 -0
  280. data/{app/assets/stylesheets/luca/components/table_view.scss → vendor/assets/luca-ui/components/grid_view.css} +51 -60
  281. data/vendor/assets/luca-ui/components/grid_view.js +202 -0
  282. data/vendor/assets/luca-ui/components/record_manager.js +207 -0
  283. data/vendor/assets/luca-ui/components/router.js +36 -0
  284. data/vendor/assets/luca-ui/components/template.js +26 -0
  285. data/vendor/assets/luca-ui/components/toolbar.css +11 -0
  286. data/vendor/assets/luca-ui/containers/card_view.js +98 -0
  287. data/vendor/assets/luca-ui/containers/column_view.js +52 -0
  288. data/vendor/assets/luca-ui/containers/container.css +3 -0
  289. data/vendor/assets/luca-ui/containers/modal_view.css +0 -0
  290. data/vendor/assets/luca-ui/containers/modal_view.js +87 -0
  291. data/vendor/assets/luca-ui/containers/panel_view.js +34 -0
  292. data/vendor/assets/luca-ui/containers/split_view.js +13 -0
  293. data/vendor/assets/luca-ui/containers/tab_view.css +16 -0
  294. data/vendor/assets/luca-ui/containers/tab_view.js +80 -0
  295. data/vendor/assets/luca-ui/containers/viewport.js +18 -0
  296. data/vendor/assets/luca-ui/core/collection.js +221 -0
  297. data/vendor/assets/luca-ui/core/container.js +205 -0
  298. data/vendor/assets/luca-ui/core/field.js +59 -0
  299. data/vendor/assets/luca-ui/core/observer.js +42 -0
  300. data/vendor/assets/luca-ui/core/view.js +127 -0
  301. data/vendor/assets/luca-ui/framework.js +110 -0
  302. data/vendor/assets/luca-ui/index.js +5 -0
  303. data/vendor/assets/luca-ui/managers/collection_manager.js +98 -0
  304. data/vendor/assets/luca-ui/managers/socket_manager.js +52 -0
  305. data/vendor/assets/luca-ui/modules/deferrable.js +21 -0
  306. data/vendor/assets/luca-ui/modules/local_storage.js +81 -0
  307. data/vendor/assets/luca-ui/normalize.css +359 -0
  308. data/vendor/assets/luca-ui/stylesheets/base.css +85 -0
  309. data/vendor/assets/luca-ui/stylesheets/components/form_view.css +32 -0
  310. data/vendor/assets/luca-ui/stylesheets/components/grid_view.css +76 -0
  311. data/vendor/assets/luca-ui/stylesheets/components/toolbar.css +11 -0
  312. data/vendor/assets/luca-ui/stylesheets/containers/container.css +3 -0
  313. data/vendor/assets/luca-ui/stylesheets/containers/modal_view.css +0 -0
  314. data/vendor/assets/luca-ui/stylesheets/containers/tab_view.css +16 -0
  315. data/vendor/assets/luca-ui/stylesheets/normalize.css +359 -0
  316. data/vendor/assets/luca-ui/templates/components/bootstrap_form_controls.js +4 -0
  317. data/vendor/assets/luca-ui/templates/components/form_view.js +4 -0
  318. data/vendor/assets/luca-ui/templates/components/grid_view.js +4 -0
  319. data/vendor/assets/luca-ui/templates/components/grid_view_empty_text.js +4 -0
  320. data/vendor/assets/luca-ui/templates/containers/basic.js +4 -0
  321. data/vendor/assets/luca-ui/templates/containers/tab_selector_container.js +4 -0
  322. data/vendor/assets/luca-ui/templates/containers/tab_view.js +4 -0
  323. data/vendor/assets/luca-ui/templates/containers/toolbar_wrapper.js +4 -0
  324. data/vendor/assets/luca-ui/templates/fields/button_field.js +4 -0
  325. data/vendor/assets/luca-ui/templates/fields/button_field_link.js +4 -0
  326. data/vendor/assets/luca-ui/templates/fields/checkbox_field.js +4 -0
  327. data/vendor/assets/luca-ui/templates/fields/file_upload_field.js +4 -0
  328. data/vendor/assets/luca-ui/templates/fields/hidden_field.js +4 -0
  329. data/vendor/assets/luca-ui/templates/fields/select_field.js +4 -0
  330. data/vendor/assets/luca-ui/templates/fields/text_area_field.js +4 -0
  331. data/vendor/assets/luca-ui/templates/fields/text_field.js +4 -0
  332. data/vendor/assets/luca-ui/templates/sample/contents.js +4 -0
  333. data/vendor/assets/luca-ui/templates/sample/welcome.js +4 -0
  334. data/vendor/assets/stylesheets/luca-ui.css +471 -68
  335. data/views/jasmine.erb +2 -2
  336. metadata +328 -496
  337. data/app/assets/javascripts/luca/basic.coffee +0 -8
  338. data/app/assets/javascripts/luca/components/application.coffee +0 -530
  339. data/app/assets/javascripts/luca/components/collection_view.coffee +0 -211
  340. data/app/assets/javascripts/luca/components/controller.coffee +0 -176
  341. data/app/assets/javascripts/luca/components/fields/base.coffee +0 -144
  342. data/app/assets/javascripts/luca/components/fields/button_field.coffee +0 -91
  343. data/app/assets/javascripts/luca/components/fields/hidden_field.coffee +0 -11
  344. data/app/assets/javascripts/luca/components/fields/label_field.coffee +0 -12
  345. data/app/assets/javascripts/luca/components/fields/select_field.coffee +0 -159
  346. data/app/assets/javascripts/luca/components/fields/text_area_field.coffee +0 -57
  347. data/app/assets/javascripts/luca/components/fields/type_ahead_field.coffee +0 -20
  348. data/app/assets/javascripts/luca/components/form_view.coffee +0 -421
  349. data/app/assets/javascripts/luca/components/grid_layout_view.coffee +0 -42
  350. data/app/assets/javascripts/luca/components/index.coffee +0 -7
  351. data/app/assets/javascripts/luca/components/load_mask.coffee +0 -8
  352. data/app/assets/javascripts/luca/components/multi_collection_view.coffee +0 -92
  353. data/app/assets/javascripts/luca/components/nav_bar.coffee +0 -80
  354. data/app/assets/javascripts/luca/components/page.coffee +0 -70
  355. data/app/assets/javascripts/luca/components/pagination_control.coffee +0 -104
  356. data/app/assets/javascripts/luca/components/simple_collection_view.coffee +0 -10
  357. data/app/assets/javascripts/luca/components/table_view.coffee +0 -93
  358. data/app/assets/javascripts/luca/components/table_view_scrollable.coffee +0 -23
  359. data/app/assets/javascripts/luca/concerns/application_event_bindings.coffee +0 -19
  360. data/app/assets/javascripts/luca/concerns/collection_event_bindings.coffee +0 -47
  361. data/app/assets/javascripts/luca/concerns/development_tool_helpers.coffee +0 -30
  362. data/app/assets/javascripts/luca/concerns/dom_helpers.coffee +0 -61
  363. data/app/assets/javascripts/luca/concerns/enhanced_properties.coffee +0 -23
  364. data/app/assets/javascripts/luca/concerns/filterable.coffee +0 -101
  365. data/app/assets/javascripts/luca/concerns/form_model_bindings.coffee +0 -20
  366. data/app/assets/javascripts/luca/concerns/grid_layout.coffee +0 -15
  367. data/app/assets/javascripts/luca/concerns/modal_view.coffee +0 -63
  368. data/app/assets/javascripts/luca/concerns/model_presenter.coffee +0 -23
  369. data/app/assets/javascripts/luca/concerns/paginatable.coffee +0 -79
  370. data/app/assets/javascripts/luca/concerns/query_collection_bindings.coffee +0 -52
  371. data/app/assets/javascripts/luca/concerns/sortable.coffee +0 -69
  372. data/app/assets/javascripts/luca/concerns/state_model.coffee +0 -58
  373. data/app/assets/javascripts/luca/concerns/templating.coffee +0 -13
  374. data/app/assets/javascripts/luca/config.coffee +0 -54
  375. data/app/assets/javascripts/luca/containers/card_view.coffee +0 -178
  376. data/app/assets/javascripts/luca/containers/container.coffee +0 -711
  377. data/app/assets/javascripts/luca/containers/index.coffee +0 -2
  378. data/app/assets/javascripts/luca/containers/page_controller.coffee +0 -25
  379. data/app/assets/javascripts/luca/core/events.coffee +0 -114
  380. data/app/assets/javascripts/luca/core/index.coffee +0 -12
  381. data/app/assets/javascripts/luca/core/model.coffee +0 -56
  382. data/app/assets/javascripts/luca/core/panel.coffee +0 -124
  383. data/app/assets/javascripts/luca/core/registry/component_definition.coffee +0 -319
  384. data/app/assets/javascripts/luca/core/registry/concerns.coffee +0 -70
  385. data/app/assets/javascripts/luca/core/registry/index.coffee +0 -4
  386. data/app/assets/javascripts/luca/core/registry/meta_data.coffee +0 -99
  387. data/app/assets/javascripts/luca/core/templates.coffee +0 -51
  388. data/app/assets/javascripts/luca/core/view.coffee +0 -383
  389. data/app/assets/javascripts/luca/dependencies.coffee +0 -9
  390. data/app/assets/javascripts/luca/development/code_sync_manager.coffee +0 -173
  391. data/app/assets/javascripts/luca/development/component.coffee +0 -76
  392. data/app/assets/javascripts/luca/development/components.coffee +0 -57
  393. data/app/assets/javascripts/luca/development/index.coffee +0 -5
  394. data/app/assets/javascripts/luca/index.coffee +0 -9
  395. data/app/assets/javascripts/luca/managers/index.coffee +0 -2
  396. data/app/assets/javascripts/luca/managers/socket_manager.coffee +0 -89
  397. data/app/assets/javascripts/luca/templates/components/bootstrap_form_controls.jst.ejs +0 -10
  398. data/app/assets/javascripts/luca/templates/components/collection_loader_view.jst.ejs +0 -6
  399. data/app/assets/javascripts/luca/templates/components/form_alert.jst.ejs +0 -4
  400. data/app/assets/javascripts/luca/templates/components/grid_view.jst.ejs +0 -11
  401. data/app/assets/javascripts/luca/templates/components/grid_view_empty_text.jst.ejs +0 -3
  402. data/app/assets/javascripts/luca/templates/components/load_mask.jst.ejs +0 -5
  403. data/app/assets/javascripts/luca/templates/components/nav_bar.jst.ejs +0 -19
  404. data/app/assets/javascripts/luca/templates/components/pagination.jst.ejs +0 -10
  405. data/app/assets/javascripts/luca/templates/components/table_view.jst.ejs +0 -4
  406. data/app/assets/javascripts/luca/templates/containers/basic.jst.ejs +0 -1
  407. data/app/assets/javascripts/luca/templates/containers/tab_selector_container.jst.ejs +0 -12
  408. data/app/assets/javascripts/luca/templates/containers/tab_view.jst.ejs +0 -2
  409. data/app/assets/javascripts/luca/templates/containers/toolbar_wrapper.jst.ejs +0 -1
  410. data/app/assets/javascripts/luca/templates/fields/button_field.jst.ejs +0 -2
  411. data/app/assets/javascripts/luca/templates/fields/button_field_link.jst.ejs +0 -6
  412. data/app/assets/javascripts/luca/templates/fields/checkbox_array.jst.ejs +0 -4
  413. data/app/assets/javascripts/luca/templates/fields/checkbox_array_item.jst.ejs +0 -3
  414. data/app/assets/javascripts/luca/templates/fields/checkbox_field.jst.ejs +0 -10
  415. data/app/assets/javascripts/luca/templates/fields/file_upload_field.jst.ejs +0 -10
  416. data/app/assets/javascripts/luca/templates/fields/hidden_field.jst.ejs +0 -1
  417. data/app/assets/javascripts/luca/templates/fields/select_field.jst.ejs +0 -11
  418. data/app/assets/javascripts/luca/templates/fields/text_area_field.jst.ejs +0 -11
  419. data/app/assets/javascripts/luca/templates/fields/text_field.jst.ejs +0 -16
  420. data/app/assets/javascripts/luca/util/deprecations.coffee +0 -18
  421. data/app/assets/javascripts/luca/util/index.coffee +0 -4
  422. data/app/assets/javascripts/luca/util/keybindings.coffee +0 -24
  423. data/app/assets/javascripts/luca/util/logging.coffee +0 -30
  424. data/app/assets/javascripts/luca-ui.js +0 -1
  425. data/app/assets/stylesheets/luca/components/form_view.scss +0 -7
  426. data/app/assets/stylesheets/luca/containers/container.scss +0 -19
  427. data/app/assets/stylesheets/luca/development/index.css +0 -3
  428. data/app/assets/stylesheets/luca/index.css +0 -4
  429. data/bin/luca +0 -14
  430. data/docs/framework.json +0 -1
  431. data/docs/luca-framework-documentation.js +0 -1
  432. data/lib/generators/luca/application/application_generator.rb +0 -75
  433. data/lib/generators/luca/application/templates/controller.rb +0 -4
  434. data/lib/generators/luca/application/templates/index.html.erb +0 -19
  435. data/lib/generators/luca/application/templates/index.html.haml +0 -7
  436. data/lib/generators/luca/application/templates/javascripts/application.coffee +0 -18
  437. data/lib/generators/luca/application/templates/javascripts/collection_manager.coffee +0 -2
  438. data/lib/generators/luca/application/templates/javascripts/config.coffee +0 -3
  439. data/lib/generators/luca/application/templates/javascripts/dependencies.coffee +0 -3
  440. data/lib/generators/luca/application/templates/javascripts/home.jst.ejs +0 -2
  441. data/lib/generators/luca/application/templates/javascripts/index.coffee +0 -15
  442. data/lib/generators/luca/application/templates/javascripts/router.coffee +0 -4
  443. data/lib/guard/luca.rb +0 -84
  444. data/lib/luca/asset_compiler.rb +0 -117
  445. data/lib/luca/cli/generate.rb +0 -37
  446. data/lib/luca/cli/server.rb +0 -20
  447. data/lib/luca/cli/sync.rb +0 -40
  448. data/lib/luca/cli/watch.rb +0 -16
  449. data/lib/luca/cli.rb +0 -68
  450. data/lib/luca/collection/endpoint.rb +0 -38
  451. data/lib/luca/collection/file_backend.rb +0 -121
  452. data/lib/luca/collection/redis_backend.rb +0 -153
  453. data/lib/luca/collection.rb +0 -64
  454. data/lib/luca/compiled_asset.rb +0 -61
  455. data/lib/luca/component_definition.rb +0 -356
  456. data/lib/luca/luca_application.rb +0 -258
  457. data/lib/luca/project.rb +0 -73
  458. data/lib/luca/project_harness.rb +0 -96
  459. data/lib/luca/server.rb +0 -7
  460. data/lib/luca/stylesheet.rb +0 -35
  461. data/lib/luca/template_asset.rb +0 -64
  462. data/lib/luca/version.rb +0 -3
  463. data/lib/luca/watcher.rb +0 -72
  464. data/lib/railties/luca/tasks.rake +0 -38
  465. data/site/.bundle/config +0 -2
  466. data/site/.gitignore +0 -5
  467. data/site/.rvmrc +0 -1
  468. data/site/CHANGELOG.md +0 -41
  469. data/site/DOCS.md +0 -41
  470. data/site/Gemfile +0 -8
  471. data/site/Gemfile.lock +0 -134
  472. data/site/LICENSE.md +0 -19
  473. data/site/config.rb +0 -84
  474. data/site/helpers/site_helpers.rb +0 -20
  475. data/site/html5bp-docs/README.md +0 -38
  476. data/site/html5bp-docs/contribute.md +0 -104
  477. data/site/html5bp-docs/crossdomain.md +0 -21
  478. data/site/html5bp-docs/css.md +0 -135
  479. data/site/html5bp-docs/extend.md +0 -507
  480. data/site/html5bp-docs/faq.md +0 -77
  481. data/site/html5bp-docs/htaccess.md +0 -323
  482. data/site/html5bp-docs/html.md +0 -170
  483. data/site/html5bp-docs/js.md +0 -31
  484. data/site/html5bp-docs/misc.md +0 -25
  485. data/site/html5bp-docs/usage.md +0 -109
  486. data/site/readme.md +0 -47
  487. data/site/source/.htaccess +0 -540
  488. data/site/source/404.html +0 -157
  489. data/site/source/app/assets/javascripts/dependencies.js.coffee +0 -6
  490. data/site/source/app/assets/javascripts/docs/application.coffee +0 -64
  491. data/site/source/app/assets/javascripts/docs/collections/docs_documentation.coffee +0 -17
  492. data/site/source/app/assets/javascripts/docs/collections/github_repositories.coffee +0 -7
  493. data/site/source/app/assets/javascripts/docs/collections/index.coffee +0 -1
  494. data/site/source/app/assets/javascripts/docs/collections/luca_documentation.coffee +0 -17
  495. data/site/source/app/assets/javascripts/docs/collections/public_gists.coffee +0 -4
  496. data/site/source/app/assets/javascripts/docs/config.coffee +0 -5
  497. data/site/source/app/assets/javascripts/docs/index.coffee +0 -12
  498. data/site/source/app/assets/javascripts/docs/lib/router.coffee +0 -3
  499. data/site/source/app/assets/javascripts/docs/models/component.coffee +0 -99
  500. data/site/source/app/assets/javascripts/docs/models/github_repository.coffee +0 -3
  501. data/site/source/app/assets/javascripts/docs/models/index.coffee +0 -1
  502. data/site/source/app/assets/javascripts/docs/templates/component_documentation.jst.ejs +0 -55
  503. data/site/source/app/assets/javascripts/docs/templates/examples_browser/overview.jst.ejs +0 -4
  504. data/site/source/app/assets/javascripts/docs/templates/examples_browser/selector.jst.ejs +0 -11
  505. data/site/source/app/assets/javascripts/docs/templates/github_repository.jst.ejs +0 -4
  506. data/site/source/app/assets/javascripts/docs/templates/layouts/main.jst.ejs +0 -4
  507. data/site/source/app/assets/javascripts/docs/templates/left_navigation.jst.ejs +0 -5
  508. data/site/source/app/assets/javascripts/docs/templates/pages/getting_started.jst.ejs +0 -78
  509. data/site/source/app/assets/javascripts/docs/templates/pages/home.jst.ejs +0 -57
  510. data/site/source/app/assets/javascripts/docs/views/components/code_editor.coffee +0 -45
  511. data/site/source/app/assets/javascripts/docs/views/components/component_documentation.coffee +0 -72
  512. data/site/source/app/assets/javascripts/docs/views/index.coffee +0 -3
  513. data/site/source/app/assets/javascripts/docs/views/pages/browse_source/details.coffee +0 -37
  514. data/site/source/app/assets/javascripts/docs/views/pages/browse_source/list.coffee +0 -31
  515. data/site/source/app/assets/javascripts/docs/views/pages/browse_source.coffee +0 -46
  516. data/site/source/app/assets/javascripts/docs/views/pages/component_editor.coffee +0 -10
  517. data/site/source/app/assets/javascripts/docs/views/pages/examples_browser/docs.coffee +0 -12
  518. data/site/source/app/assets/javascripts/docs/views/pages/examples_browser/source.coffee +0 -13
  519. data/site/source/app/assets/javascripts/docs/views/pages/examples_browser.coffee +0 -102
  520. data/site/source/app/assets/javascripts/docs/views/pages/home.coffee +0 -10
  521. data/site/source/app/assets/javascripts/docs/views/views/api_browser/index.coffee +0 -43
  522. data/site/source/app/assets/javascripts/docs/views/views/collection_view_examples/grid_layout_view_example.coffee +0 -14
  523. data/site/source/app/assets/javascripts/docs/views/views/collection_view_examples/table_view_example.coffee +0 -39
  524. data/site/source/app/assets/javascripts/docs/views/views/form_view_examples/basic_example.coffee +0 -38
  525. data/site/source/app/assets/javascripts/docs/views/views/form_view_examples/complex_layout.coffee +0 -110
  526. data/site/source/app/assets/javascripts/docs/views/views/top_navigation.coffee +0 -6
  527. data/site/source/app/assets/javascripts/docs-docs.js +0 -1
  528. data/site/source/app/assets/javascripts/luca-docs.js +0 -1
  529. data/site/source/app/assets/javascripts/luca-framework-documentation.js +0 -1
  530. data/site/source/app/assets/javascripts/site.js.coffee +0 -4
  531. data/site/source/app/assets/javascripts/vendor/codemirror.js +0 -4786
  532. data/site/source/app/assets/javascripts/vendor/coffeescript.js +0 -346
  533. data/site/source/app/assets/javascripts/vendor/css.js +0 -465
  534. data/site/source/app/assets/javascripts/vendor/htmlmixed.js +0 -84
  535. data/site/source/app/assets/javascripts/vendor/javascript.js +0 -422
  536. data/site/source/app/assets/javascripts/vendor/js-beautify.js +0 -1353
  537. data/site/source/app/assets/javascripts/vendor/modernizr-2.6.1.min.js +0 -4
  538. data/site/source/app/assets/javascripts/vendor/vim.js +0 -2511
  539. data/site/source/app/assets/stylesheets/docs/api-browser.css.scss +0 -5
  540. data/site/source/app/assets/stylesheets/docs/application.css.scss +0 -35
  541. data/site/source/app/assets/stylesheets/docs/browse-source.css.scss +0 -5
  542. data/site/source/app/assets/stylesheets/docs/scrollable-table.css.scss +0 -5
  543. data/site/source/app/assets/stylesheets/site.css.scss +0 -2
  544. data/site/source/app/assets/stylesheets/vendor/codemirror.css +0 -240
  545. data/site/source/app/assets/stylesheets/vendor/prettify-tomorrow-night-bright.css +0 -160
  546. data/site/source/app/assets/stylesheets/vendor/twilight.css +0 -26
  547. data/site/source/crossdomain.xml +0 -15
  548. data/site/source/documentation.html.haml +0 -1
  549. data/site/source/favicon_base.png +0 -0
  550. data/site/source/humans.txt +0 -15
  551. data/site/source/images/background.png +0 -0
  552. data/site/source/images/middleman.png +0 -0
  553. data/site/source/index.html.haml +0 -1
  554. data/site/source/layouts/layout.haml +0 -55
  555. data/site/source/readme.md +0 -63
  556. data/site/source/robots.txt +0 -3
  557. data/spec/javascripts/components/collection_view_spec.coffee +0 -59
  558. data/spec/javascripts/components/controller_spec.coffee +0 -62
  559. data/spec/javascripts/components/form_view_spec.coffee +0 -162
  560. data/spec/javascripts/components/multi_collection_view_spec.coffee +0 -5
  561. data/spec/javascripts/components/table_view_spec.coffee +0 -17
  562. data/spec/javascripts/concerns/collection_event_bindings_spec.coffee +0 -15
  563. data/spec/javascripts/concerns/dom_helpers_spec.coffee +0 -16
  564. data/spec/javascripts/concerns/filterable_spec.coffee +0 -25
  565. data/spec/javascripts/concerns/model_presenter_spec.coffee +0 -31
  566. data/spec/javascripts/concerns/state_model_spec.coffee +0 -55
  567. data/spec/javascripts/containers/card_view_spec.coffee +0 -108
  568. data/spec/javascripts/core/concerns_spec.coffee +0 -88
  569. data/spec/javascripts/core/container_spec.coffee +0 -287
  570. data/spec/javascripts/core/define_spec.coffee +0 -116
  571. data/spec/javascripts/core/events_spec.coffee +0 -26
  572. data/spec/javascripts/core/field_spec.coffee +0 -4
  573. data/spec/javascripts/core/util_spec.coffee +0 -24
  574. data/spec/javascripts/dependencies/index.coffee +0 -3
  575. data/spec/lib/component_definition_spec.rb +0 -63
  576. data/spec/lib/input_compiler_spec.rb +0 -9
  577. data/spec/lib/luca_application_spec.rb +0 -30
  578. data/spec/support/fixtures/application.coffee +0 -45
  579. data/spec/support/fixtures/component.coffee +0 -34
  580. data/tutorials/component-driven-design.md +0 -140
  581. data/tutorials/structure-of-a-project.md +0 -63
  582. data/vendor/assets/javascripts/backbone-ext.js +0 -21
  583. data/vendor/assets/javascripts/backbone-min.js +0 -42
  584. data/vendor/assets/javascripts/backbone-query.min.js +0 -1
  585. data/vendor/assets/javascripts/bootstrap.min.js +0 -7
  586. data/vendor/assets/javascripts/codemirror-ui.js +0 -503
  587. data/vendor/assets/javascripts/hogan.js +0 -707
  588. data/vendor/assets/javascripts/inflections.js +0 -656
  589. data/vendor/assets/javascripts/jasmine-html.js +0 -190
  590. data/vendor/assets/javascripts/jasmine.js +0 -2476
  591. data/vendor/assets/javascripts/jquery.js +0 -5
  592. data/vendor/assets/javascripts/keymaster.min.js +0 -4
  593. data/vendor/assets/javascripts/luca-dependencies.min.js +0 -8
  594. data/vendor/assets/javascripts/luca-development.min.js +0 -1
  595. data/vendor/assets/javascripts/luca-spec.js +0 -11
  596. data/vendor/assets/javascripts/luca.full.min.js +0 -12
  597. data/vendor/assets/javascripts/luca.min.js +0 -5
  598. data/vendor/assets/javascripts/sinon.js +0 -3469
  599. data/vendor/assets/javascripts/underscore-min.js +0 -1
  600. data/vendor/assets/javascripts/underscore-string.min.js +0 -1
  601. data/vendor/assets/stylesheets/bootstrap-responsive.min.css +0 -9
  602. data/vendor/assets/stylesheets/bootstrap.min.css +0 -9
  603. data/vendor/assets/stylesheets/luca-components.css +0 -202
  604. data/vendor/assets/stylesheets/luca-development.css +0 -23
@@ -1,1353 +0,0 @@
1
- /*jslint onevar: false, plusplus: false */
2
- /*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
3
- /*
4
-
5
- JS Beautifier
6
- ---------------
7
-
8
-
9
- Written by Einar Lielmanis, <einar@jsbeautifier.org>
10
- http://jsbeautifier.org/
11
-
12
- Originally converted to javascript by Vital, <vital76@gmail.com>
13
- "End braces on own line" added by Chris J. Shull, <chrisjshull@gmail.com>
14
-
15
- You are free to use this in any way you want, in case you find this useful or working for you.
16
-
17
- Usage:
18
- js_beautify(js_source_text);
19
- js_beautify(js_source_text, options);
20
-
21
- The options are:
22
- indent_size (default 4) - indentation size,
23
- indent_char (default space) - character to indent with,
24
- preserve_newlines (default true) - whether existing line breaks should be preserved,
25
- max_preserve_newlines (default unlimited) - maximum number of line breaks to be preserved in one chunk,
26
-
27
- jslint_happy (default false) - if true, then jslint-stricter mode is enforced.
28
-
29
- jslint_happy !jslint_happy
30
- ---------------------------------
31
- function () function()
32
-
33
- brace_style (default "collapse") - "collapse" | "expand" | "end-expand" | "expand-strict"
34
- put braces on the same line as control statements (default), or put braces on own line (Allman / ANSI style), or just put end braces on own line.
35
-
36
- expand-strict: put brace on own line even in such cases:
37
-
38
- var a =
39
- {
40
- a: 5,
41
- b: 6
42
- }
43
- This mode may break your scripts - e.g "return { a: 1 }" will be broken into two lines, so beware.
44
-
45
- space_before_conditional (default true) - should the space before conditional statement be added, "if(true)" vs "if (true)",
46
-
47
- unescape_strings (default false) - should printable characters in strings encoded in \xNN notation be unescaped, "example" vs "\x65\x78\x61\x6d\x70\x6c\x65"
48
-
49
- e.g
50
-
51
- js_beautify(js_source_text, {
52
- 'indent_size': 1,
53
- 'indent_char': '\t'
54
- });
55
-
56
-
57
- */
58
-
59
-
60
-
61
- function js_beautify(js_source_text, options) {
62
-
63
- var input, output, token_text, last_type, last_text, last_last_text, last_word, flags, flag_store, indent_string;
64
- var whitespace, wordchar, punct, parser_pos, line_starters, digits;
65
- var prefix, token_type, do_block_just_closed;
66
- var wanted_newline, just_added_newline, n_newlines;
67
- var preindent_string = '';
68
-
69
-
70
- // Some interpreters have unexpected results with foo = baz || bar;
71
- options = options ? options : {};
72
-
73
- var opt_brace_style;
74
-
75
- // compatibility
76
- if (options.space_after_anon_function !== undefined && options.jslint_happy === undefined) {
77
- options.jslint_happy = options.space_after_anon_function;
78
- }
79
- if (options.braces_on_own_line !== undefined) { //graceful handling of deprecated option
80
- opt_brace_style = options.braces_on_own_line ? "expand" : "collapse";
81
- }
82
- opt_brace_style = options.brace_style ? options.brace_style : (opt_brace_style ? opt_brace_style : "collapse");
83
-
84
-
85
- var opt_indent_size = options.indent_size ? options.indent_size : 4,
86
- opt_indent_char = options.indent_char ? options.indent_char : ' ',
87
- opt_preserve_newlines = typeof options.preserve_newlines === 'undefined' ? true : options.preserve_newlines,
88
- opt_break_chained_methods = typeof options.break_chained_methods === 'undefined' ? false : options.break_chained_methods,
89
- opt_max_preserve_newlines = typeof options.max_preserve_newlines === 'undefined' ? false : options.max_preserve_newlines,
90
- opt_jslint_happy = options.jslint_happy === 'undefined' ? false : options.jslint_happy,
91
- opt_keep_array_indentation = typeof options.keep_array_indentation === 'undefined' ? false : options.keep_array_indentation,
92
- opt_space_before_conditional = typeof options.space_before_conditional === 'undefined' ? true : options.space_before_conditional,
93
- opt_unescape_strings = typeof options.unescape_strings === 'undefined' ? false : options.unescape_strings;
94
-
95
- just_added_newline = false;
96
-
97
- // cache the source's length.
98
- var input_length = js_source_text.length;
99
-
100
- function trim_output(eat_newlines) {
101
- eat_newlines = typeof eat_newlines === 'undefined' ? false : eat_newlines;
102
- while (output.length && (output[output.length - 1] === ' '
103
- || output[output.length - 1] === indent_string
104
- || output[output.length - 1] === preindent_string
105
- || (eat_newlines && (output[output.length - 1] === '\n' || output[output.length - 1] === '\r')))) {
106
- output.pop();
107
- }
108
- }
109
-
110
- function trim(s) {
111
- return s.replace(/^\s\s*|\s\s*$/, '');
112
- }
113
-
114
- // we could use just string.split, but
115
- // IE doesn't like returning empty strings
116
- function split_newlines(s) {
117
- //return s.split(/\x0d\x0a|\x0a/);
118
-
119
- s = s.replace(/\x0d/g, '');
120
- var out = [],
121
- idx = s.indexOf("\n");
122
- while (idx !== -1) {
123
- out.push(s.substring(0, idx));
124
- s = s.substring(idx + 1);
125
- idx = s.indexOf("\n");
126
- }
127
- if (s.length) {
128
- out.push(s);
129
- }
130
- return out;
131
- }
132
-
133
- function force_newline() {
134
- var old_keep_array_indentation = opt_keep_array_indentation;
135
- opt_keep_array_indentation = false;
136
- print_newline();
137
- opt_keep_array_indentation = old_keep_array_indentation;
138
- }
139
-
140
- function print_newline(ignore_repeated, reset_statement_flags) {
141
-
142
- flags.eat_next_space = false;
143
- if (opt_keep_array_indentation && is_array(flags.mode)) {
144
- return;
145
- }
146
-
147
- ignore_repeated = typeof ignore_repeated === 'undefined' ? true : ignore_repeated;
148
- reset_statement_flags = typeof reset_statement_flags === 'undefined' ? true : reset_statement_flags;
149
-
150
- if (reset_statement_flags) {
151
- flags.if_line = false;
152
- flags.chain_extra_indentation = 0;
153
- }
154
-
155
- trim_output();
156
-
157
- if (!output.length) {
158
- return; // no newline on start of file
159
- }
160
-
161
- if (output[output.length - 1] !== "\n" || !ignore_repeated) {
162
- just_added_newline = true;
163
- output.push("\n");
164
- }
165
- if (preindent_string) {
166
- output.push(preindent_string);
167
- }
168
- for (var i = 0; i < flags.indentation_level + flags.chain_extra_indentation; i += 1) {
169
- output.push(indent_string);
170
- }
171
- if (flags.var_line && flags.var_line_reindented) {
172
- output.push(indent_string); // skip space-stuffing, if indenting with a tab
173
- }
174
- }
175
-
176
-
177
-
178
- function print_single_space() {
179
-
180
- var last_output = ' ';
181
-
182
- if (flags.eat_next_space) {
183
- flags.eat_next_space = false;
184
- } else if (last_type === 'TK_COMMENT') {
185
- print_newline();
186
- } else {
187
- if (output.length) {
188
- last_output = output[output.length - 1];
189
- }
190
- if (last_output !== ' ' && last_output !== '\n' && last_output !== indent_string) { // prevent occassional duplicate space
191
- output.push(' ');
192
- }
193
- }
194
- }
195
-
196
-
197
- function print_token() {
198
- just_added_newline = false;
199
- flags.eat_next_space = false;
200
- output.push(token_text);
201
- }
202
-
203
- function indent() {
204
- flags.indentation_level += 1;
205
- }
206
-
207
-
208
- function remove_indent() {
209
- if (output.length && output[output.length - 1] === indent_string) {
210
- output.pop();
211
- }
212
- }
213
-
214
- function set_mode(mode) {
215
- if (flags) {
216
- flag_store.push(flags);
217
- }
218
- flags = {
219
- previous_mode: flags ? flags.mode : 'BLOCK',
220
- mode: mode,
221
- var_line: false,
222
- var_line_tainted: false,
223
- var_line_reindented: false,
224
- in_html_comment: false,
225
- if_line: false,
226
- chain_extra_indentation: 0,
227
- in_case_statement: false, // switch(..){ INSIDE HERE }
228
- in_case: false, // we're on the exact line with "case 0:"
229
- case_body: false, // the indented case-action block
230
- eat_next_space: false,
231
- indentation_level: (flags ? flags.indentation_level + ((flags.var_line && flags.var_line_reindented) ? 1 : 0) : 0),
232
- ternary_depth: 0
233
- };
234
- }
235
-
236
- function is_array(mode) {
237
- return mode === '[EXPRESSION]' || mode === '[INDENTED-EXPRESSION]';
238
- }
239
-
240
- function is_expression(mode) {
241
- return in_array(mode, ['[EXPRESSION]', '(EXPRESSION)', '(FOR-EXPRESSION)', '(COND-EXPRESSION)']);
242
- }
243
-
244
- function restore_mode() {
245
- do_block_just_closed = flags.mode === 'DO_BLOCK';
246
- if (flag_store.length > 0) {
247
- var mode = flags.mode;
248
- flags = flag_store.pop();
249
- flags.previous_mode = mode;
250
- }
251
- }
252
-
253
- function all_lines_start_with(lines, c) {
254
- for (var i = 0; i < lines.length; i++) {
255
- var line = trim(lines[i]);
256
- if (line.charAt(0) !== c) {
257
- return false;
258
- }
259
- }
260
- return true;
261
- }
262
-
263
- function is_special_word(word) {
264
- return in_array(word, ['case', 'return', 'do', 'if', 'throw', 'else']);
265
- }
266
-
267
- function in_array(what, arr) {
268
- for (var i = 0; i < arr.length; i += 1) {
269
- if (arr[i] === what) {
270
- return true;
271
- }
272
- }
273
- return false;
274
- }
275
-
276
- function unescape_string(s) {
277
- var esc = false,
278
- out = '',
279
- pos = 0,
280
- s_hex = '',
281
- escaped = 0,
282
- c;
283
-
284
- while (esc || pos < s.length) {
285
-
286
- c = s.charAt(pos);
287
- pos++;
288
-
289
- if (esc) {
290
- esc = false;
291
- if (c === 'x') {
292
- // simple hex-escape \x24
293
- s_hex = s.substr(pos, 2);
294
- pos += 2;
295
- } else if (c === 'u') {
296
- // unicode-escape, \u2134
297
- s_hex = s.substr(pos, 4);
298
- pos += 4;
299
- } else {
300
- // some common escape, e.g \n
301
- out += '\\' + c;
302
- continue;
303
- }
304
- if ( ! s_hex.match(/^[0123456789abcdefABCDEF]+$/)) {
305
- // some weird escaping, bail out,
306
- // leaving whole string intact
307
- return s;
308
- }
309
-
310
- escaped = parseInt(s_hex, 16);
311
-
312
- if (escaped >= 0x00 && escaped < 0x20) {
313
- // leave 0x00...0x1f escaped
314
- if (c === 'x') {
315
- out += '\\x' + s_hex;
316
- } else {
317
- out += '\\u' + s_hex;
318
- }
319
- continue;
320
- } else if (escaped == 0x22 || escaped === 0x27 || escaped == 0x5c) {
321
- // single-quote, apostrophe, backslash - escape these
322
- out += '\\' + String.fromCharCode(escaped);
323
- } else if (c === 'x' && escaped > 0x7e && escaped <= 0xff) {
324
- // we bail out on \x7f..\xff,
325
- // leaving whole string escaped,
326
- // as it's probably completely binary
327
- return s;
328
- } else {
329
- out += String.fromCharCode(escaped);
330
- }
331
- } else if (c == '\\') {
332
- esc = true;
333
- } else {
334
- out += c;
335
- }
336
- }
337
- return out;
338
- }
339
-
340
- function look_up(exclude) {
341
- var local_pos = parser_pos;
342
- var c = input.charAt(local_pos);
343
- while (in_array(c, whitespace) && c !== exclude) {
344
- local_pos++;
345
- if (local_pos >= input_length) {
346
- return 0;
347
- }
348
- c = input.charAt(local_pos);
349
- }
350
- return c;
351
- }
352
-
353
- function get_next_token() {
354
- var i;
355
-
356
- n_newlines = 0;
357
-
358
- if (parser_pos >= input_length) {
359
- return ['', 'TK_EOF'];
360
- }
361
-
362
- wanted_newline = false;
363
-
364
- var c = input.charAt(parser_pos);
365
- parser_pos += 1;
366
-
367
-
368
- var keep_whitespace = opt_keep_array_indentation && is_array(flags.mode);
369
-
370
- if (keep_whitespace) {
371
-
372
- var whitespace_count = 0;
373
-
374
- while (in_array(c, whitespace)) {
375
-
376
- if (c === "\n") {
377
- trim_output();
378
- output.push("\n");
379
- just_added_newline = true;
380
- whitespace_count = 0;
381
- } else {
382
- if (just_added_newline) {
383
- if (c === indent_string) {
384
- output.push(indent_string);
385
- } else {
386
- if (c !== '\r') {
387
- output.push(' ');
388
- }
389
- }
390
- }
391
- }
392
-
393
- if (parser_pos >= input_length) {
394
- return ['', 'TK_EOF'];
395
- }
396
-
397
- c = input.charAt(parser_pos);
398
- parser_pos += 1;
399
-
400
- }
401
-
402
- } else {
403
- while (in_array(c, whitespace)) {
404
-
405
- if (c === "\n") {
406
- n_newlines += ((opt_max_preserve_newlines) ? (n_newlines <= opt_max_preserve_newlines) ? 1 : 0 : 1);
407
- }
408
-
409
-
410
- if (parser_pos >= input_length) {
411
- return ['', 'TK_EOF'];
412
- }
413
-
414
- c = input.charAt(parser_pos);
415
- parser_pos += 1;
416
-
417
- }
418
-
419
- if (opt_preserve_newlines) {
420
- if (n_newlines > 1) {
421
- for (i = 0; i < n_newlines; i += 1) {
422
- print_newline(i === 0);
423
- just_added_newline = true;
424
- }
425
- }
426
- }
427
- wanted_newline = n_newlines > 0;
428
- }
429
-
430
-
431
- if (in_array(c, wordchar)) {
432
- if (parser_pos < input_length) {
433
- while (in_array(input.charAt(parser_pos), wordchar)) {
434
- c += input.charAt(parser_pos);
435
- parser_pos += 1;
436
- if (parser_pos === input_length) {
437
- break;
438
- }
439
- }
440
- }
441
-
442
- // small and surprisingly unugly hack for 1E-10 representation
443
- if (parser_pos !== input_length && c.match(/^[0-9]+[Ee]$/) && (input.charAt(parser_pos) === '-' || input.charAt(parser_pos) === '+')) {
444
-
445
- var sign = input.charAt(parser_pos);
446
- parser_pos += 1;
447
-
448
- var t = get_next_token();
449
- c += sign + t[0];
450
- return [c, 'TK_WORD'];
451
- }
452
-
453
- if (c === 'in') { // hack for 'in' operator
454
- return [c, 'TK_OPERATOR'];
455
- }
456
- if (wanted_newline && last_type !== 'TK_OPERATOR'
457
- && last_type !== 'TK_EQUALS'
458
- && !flags.if_line && (opt_preserve_newlines || last_text !== 'var')) {
459
- print_newline();
460
- }
461
- return [c, 'TK_WORD'];
462
- }
463
-
464
- if (c === '(' || c === '[') {
465
- return [c, 'TK_START_EXPR'];
466
- }
467
-
468
- if (c === ')' || c === ']') {
469
- return [c, 'TK_END_EXPR'];
470
- }
471
-
472
- if (c === '{') {
473
- return [c, 'TK_START_BLOCK'];
474
- }
475
-
476
- if (c === '}') {
477
- return [c, 'TK_END_BLOCK'];
478
- }
479
-
480
- if (c === ';') {
481
- return [c, 'TK_SEMICOLON'];
482
- }
483
-
484
- if (c === '/') {
485
- var comment = '';
486
- // peek for comment /* ... */
487
- var inline_comment = true;
488
- if (input.charAt(parser_pos) === '*') {
489
- parser_pos += 1;
490
- if (parser_pos < input_length) {
491
- while (parser_pos < input_length &&
492
- ! (input.charAt(parser_pos) === '*' && input.charAt(parser_pos + 1) && input.charAt(parser_pos + 1) === '/')) {
493
- c = input.charAt(parser_pos);
494
- comment += c;
495
- if (c === "\n" || c === "\r") {
496
- inline_comment = false;
497
- }
498
- parser_pos += 1;
499
- if (parser_pos >= input_length) {
500
- break;
501
- }
502
- }
503
- }
504
- parser_pos += 2;
505
- if (inline_comment && n_newlines === 0) {
506
- return ['/*' + comment + '*/', 'TK_INLINE_COMMENT'];
507
- } else {
508
- return ['/*' + comment + '*/', 'TK_BLOCK_COMMENT'];
509
- }
510
- }
511
- // peek for comment // ...
512
- if (input.charAt(parser_pos) === '/') {
513
- comment = c;
514
- while (input.charAt(parser_pos) !== '\r' && input.charAt(parser_pos) !== '\n') {
515
- comment += input.charAt(parser_pos);
516
- parser_pos += 1;
517
- if (parser_pos >= input_length) {
518
- break;
519
- }
520
- }
521
- if (wanted_newline) {
522
- print_newline();
523
- }
524
- return [comment, 'TK_COMMENT'];
525
- }
526
-
527
- }
528
-
529
- if (c === "'" || // string
530
- c === '"' || // string
531
- (c === '/' &&
532
- ((last_type === 'TK_WORD' && is_special_word(last_text)) ||
533
- (last_text === ')' && in_array(flags.previous_mode, ['(COND-EXPRESSION)', '(FOR-EXPRESSION)'])) ||
534
- (last_type === 'TK_COMMA' || last_type === 'TK_COMMENT' || last_type === 'TK_START_EXPR' || last_type === 'TK_START_BLOCK' || last_type === 'TK_END_BLOCK' || last_type === 'TK_OPERATOR' || last_type === 'TK_EQUALS' || last_type === 'TK_EOF' || last_type === 'TK_SEMICOLON')))) { // regexp
535
- var sep = c,
536
- esc = false,
537
- has_char_escapes = false,
538
- resulting_string = c;
539
-
540
- if (parser_pos < input_length) {
541
- if (sep === '/') {
542
- //
543
- // handle regexp separately...
544
- //
545
- var in_char_class = false;
546
- while (esc || in_char_class || input.charAt(parser_pos) !== sep) {
547
- resulting_string += input.charAt(parser_pos);
548
- if (!esc) {
549
- esc = input.charAt(parser_pos) === '\\';
550
- if (input.charAt(parser_pos) === '[') {
551
- in_char_class = true;
552
- } else if (input.charAt(parser_pos) === ']') {
553
- in_char_class = false;
554
- }
555
- } else {
556
- esc = false;
557
- }
558
- parser_pos += 1;
559
- if (parser_pos >= input_length) {
560
- // incomplete string/rexp when end-of-file reached.
561
- // bail out with what had been received so far.
562
- return [resulting_string, 'TK_STRING'];
563
- }
564
- }
565
-
566
- } else {
567
- //
568
- // and handle string also separately
569
- //
570
- while (esc || input.charAt(parser_pos) !== sep) {
571
- resulting_string += input.charAt(parser_pos);
572
- if (esc) {
573
- if (input.charAt(parser_pos) === 'x' || input.charAt(parser_pos) === 'u') {
574
- has_char_escapes = true;
575
- }
576
- esc = false;
577
- } else {
578
- esc = input.charAt(parser_pos) === '\\';
579
- }
580
- parser_pos += 1;
581
- if (parser_pos >= input_length) {
582
- // incomplete string/rexp when end-of-file reached.
583
- // bail out with what had been received so far.
584
- return [resulting_string, 'TK_STRING'];
585
- }
586
- }
587
-
588
- }
589
- }
590
-
591
- parser_pos += 1;
592
- resulting_string += sep;
593
-
594
- if (has_char_escapes && opt_unescape_strings) {
595
- resulting_string = unescape_string(resulting_string);
596
- }
597
-
598
- if (sep === '/') {
599
- // regexps may have modifiers /regexp/MOD , so fetch those, too
600
- while (parser_pos < input_length && in_array(input.charAt(parser_pos), wordchar)) {
601
- resulting_string += input.charAt(parser_pos);
602
- parser_pos += 1;
603
- }
604
- }
605
- return [resulting_string, 'TK_STRING'];
606
- }
607
-
608
- if (c === '#') {
609
-
610
-
611
- if (output.length === 0 && input.charAt(parser_pos) === '!') {
612
- // shebang
613
- resulting_string = c;
614
- while (parser_pos < input_length && c !== '\n') {
615
- c = input.charAt(parser_pos);
616
- resulting_string += c;
617
- parser_pos += 1;
618
- }
619
- output.push(trim(resulting_string) + '\n');
620
- print_newline();
621
- return get_next_token();
622
- }
623
-
624
-
625
-
626
- // Spidermonkey-specific sharp variables for circular references
627
- // https://developer.mozilla.org/En/Sharp_variables_in_JavaScript
628
- // http://mxr.mozilla.org/mozilla-central/source/js/src/jsscan.cpp around line 1935
629
- var sharp = '#';
630
- if (parser_pos < input_length && in_array(input.charAt(parser_pos), digits)) {
631
- do {
632
- c = input.charAt(parser_pos);
633
- sharp += c;
634
- parser_pos += 1;
635
- } while (parser_pos < input_length && c !== '#' && c !== '=');
636
- if (c === '#') {
637
- //
638
- } else if (input.charAt(parser_pos) === '[' && input.charAt(parser_pos + 1) === ']') {
639
- sharp += '[]';
640
- parser_pos += 2;
641
- } else if (input.charAt(parser_pos) === '{' && input.charAt(parser_pos + 1) === '}') {
642
- sharp += '{}';
643
- parser_pos += 2;
644
- }
645
- return [sharp, 'TK_WORD'];
646
- }
647
- }
648
-
649
- if (c === '<' && input.substring(parser_pos - 1, parser_pos + 3) === '<!--') {
650
- parser_pos += 3;
651
- c = '<!--';
652
- while (input.charAt(parser_pos) !== '\n' && parser_pos < input_length) {
653
- c += input.charAt(parser_pos);
654
- parser_pos++;
655
- }
656
- flags.in_html_comment = true;
657
- return [c, 'TK_COMMENT'];
658
- }
659
-
660
- if (c === '-' && flags.in_html_comment && input.substring(parser_pos - 1, parser_pos + 2) === '-->') {
661
- flags.in_html_comment = false;
662
- parser_pos += 2;
663
- if (wanted_newline) {
664
- print_newline();
665
- }
666
- return ['-->', 'TK_COMMENT'];
667
- }
668
-
669
- if (c === '.') {
670
- return [c, 'TK_DOT'];
671
- }
672
-
673
- if (in_array(c, punct)) {
674
- while (parser_pos < input_length && in_array(c + input.charAt(parser_pos), punct)) {
675
- c += input.charAt(parser_pos);
676
- parser_pos += 1;
677
- if (parser_pos >= input_length) {
678
- break;
679
- }
680
- }
681
-
682
- if (c === ',') {
683
- return [c, 'TK_COMMA'];
684
- } else if (c === '=') {
685
- return [c, 'TK_EQUALS'];
686
- } else {
687
- return [c, 'TK_OPERATOR'];
688
- }
689
- }
690
-
691
- return [c, 'TK_UNKNOWN'];
692
- }
693
-
694
- //----------------------------------
695
- indent_string = '';
696
- while (opt_indent_size > 0) {
697
- indent_string += opt_indent_char;
698
- opt_indent_size -= 1;
699
- }
700
-
701
- while (js_source_text && (js_source_text.charAt(0) === ' ' || js_source_text.charAt(0) === '\t')) {
702
- preindent_string += js_source_text.charAt(0);
703
- js_source_text = js_source_text.substring(1);
704
- }
705
- input = js_source_text;
706
-
707
- last_word = ''; // last 'TK_WORD' passed
708
- last_type = 'TK_START_EXPR'; // last token type
709
- last_text = ''; // last token text
710
- last_last_text = ''; // pre-last token text
711
- output = [];
712
-
713
- do_block_just_closed = false;
714
-
715
- whitespace = "\n\r\t ".split('');
716
- wordchar = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$'.split('');
717
- digits = '0123456789'.split('');
718
-
719
- punct = '+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! !! , : ? ^ ^= |= ::';
720
- punct += ' <%= <% %> <?= <? ?>'; // try to be a good boy and try not to break the markup language identifiers
721
- punct = punct.split(' ');
722
-
723
- // words which should always start on new line.
724
- line_starters = 'continue,try,throw,return,var,if,switch,case,default,for,while,break,function'.split(',');
725
-
726
- // states showing if we are currently in expression (i.e. "if" case) - 'EXPRESSION', or in usual block (like, procedure), 'BLOCK'.
727
- // some formatting depends on that.
728
- flag_store = [];
729
- set_mode('BLOCK');
730
-
731
- parser_pos = 0;
732
- while (true) {
733
- var t = get_next_token();
734
- token_text = t[0];
735
- token_type = t[1];
736
- if (token_type === 'TK_EOF') {
737
- break;
738
- }
739
-
740
- switch (token_type) {
741
-
742
- case 'TK_START_EXPR':
743
-
744
- if (token_text === '[') {
745
-
746
- if (last_type === 'TK_WORD' || last_text === ')') {
747
- // this is array index specifier, break immediately
748
- // a[x], fn()[x]
749
- if (in_array(last_text, line_starters)) {
750
- print_single_space();
751
- }
752
- set_mode('(EXPRESSION)');
753
- print_token();
754
- break;
755
- }
756
-
757
- if (flags.mode === '[EXPRESSION]' || flags.mode === '[INDENTED-EXPRESSION]') {
758
- if (last_last_text === ']' && last_text === ',') {
759
- // ], [ goes to new line
760
- if (flags.mode === '[EXPRESSION]') {
761
- flags.mode = '[INDENTED-EXPRESSION]';
762
- if (!opt_keep_array_indentation) {
763
- indent();
764
- }
765
- }
766
- set_mode('[EXPRESSION]');
767
- if (!opt_keep_array_indentation) {
768
- print_newline();
769
- }
770
- } else if (last_text === '[') {
771
- if (flags.mode === '[EXPRESSION]') {
772
- flags.mode = '[INDENTED-EXPRESSION]';
773
- if (!opt_keep_array_indentation) {
774
- indent();
775
- }
776
- }
777
- set_mode('[EXPRESSION]');
778
-
779
- if (!opt_keep_array_indentation) {
780
- print_newline();
781
- }
782
- } else {
783
- set_mode('[EXPRESSION]');
784
- }
785
- } else {
786
- set_mode('[EXPRESSION]');
787
- }
788
-
789
-
790
-
791
- } else {
792
- if (last_word === 'for') {
793
- set_mode('(FOR-EXPRESSION)');
794
- } else if (in_array(last_word, ['if', 'while'])) {
795
- set_mode('(COND-EXPRESSION)');
796
- } else {
797
- set_mode('(EXPRESSION)');
798
- }
799
- }
800
-
801
- if (last_text === ';' || last_type === 'TK_START_BLOCK') {
802
- print_newline();
803
- } else if (last_type === 'TK_END_EXPR' || last_type === 'TK_START_EXPR' || last_type === 'TK_END_BLOCK' || last_text === '.') {
804
- if (wanted_newline) {
805
- print_newline();
806
- }
807
- // do nothing on (( and )( and ][ and ]( and .(
808
- } else if (last_type !== 'TK_WORD' && last_type !== 'TK_OPERATOR') {
809
- print_single_space();
810
- } else if (last_word === 'function' || last_word === 'typeof') {
811
- // function() vs function ()
812
- if (opt_jslint_happy) {
813
- print_single_space();
814
- }
815
- } else if (in_array(last_text, line_starters) || last_text === 'catch') {
816
- if (opt_space_before_conditional) {
817
- print_single_space();
818
- }
819
- }
820
- print_token();
821
-
822
- break;
823
-
824
- case 'TK_DOT':
825
-
826
- if (is_special_word(last_text)) {
827
- print_single_space();
828
- } else if (last_text === ')') {
829
- if (opt_break_chained_methods || wanted_newline) {
830
- flags.chain_extra_indentation = 1;
831
- print_newline(true /* ignore_repeated */, false /* reset_statement_flags */);
832
- }
833
- }
834
-
835
- print_token();
836
- break;
837
-
838
- case 'TK_END_EXPR':
839
- if (token_text === ']') {
840
- if (opt_keep_array_indentation) {
841
- if (last_text === '}') {
842
- // trim_output();
843
- // print_newline(true);
844
- remove_indent();
845
- print_token();
846
- restore_mode();
847
- break;
848
- }
849
- } else {
850
- if (flags.mode === '[INDENTED-EXPRESSION]') {
851
- if (last_text === ']') {
852
- restore_mode();
853
- print_newline();
854
- print_token();
855
- break;
856
- }
857
- }
858
- }
859
- }
860
- restore_mode();
861
- print_token();
862
- break;
863
-
864
- case 'TK_START_BLOCK':
865
-
866
- if (last_word === 'do') {
867
- set_mode('DO_BLOCK');
868
- } else {
869
- set_mode('BLOCK');
870
- }
871
- if (opt_brace_style === "expand" || opt_brace_style === "expand-strict") {
872
- var empty_braces = false;
873
- if (opt_brace_style === "expand-strict") {
874
- empty_braces = (look_up() === '}');
875
- if (!empty_braces) {
876
- print_newline(true);
877
- }
878
- } else {
879
- if (last_type !== 'TK_OPERATOR') {
880
- if (last_text === '=' || (is_special_word(last_text) && last_text !== 'else')) {
881
- print_single_space();
882
- } else {
883
- print_newline(true);
884
- }
885
- }
886
- }
887
- print_token();
888
- if (!empty_braces) {
889
- indent();
890
- }
891
- } else {
892
- if (last_type !== 'TK_OPERATOR' && last_type !== 'TK_START_EXPR') {
893
- if (last_type === 'TK_START_BLOCK') {
894
- print_newline();
895
- } else {
896
- print_single_space();
897
- }
898
- } else {
899
- // if TK_OPERATOR or TK_START_EXPR
900
- if (is_array(flags.previous_mode) && last_text === ',') {
901
- if (last_last_text === '}') {
902
- // }, { in array context
903
- print_single_space();
904
- } else {
905
- print_newline(); // [a, b, c, {
906
- }
907
- }
908
- }
909
- indent();
910
- print_token();
911
- }
912
-
913
- break;
914
-
915
- case 'TK_END_BLOCK':
916
- restore_mode();
917
- if (opt_brace_style === "expand" || opt_brace_style === "expand-strict") {
918
- if (last_text !== '{') {
919
- print_newline();
920
- }
921
- print_token();
922
- } else {
923
- if (last_type === 'TK_START_BLOCK') {
924
- // nothing
925
- if (just_added_newline) {
926
- remove_indent();
927
- } else {
928
- // {}
929
- trim_output();
930
- }
931
- } else {
932
- if (is_array(flags.mode) && opt_keep_array_indentation) {
933
- // we REALLY need a newline here, but newliner would skip that
934
- opt_keep_array_indentation = false;
935
- print_newline();
936
- opt_keep_array_indentation = true;
937
-
938
- } else {
939
- print_newline();
940
- }
941
- }
942
- print_token();
943
- }
944
- break;
945
-
946
- case 'TK_WORD':
947
-
948
- // no, it's not you. even I have problems understanding how this works
949
- // and what does what.
950
- if (do_block_just_closed) {
951
- // do {} ## while ()
952
- print_single_space();
953
- print_token();
954
- print_single_space();
955
- do_block_just_closed = false;
956
- break;
957
- }
958
-
959
- prefix = 'NONE';
960
-
961
- if (token_text === 'function') {
962
- if (flags.var_line && last_type !== 'TK_EQUALS' ) {
963
- flags.var_line_reindented = true;
964
- }
965
- if ((just_added_newline || last_text === ';') && last_text !== '{'
966
- && last_type !== 'TK_BLOCK_COMMENT' && last_type !== 'TK_COMMENT') {
967
- // make sure there is a nice clean space of at least one blank line
968
- // before a new function definition
969
- n_newlines = just_added_newline ? n_newlines : 0;
970
- if (!opt_preserve_newlines) {
971
- n_newlines = 1;
972
- }
973
-
974
- for (var i = 0; i < 2 - n_newlines; i++) {
975
- print_newline(false);
976
- }
977
- }
978
- if (last_type === 'TK_WORD') {
979
- if (last_text === 'get' || last_text === 'set' || last_text === 'new' || last_text === 'return') {
980
- print_single_space();
981
- } else {
982
- print_newline();
983
- }
984
- } else if (last_type === 'TK_OPERATOR' || last_text === '=') {
985
- // foo = function
986
- print_single_space();
987
- } else if (is_expression(flags.mode)) {
988
- // print nothing
989
- } else {
990
- print_newline();
991
- }
992
-
993
- print_token();
994
- last_word = token_text;
995
- break;
996
- }
997
-
998
- if (token_text === 'case' || (token_text === 'default' && flags.in_case_statement)) {
999
- print_newline();
1000
- if (flags.case_body) {
1001
- // switch cases following one another
1002
- flags.indentation_level--;
1003
- flags.case_body = false;
1004
- remove_indent();
1005
- }
1006
- print_token();
1007
- flags.in_case = true;
1008
- flags.in_case_statement = true;
1009
- break;
1010
- }
1011
-
1012
- if (last_type === 'TK_END_BLOCK') {
1013
-
1014
- if (!in_array(token_text.toLowerCase(), ['else', 'catch', 'finally'])) {
1015
- prefix = 'NEWLINE';
1016
- } else {
1017
- if (opt_brace_style === "expand" || opt_brace_style === "end-expand" || opt_brace_style === "expand-strict") {
1018
- prefix = 'NEWLINE';
1019
- } else {
1020
- prefix = 'SPACE';
1021
- print_single_space();
1022
- }
1023
- }
1024
- } else if (last_type === 'TK_SEMICOLON' && (flags.mode === 'BLOCK' || flags.mode === 'DO_BLOCK')) {
1025
- prefix = 'NEWLINE';
1026
- } else if (last_type === 'TK_SEMICOLON' && is_expression(flags.mode)) {
1027
- prefix = 'SPACE';
1028
- } else if (last_type === 'TK_STRING') {
1029
- prefix = 'NEWLINE';
1030
- } else if (last_type === 'TK_WORD') {
1031
- if (last_text === 'else') {
1032
- // eat newlines between ...else *** some_op...
1033
- // won't preserve extra newlines in this place (if any), but don't care that much
1034
- trim_output(true);
1035
- }
1036
- prefix = 'SPACE';
1037
- } else if (last_type === 'TK_START_BLOCK') {
1038
- prefix = 'NEWLINE';
1039
- } else if (last_type === 'TK_END_EXPR') {
1040
- print_single_space();
1041
- prefix = 'NEWLINE';
1042
- }
1043
-
1044
- if (in_array(token_text, line_starters) && last_text !== ')') {
1045
- if (last_text === 'else') {
1046
- prefix = 'SPACE';
1047
- } else {
1048
- prefix = 'NEWLINE';
1049
- }
1050
-
1051
- }
1052
-
1053
- if (flags.if_line && last_type === 'TK_END_EXPR') {
1054
- flags.if_line = false;
1055
- }
1056
- if (in_array(token_text.toLowerCase(), ['else', 'catch', 'finally'])) {
1057
- if (last_type !== 'TK_END_BLOCK' || opt_brace_style === "expand" || opt_brace_style === "end-expand" || opt_brace_style === "expand-strict") {
1058
- print_newline();
1059
- } else {
1060
- trim_output(true);
1061
- print_single_space();
1062
- }
1063
- } else if (prefix === 'NEWLINE') {
1064
- if (is_special_word(last_text)) {
1065
- // no newline between 'return nnn'
1066
- print_single_space();
1067
- } else if (last_type !== 'TK_END_EXPR') {
1068
- if ((last_type !== 'TK_START_EXPR' || token_text !== 'var') && last_text !== ':') {
1069
- // no need to force newline on 'var': for (var x = 0...)
1070
- if (token_text === 'if' && last_word === 'else' && last_text !== '{') {
1071
- // no newline for } else if {
1072
- print_single_space();
1073
- } else {
1074
- flags.var_line = false;
1075
- flags.var_line_reindented = false;
1076
- print_newline();
1077
- }
1078
- }
1079
- } else if (in_array(token_text, line_starters) && last_text !== ')') {
1080
- flags.var_line = false;
1081
- flags.var_line_reindented = false;
1082
- print_newline();
1083
- }
1084
- } else if (is_array(flags.mode) && last_text === ',' && last_last_text === '}') {
1085
- print_newline(); // }, in lists get a newline treatment
1086
- } else if (prefix === 'SPACE') {
1087
- print_single_space();
1088
- }
1089
- print_token();
1090
- last_word = token_text;
1091
-
1092
- if (token_text === 'var') {
1093
- flags.var_line = true;
1094
- flags.var_line_reindented = false;
1095
- flags.var_line_tainted = false;
1096
- }
1097
-
1098
- if (token_text === 'if') {
1099
- flags.if_line = true;
1100
- }
1101
- if (token_text === 'else') {
1102
- flags.if_line = false;
1103
- }
1104
-
1105
- break;
1106
-
1107
- case 'TK_SEMICOLON':
1108
-
1109
- print_token();
1110
- flags.var_line = false;
1111
- flags.var_line_reindented = false;
1112
- if (flags.mode === 'OBJECT') {
1113
- // OBJECT mode is weird and doesn't get reset too well.
1114
- flags.mode = 'BLOCK';
1115
- }
1116
- break;
1117
-
1118
- case 'TK_STRING':
1119
-
1120
- if (last_type === 'TK_END_EXPR' && in_array(flags.previous_mode, ['(COND-EXPRESSION)', '(FOR-EXPRESSION)'])) {
1121
- print_single_space();
1122
- } else if (last_type === 'TK_WORD') {
1123
- print_single_space();
1124
- } else if (last_type === 'TK_COMMA' || last_type === 'TK_START_EXPR' || last_type === 'TK_EQUALS' || last_type === 'TK_OPERATOR') {
1125
- if (opt_preserve_newlines && wanted_newline && flags.mode !== 'OBJECT') {
1126
- print_newline();
1127
- output.push(indent_string);
1128
- }
1129
- } else {
1130
- print_newline();
1131
- }
1132
- print_token();
1133
- break;
1134
-
1135
- case 'TK_EQUALS':
1136
- if (flags.var_line) {
1137
- // just got an '=' in a var-line, different formatting/line-breaking, etc will now be done
1138
- flags.var_line_tainted = true;
1139
- }
1140
- print_single_space();
1141
- print_token();
1142
- print_single_space();
1143
- break;
1144
-
1145
- case 'TK_COMMA':
1146
- if (flags.var_line) {
1147
- if (is_expression(flags.mode) || last_type === 'TK_END_BLOCK' ) {
1148
- // do not break on comma, for(var a = 1, b = 2)
1149
- flags.var_line_tainted = false;
1150
- }
1151
- if (flags.var_line_tainted) {
1152
- print_token();
1153
- flags.var_line_reindented = true;
1154
- flags.var_line_tainted = false;
1155
- print_newline();
1156
- break;
1157
- } else {
1158
- flags.var_line_tainted = false;
1159
- }
1160
-
1161
- print_token();
1162
- print_single_space();
1163
- break;
1164
- }
1165
-
1166
- if (last_type === 'TK_COMMENT') {
1167
- print_newline();
1168
- }
1169
-
1170
- if (last_type === 'TK_END_BLOCK' && flags.mode !== "(EXPRESSION)") {
1171
- print_token();
1172
- if (flags.mode === 'OBJECT' && last_text === '}') {
1173
- print_newline();
1174
- } else {
1175
- print_single_space();
1176
- }
1177
- } else {
1178
- if (flags.mode === 'OBJECT') {
1179
- print_token();
1180
- print_newline();
1181
- } else {
1182
- // EXPR or DO_BLOCK
1183
- print_token();
1184
- print_single_space();
1185
- }
1186
- }
1187
- break;
1188
-
1189
-
1190
- case 'TK_OPERATOR':
1191
-
1192
- var space_before = true;
1193
- var space_after = true;
1194
- if (is_special_word(last_text)) {
1195
- // "return" had a special handling in TK_WORD. Now we need to return the favor
1196
- print_single_space();
1197
- print_token();
1198
- break;
1199
- }
1200
-
1201
- // hack for actionscript's import .*;
1202
- if (token_text === '*' && last_type === 'TK_DOT' && !last_last_text.match(/^\d+$/)) {
1203
- print_token();
1204
- break;
1205
- }
1206
-
1207
- if (token_text === ':' && flags.in_case) {
1208
- flags.case_body = true;
1209
- indent();
1210
- print_token();
1211
- print_newline();
1212
- flags.in_case = false;
1213
- break;
1214
- }
1215
-
1216
- if (token_text === '::') {
1217
- // no spaces around exotic namespacing syntax operator
1218
- print_token();
1219
- break;
1220
- }
1221
-
1222
- if (in_array(token_text, ['--', '++', '!']) || (in_array(token_text, ['-', '+']) && (in_array(last_type, ['TK_START_BLOCK', 'TK_START_EXPR', 'TK_EQUALS', 'TK_OPERATOR']) || in_array(last_text, line_starters) || last_text == ','))) {
1223
- // unary operators (and binary +/- pretending to be unary) special cases
1224
-
1225
- space_before = false;
1226
- space_after = false;
1227
-
1228
- if (last_text === ';' && is_expression(flags.mode)) {
1229
- // for (;; ++i)
1230
- // ^^^
1231
- space_before = true;
1232
- }
1233
- if (last_type === 'TK_WORD' && in_array(last_text, line_starters)) {
1234
- space_before = true;
1235
- }
1236
-
1237
- if (flags.mode === 'BLOCK' && (last_text === '{' || last_text === ';')) {
1238
- // { foo; --i }
1239
- // foo(); --bar;
1240
- print_newline();
1241
- }
1242
- } else if (token_text === ':') {
1243
- if (flags.ternary_depth === 0) {
1244
- if (flags.mode === 'BLOCK') {
1245
- flags.mode = 'OBJECT';
1246
- }
1247
- space_before = false;
1248
- } else {
1249
- flags.ternary_depth -= 1;
1250
- }
1251
- } else if (token_text === '?') {
1252
- flags.ternary_depth += 1;
1253
- }
1254
- if (space_before) {
1255
- print_single_space();
1256
- }
1257
-
1258
- print_token();
1259
-
1260
- if (space_after) {
1261
- print_single_space();
1262
- }
1263
-
1264
- break;
1265
-
1266
- case 'TK_BLOCK_COMMENT':
1267
-
1268
- var lines = split_newlines(token_text);
1269
- var j; // iterator for this case
1270
-
1271
- if (all_lines_start_with(lines.slice(1), '*')) {
1272
- // javadoc: reformat and reindent
1273
- print_newline();
1274
- output.push(lines[0]);
1275
- for (j = 1; j < lines.length; j++) {
1276
- print_newline();
1277
- output.push(' ');
1278
- output.push(trim(lines[j]));
1279
- }
1280
-
1281
- } else {
1282
-
1283
- // simple block comment: leave intact
1284
- if (lines.length > 1) {
1285
- // multiline comment block starts with a new line
1286
- print_newline();
1287
- } else {
1288
- // single-line /* comment */ stays where it is
1289
- if (last_type === 'TK_END_BLOCK') {
1290
- print_newline();
1291
- } else {
1292
- print_single_space();
1293
- }
1294
-
1295
- }
1296
-
1297
- for (j = 0; j < lines.length; j++) {
1298
- output.push(lines[j]);
1299
- output.push("\n");
1300
- }
1301
-
1302
- }
1303
- if (look_up('\n') !== '\n') {
1304
- print_newline();
1305
- }
1306
- break;
1307
-
1308
- case 'TK_INLINE_COMMENT':
1309
- print_single_space();
1310
- print_token();
1311
- if (is_expression(flags.mode)) {
1312
- print_single_space();
1313
- } else {
1314
- force_newline();
1315
- }
1316
- break;
1317
-
1318
- case 'TK_COMMENT':
1319
-
1320
- if (last_text === ',' && !wanted_newline) {
1321
- trim_output(true);
1322
- }
1323
- if (last_type !== 'TK_COMMENT') {
1324
- if (wanted_newline) {
1325
- print_newline();
1326
- } else {
1327
- print_single_space();
1328
- }
1329
- }
1330
- print_token();
1331
- print_newline();
1332
- break;
1333
-
1334
- case 'TK_UNKNOWN':
1335
- print_token();
1336
- break;
1337
- }
1338
-
1339
- last_last_text = last_text;
1340
- last_type = token_type;
1341
- last_text = token_text;
1342
- }
1343
-
1344
- var sweet_code = preindent_string + output.join('').replace(/[\r\n ]+$/, '');
1345
- return sweet_code;
1346
-
1347
- }
1348
-
1349
- // Add support for CommonJS. Just put this file somewhere on your require.paths
1350
- // and you will be able to `var js_beautify = require("beautify").js_beautify`.
1351
- if (typeof exports !== "undefined") {
1352
- exports.js_beautify = js_beautify;
1353
- }