polyblock 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (264) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +34 -0
  5. data/app/assets/javascripts/beautify-css.js +264 -0
  6. data/app/assets/javascripts/beautify-html.js +838 -0
  7. data/app/assets/javascripts/beautify.js +1632 -0
  8. data/app/assets/javascripts/ckeditor/config.js +81 -0
  9. data/app/assets/javascripts/ckeditor/lang/en.js +5 -0
  10. data/app/assets/javascripts/ckeditor/plugins/sourcedialog/dialogs/sourcedialog.js +78 -0
  11. data/app/assets/javascripts/ckeditor/plugins/sourcedialog/icons/hidpi/sourcedialog-rtl.png +0 -0
  12. data/app/assets/javascripts/ckeditor/plugins/sourcedialog/icons/hidpi/sourcedialog.png +0 -0
  13. data/app/assets/javascripts/ckeditor/plugins/sourcedialog/icons/sourcedialog-rtl.png +0 -0
  14. data/app/assets/javascripts/ckeditor/plugins/sourcedialog/icons/sourcedialog.png +0 -0
  15. data/app/assets/javascripts/ckeditor/plugins/sourcedialog/plugin.js +27 -0
  16. data/app/assets/javascripts/ckeditor/plugins/sourcedialog/samples/sourcedialog.html +118 -0
  17. data/app/assets/javascripts/clientside-haml.js +2302 -0
  18. data/app/assets/javascripts/polyblock/application.js +24 -0
  19. data/app/assets/javascripts/polyblock/polyblock.js.coffee +143 -0
  20. data/app/assets/javascripts/transit.js +9 -0
  21. data/app/assets/javascripts/underscore.string.js +600 -0
  22. data/app/assets/stylesheets/polyblock/application.css +13 -0
  23. data/app/assets/stylesheets/polyblock/polyblocks.css +4 -0
  24. data/app/controllers/polyblock/application_controller.rb +4 -0
  25. data/app/controllers/polyblock/polyblocks_controller.rb +41 -0
  26. data/app/helpers/polyblock/application_helper.rb +29 -0
  27. data/app/helpers/polyblock/polyblocks_helper.rb +4 -0
  28. data/app/models/ckeditor/asset.rb +4 -0
  29. data/app/models/ckeditor/attachment_file.rb +12 -0
  30. data/app/models/ckeditor/picture.rb +13 -0
  31. data/app/models/polyblock/block.rb +7 -0
  32. data/app/views/layouts/polyblock/application.html.erb +14 -0
  33. data/app/views/polyblock/_editor_bar.html.erb +26 -0
  34. data/config/initializers/ckeditor.rb +21 -0
  35. data/config/routes.rb +7 -0
  36. data/db/migrate/20131201144424_create_ckeditor_assets.rb +26 -0
  37. data/db/migrate/20131201194124_create_polyblock_blocks.rb +12 -0
  38. data/lib/polyblock/engine.rb +12 -0
  39. data/lib/polyblock/version.rb +3 -0
  40. data/lib/polyblock.rb +4 -0
  41. data/lib/tasks/polyblock_tasks.rake +4 -0
  42. data/test/controllers/polyblock/polyblocks_controller_test.rb +9 -0
  43. data/test/dummy/README.rdoc +28 -0
  44. data/test/dummy/Rakefile +6 -0
  45. data/test/dummy/app/assets/javascripts/application.js +14 -0
  46. data/test/dummy/app/assets/javascripts/home.js +2 -0
  47. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  48. data/test/dummy/app/assets/stylesheets/home.css +4 -0
  49. data/test/dummy/app/controllers/application_controller.rb +5 -0
  50. data/test/dummy/app/controllers/home_controller.rb +7 -0
  51. data/test/dummy/app/helpers/application_helper.rb +2 -0
  52. data/test/dummy/app/helpers/home_helper.rb +2 -0
  53. data/test/dummy/app/views/home/index.html.erb +2 -0
  54. data/test/dummy/app/views/layouts/application.html.erb +15 -0
  55. data/test/dummy/bin/bundle +3 -0
  56. data/test/dummy/bin/rails +4 -0
  57. data/test/dummy/bin/rake +4 -0
  58. data/test/dummy/config/application.rb +23 -0
  59. data/test/dummy/config/boot.rb +5 -0
  60. data/test/dummy/config/database.yml +25 -0
  61. data/test/dummy/config/environment.rb +5 -0
  62. data/test/dummy/config/environments/development.rb +29 -0
  63. data/test/dummy/config/environments/production.rb +80 -0
  64. data/test/dummy/config/environments/test.rb +36 -0
  65. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  66. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  67. data/test/dummy/config/initializers/inflections.rb +16 -0
  68. data/test/dummy/config/initializers/mime_types.rb +5 -0
  69. data/test/dummy/config/initializers/secret_token.rb +12 -0
  70. data/test/dummy/config/initializers/session_store.rb +3 -0
  71. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  72. data/test/dummy/config/locales/en.yml +23 -0
  73. data/test/dummy/config/routes.rb +4 -0
  74. data/test/dummy/config.ru +4 -0
  75. data/test/dummy/db/development.sqlite3 +0 -0
  76. data/test/dummy/db/schema.rb +50 -0
  77. data/test/dummy/log/development.log +8760 -0
  78. data/test/dummy/public/404.html +58 -0
  79. data/test/dummy/public/422.html +58 -0
  80. data/test/dummy/public/500.html +57 -0
  81. data/test/dummy/public/favicon.ico +0 -0
  82. data/test/dummy/test/controllers/home_controller_test.rb +7 -0
  83. data/test/dummy/test/helpers/home_helper_test.rb +4 -0
  84. data/test/dummy/tmp/cache/assets/development/sprockets/01d10ffd358eeb0b021cc9183f39ae68 +0 -0
  85. data/test/dummy/tmp/cache/assets/development/sprockets/020cd4251b379e7f2ec729509bca3e41 +0 -0
  86. data/test/dummy/tmp/cache/assets/development/sprockets/0298cd9551a53c73ed306982bb488f21 +0 -0
  87. data/test/dummy/tmp/cache/assets/development/sprockets/033f9ad8b2cb2b403008de33db1e8b30 +0 -0
  88. data/test/dummy/tmp/cache/assets/development/sprockets/03759dc8759159b0cb33071eaa445eb0 +0 -0
  89. data/test/dummy/tmp/cache/assets/development/sprockets/054e6644a2f22ee98494c2f140e3a1e4 +0 -0
  90. data/test/dummy/tmp/cache/assets/development/sprockets/0c77775fe25328089569a112cb862dd4 +0 -0
  91. data/test/dummy/tmp/cache/assets/development/sprockets/0e895aeb087b1fb9e26b4e2398dcd1bd +0 -0
  92. data/test/dummy/tmp/cache/assets/development/sprockets/0f975357b9b6fee1af11ec65211c80bf +0 -0
  93. data/test/dummy/tmp/cache/assets/development/sprockets/12aa9b2820181ab345ef05ee8396ba2b +0 -0
  94. data/test/dummy/tmp/cache/assets/development/sprockets/131c3cd884f330627e5f5eab9b908861 +0 -0
  95. data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  96. data/test/dummy/tmp/cache/assets/development/sprockets/1518dfe3536e63b395cefe2dc1e2b2be +0 -0
  97. data/test/dummy/tmp/cache/assets/development/sprockets/161b71d479fc0fa4a60bf309f585d6c7 +0 -0
  98. data/test/dummy/tmp/cache/assets/development/sprockets/1825f57b27296afe7285b26c07446d43 +0 -0
  99. data/test/dummy/tmp/cache/assets/development/sprockets/183add279724180686cad2786c68835f +0 -0
  100. data/test/dummy/tmp/cache/assets/development/sprockets/18b273e17be07c99fb48b37938c1f91e +0 -0
  101. data/test/dummy/tmp/cache/assets/development/sprockets/1926295578648cdc013840b112b4549a +0 -0
  102. data/test/dummy/tmp/cache/assets/development/sprockets/198ac8a69bf3249985d9888cbe072828 +0 -0
  103. data/test/dummy/tmp/cache/assets/development/sprockets/1a2a68c52d72fd360df1534fb62d80e5 +0 -0
  104. data/test/dummy/tmp/cache/assets/development/sprockets/1ba6042344298db56baa871bda8def48 +0 -0
  105. data/test/dummy/tmp/cache/assets/development/sprockets/1c3bf4812b7668021d8dbca7a8365f1a +0 -0
  106. data/test/dummy/tmp/cache/assets/development/sprockets/1c9faaf28d05409b88ad3113374d613c +0 -0
  107. data/test/dummy/tmp/cache/assets/development/sprockets/1dcf2f066cb7d1f61053762f665026f0 +0 -0
  108. data/test/dummy/tmp/cache/assets/development/sprockets/1eeb828973d38ac019484de910989d1a +0 -0
  109. data/test/dummy/tmp/cache/assets/development/sprockets/1f9c2e5e8f8f4274f29c2db2392b7443 +0 -0
  110. data/test/dummy/tmp/cache/assets/development/sprockets/1fb5c44086b9680362505e609ea1c3ba +0 -0
  111. data/test/dummy/tmp/cache/assets/development/sprockets/2032a9b15f933605f9e1348b938692ca +0 -0
  112. data/test/dummy/tmp/cache/assets/development/sprockets/222ae44e85a1c2658302687309a33440 +0 -0
  113. data/test/dummy/tmp/cache/assets/development/sprockets/227fcecc68de591c070de5ee5383f6aa +0 -0
  114. data/test/dummy/tmp/cache/assets/development/sprockets/2822de3b22c28bd5e718c9bf500457b2 +0 -0
  115. data/test/dummy/tmp/cache/assets/development/sprockets/284d60c07fb8c32b968c2bf0653a0c51 +0 -0
  116. data/test/dummy/tmp/cache/assets/development/sprockets/28a13e927d6f8c4f2df07ffa043a022d +0 -0
  117. data/test/dummy/tmp/cache/assets/development/sprockets/2904d9c64f7dcf593dd93db977330071 +0 -0
  118. data/test/dummy/tmp/cache/assets/development/sprockets/293760eecba440378055bf9964e26ef5 +0 -0
  119. data/test/dummy/tmp/cache/assets/development/sprockets/2e8261e97a81367a52002c140e9d4d4c +0 -0
  120. data/test/dummy/tmp/cache/assets/development/sprockets/2ef35d1c258b156746998a0e8bfb2512 +0 -0
  121. data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  122. data/test/dummy/tmp/cache/assets/development/sprockets/2f98ed9544591a552d4a27e8d6fe52e7 +0 -0
  123. data/test/dummy/tmp/cache/assets/development/sprockets/30372050d03c549f832d0a229f054a09 +0 -0
  124. data/test/dummy/tmp/cache/assets/development/sprockets/3105a0833af87dbcd24616a1aa326624 +0 -0
  125. data/test/dummy/tmp/cache/assets/development/sprockets/31242785b0b30c2926a0a001ba15c37b +0 -0
  126. data/test/dummy/tmp/cache/assets/development/sprockets/346013835dd9a50f5c9e047b3c8c6036 +0 -0
  127. data/test/dummy/tmp/cache/assets/development/sprockets/355e62a84da5c2155a31fe4addaf3fab +0 -0
  128. data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  129. data/test/dummy/tmp/cache/assets/development/sprockets/35dc797930ef7be4efb807233bb4089a +0 -0
  130. data/test/dummy/tmp/cache/assets/development/sprockets/38034a7a583e8b4c116cd9427c6a65a6 +0 -0
  131. data/test/dummy/tmp/cache/assets/development/sprockets/39bf3443ada31f4751a7d4f5992eabfa +0 -0
  132. data/test/dummy/tmp/cache/assets/development/sprockets/3aa98dd2b45d207a9fea94c6d3fc4c93 +0 -0
  133. data/test/dummy/tmp/cache/assets/development/sprockets/3b9ed85ea6b3c17f3357272f88edec81 +0 -0
  134. data/test/dummy/tmp/cache/assets/development/sprockets/40fc2f3d2a468a00e463f1d313cb1683 +0 -0
  135. data/test/dummy/tmp/cache/assets/development/sprockets/41f903e59539965c348dbac12f651853 +0 -0
  136. data/test/dummy/tmp/cache/assets/development/sprockets/42079241bc34a6f7a1ea3d085e9e81a1 +0 -0
  137. data/test/dummy/tmp/cache/assets/development/sprockets/469a23499ce29fb0b21239db80139b48 +0 -0
  138. data/test/dummy/tmp/cache/assets/development/sprockets/46e74a11aa3f8c919696fae111869929 +0 -0
  139. data/test/dummy/tmp/cache/assets/development/sprockets/483f8189cba7c0aee7a46a04febdc197 +0 -0
  140. data/test/dummy/tmp/cache/assets/development/sprockets/494fc186abfedc09409786fc8b2ba340 +0 -0
  141. data/test/dummy/tmp/cache/assets/development/sprockets/4b886bd84e18901aa1bfbaafded1ea74 +0 -0
  142. data/test/dummy/tmp/cache/assets/development/sprockets/4bac9705448d2568d956a6b580565d0e +0 -0
  143. data/test/dummy/tmp/cache/assets/development/sprockets/4bf84fc546d1736be7f5e49f37d9e373 +0 -0
  144. data/test/dummy/tmp/cache/assets/development/sprockets/4ce319d4627e6065afffeaec20f27c2c +0 -0
  145. data/test/dummy/tmp/cache/assets/development/sprockets/507329c12ad1da334c124a54ac840247 +0 -0
  146. data/test/dummy/tmp/cache/assets/development/sprockets/5080e3e500303e0b993d3147ca0c0747 +0 -0
  147. data/test/dummy/tmp/cache/assets/development/sprockets/50e76ce60f5fc61ca3e70b70d8766d75 +0 -0
  148. data/test/dummy/tmp/cache/assets/development/sprockets/52a652f96849ad97a147a7d9fe45d374 +0 -0
  149. data/test/dummy/tmp/cache/assets/development/sprockets/52d05185fe8ef8d067c2ba8f196d9afb +0 -0
  150. data/test/dummy/tmp/cache/assets/development/sprockets/5418c4cf54e69db24470c9dccd42b524 +0 -0
  151. data/test/dummy/tmp/cache/assets/development/sprockets/54e6936a11d8f5cdf5fa2f48475d2207 +0 -0
  152. data/test/dummy/tmp/cache/assets/development/sprockets/54f23a17d564a036a8942b34853d62af +0 -0
  153. data/test/dummy/tmp/cache/assets/development/sprockets/5688d74639deb1904bb099823a2b9078 +0 -0
  154. data/test/dummy/tmp/cache/assets/development/sprockets/5cf14a014ac60aeddff4e9dad4971824 +0 -0
  155. data/test/dummy/tmp/cache/assets/development/sprockets/5d5d4bb119e1e543a75ebf4c1a795a64 +0 -0
  156. data/test/dummy/tmp/cache/assets/development/sprockets/5e7c59533e1b5ef0c92e0d46f0848a2c +0 -0
  157. data/test/dummy/tmp/cache/assets/development/sprockets/60f1796bd046463c321db1046bc1c26a +0 -0
  158. data/test/dummy/tmp/cache/assets/development/sprockets/61dbe29abaf1d38eeeaed7fa9dce6ea3 +0 -0
  159. data/test/dummy/tmp/cache/assets/development/sprockets/649a30c83a617bd43d47acf786140f34 +0 -0
  160. data/test/dummy/tmp/cache/assets/development/sprockets/64d65db775748acbf392e1eacf59032d +0 -0
  161. data/test/dummy/tmp/cache/assets/development/sprockets/65a5689d2de3f83bcc1531b0bd7918ce +0 -0
  162. data/test/dummy/tmp/cache/assets/development/sprockets/66a715b5252355fae8785a848f07890c +0 -0
  163. data/test/dummy/tmp/cache/assets/development/sprockets/67068ab8480c236e15cc6d7507e52eec +0 -0
  164. data/test/dummy/tmp/cache/assets/development/sprockets/67af580bfcbac793745a2bdc2344880a +0 -0
  165. data/test/dummy/tmp/cache/assets/development/sprockets/69f01b85f9dbad9d568e46c5a81d3cef +0 -0
  166. data/test/dummy/tmp/cache/assets/development/sprockets/6aa08eaf51a818834385dea1b64100f0 +0 -0
  167. data/test/dummy/tmp/cache/assets/development/sprockets/6beb01ae124bf2ebfb1a82617e2b6098 +0 -0
  168. data/test/dummy/tmp/cache/assets/development/sprockets/6dabc2eb7494578b1bd175f001055ec8 +0 -0
  169. data/test/dummy/tmp/cache/assets/development/sprockets/6f75f19c6e3573a6696df41ac5d31cca +0 -0
  170. data/test/dummy/tmp/cache/assets/development/sprockets/71069975441a8fde10d210b51585a5a3 +0 -0
  171. data/test/dummy/tmp/cache/assets/development/sprockets/7276854d4022c2d37882818af409c467 +0 -0
  172. data/test/dummy/tmp/cache/assets/development/sprockets/73c99b0656c98ebf9f4f9a69565fa0b7 +0 -0
  173. data/test/dummy/tmp/cache/assets/development/sprockets/749930e2a2cdc8a72fb497359f83181e +0 -0
  174. data/test/dummy/tmp/cache/assets/development/sprockets/75b1e158df9657689b214b7ccd2e4cf7 +0 -0
  175. data/test/dummy/tmp/cache/assets/development/sprockets/75d065741331d0ad6ae16498b7108723 +0 -0
  176. data/test/dummy/tmp/cache/assets/development/sprockets/76ad604881ad72473bf07bd1d19c8494 +0 -0
  177. data/test/dummy/tmp/cache/assets/development/sprockets/773d7acc6545de12f1a86b77cef2e40e +0 -0
  178. data/test/dummy/tmp/cache/assets/development/sprockets/786af69fbff630e129664087cb879e57 +0 -0
  179. data/test/dummy/tmp/cache/assets/development/sprockets/78cf370d910b9a1721891b28a7c7fec0 +0 -0
  180. data/test/dummy/tmp/cache/assets/development/sprockets/7c72a7ab5a27c2ea4fe3a2d8ba0e1890 +0 -0
  181. data/test/dummy/tmp/cache/assets/development/sprockets/7e8e0833a197f1f272edbd4c74d55c8c +0 -0
  182. data/test/dummy/tmp/cache/assets/development/sprockets/8098a2ad06e177efc27a63d1ea20c17a +0 -0
  183. data/test/dummy/tmp/cache/assets/development/sprockets/80a9daa2db75d17e5e24d7442ccb41bc +0 -0
  184. data/test/dummy/tmp/cache/assets/development/sprockets/818c2000c1301a3f2f526dda13afe15c +0 -0
  185. data/test/dummy/tmp/cache/assets/development/sprockets/82bfcea3fa5e6c4fa34a2ebbb5d6f075 +0 -0
  186. data/test/dummy/tmp/cache/assets/development/sprockets/8340810a445a06118e27eaaad32e862d +0 -0
  187. data/test/dummy/tmp/cache/assets/development/sprockets/8631041495ef144973adaf1fba193a22 +0 -0
  188. data/test/dummy/tmp/cache/assets/development/sprockets/87f6abdf4627b5b8072bafbca388aa98 +0 -0
  189. data/test/dummy/tmp/cache/assets/development/sprockets/885519ac7f861d48be489733a6941bd0 +0 -0
  190. data/test/dummy/tmp/cache/assets/development/sprockets/8cea52541f58190ce0a4c5512c7355cb +0 -0
  191. data/test/dummy/tmp/cache/assets/development/sprockets/8cfd23d116cf0a7c9e1d68c2b769add7 +0 -0
  192. data/test/dummy/tmp/cache/assets/development/sprockets/8e4aca87eaa40ed7cff1b11eba46e8d5 +0 -0
  193. data/test/dummy/tmp/cache/assets/development/sprockets/8f0e003323d409b4bea8e37f8e210b37 +0 -0
  194. data/test/dummy/tmp/cache/assets/development/sprockets/8f4c36636517f6b49c072538a63a6d59 +0 -0
  195. data/test/dummy/tmp/cache/assets/development/sprockets/908b5ae11b8473493d1e9467124d1ee4 +0 -0
  196. data/test/dummy/tmp/cache/assets/development/sprockets/98c83dce67cf84818203c6f995f4ba36 +0 -0
  197. data/test/dummy/tmp/cache/assets/development/sprockets/9b261f00d3607a34f3df29dcc0beece1 +0 -0
  198. data/test/dummy/tmp/cache/assets/development/sprockets/a21978d1a823d6011c10799dd1fbb65c +0 -0
  199. data/test/dummy/tmp/cache/assets/development/sprockets/a366043ecf7a23398dd9230018ae5ee3 +0 -0
  200. data/test/dummy/tmp/cache/assets/development/sprockets/a39be73154e19325e4f93210251924f4 +0 -0
  201. data/test/dummy/tmp/cache/assets/development/sprockets/a82a85e8fa40ed62eabb9818404726cb +0 -0
  202. data/test/dummy/tmp/cache/assets/development/sprockets/a9f028f7a492b5907ed80268be8f50f4 +0 -0
  203. data/test/dummy/tmp/cache/assets/development/sprockets/aa3eca8179472bb088a8474f35f6c5ce +0 -0
  204. data/test/dummy/tmp/cache/assets/development/sprockets/aafb9cc161f1b35b684b6367c1d63373 +0 -0
  205. data/test/dummy/tmp/cache/assets/development/sprockets/abaf826b99cbedf45dd5304d096bdfaa +0 -0
  206. data/test/dummy/tmp/cache/assets/development/sprockets/ac34c01b1f09105c80ff6687bdc1493e +0 -0
  207. data/test/dummy/tmp/cache/assets/development/sprockets/ac9510df8de841f1abc8c72c6fd0e295 +0 -0
  208. data/test/dummy/tmp/cache/assets/development/sprockets/ad37bb314723ee3d230eb29326b47a46 +0 -0
  209. data/test/dummy/tmp/cache/assets/development/sprockets/ae401c4518969dbd6ecab0274940df4d +0 -0
  210. data/test/dummy/tmp/cache/assets/development/sprockets/b0a603111ad6abfe5bf08255eaf8573a +0 -0
  211. data/test/dummy/tmp/cache/assets/development/sprockets/b7e3984da49e9c18ea6f4344b6ddedf1 +0 -0
  212. data/test/dummy/tmp/cache/assets/development/sprockets/b878faf942403e313a5b103e5d80488e +0 -0
  213. data/test/dummy/tmp/cache/assets/development/sprockets/b8d45418a0dec849026e7832c6922595 +0 -0
  214. data/test/dummy/tmp/cache/assets/development/sprockets/ba41d761ded85fc461ab0cabbeaef53e +0 -0
  215. data/test/dummy/tmp/cache/assets/development/sprockets/ba83646bf2099832ad8ac75379b763df +0 -0
  216. data/test/dummy/tmp/cache/assets/development/sprockets/bafcd897244753eeb0b64f544a77a19c +0 -0
  217. data/test/dummy/tmp/cache/assets/development/sprockets/bd8633c99ac4b7825a5cca6cf494d940 +0 -0
  218. data/test/dummy/tmp/cache/assets/development/sprockets/bdea69b9c406739ca4e7a36da20e7b53 +0 -0
  219. data/test/dummy/tmp/cache/assets/development/sprockets/be9eeaafba005e1d57455b8fef64f7c6 +0 -0
  220. data/test/dummy/tmp/cache/assets/development/sprockets/bf5b075f964da07102907d7ce6811ed5 +0 -0
  221. data/test/dummy/tmp/cache/assets/development/sprockets/c22f6c78a77ef39e7e33f9b216b805f2 +0 -0
  222. data/test/dummy/tmp/cache/assets/development/sprockets/c4f8e04fa248664e0d9e375a092b5efe +0 -0
  223. data/test/dummy/tmp/cache/assets/development/sprockets/c58e57990b87dfd6f4bc915907ff45ea +0 -0
  224. data/test/dummy/tmp/cache/assets/development/sprockets/c805b4d29a0e91011768405e87f70817 +0 -0
  225. data/test/dummy/tmp/cache/assets/development/sprockets/ca03d7c3a02b5b9c3223a83873f07581 +0 -0
  226. data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  227. data/test/dummy/tmp/cache/assets/development/sprockets/d2a5ab24b7b9dd1e4686b22bde66a4f4 +0 -0
  228. data/test/dummy/tmp/cache/assets/development/sprockets/d4175e149c21384fc6b3fb79c9d45c66 +0 -0
  229. data/test/dummy/tmp/cache/assets/development/sprockets/d41b25d3ec25b4c3b2fe8eb9cf82d595 +0 -0
  230. data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  231. data/test/dummy/tmp/cache/assets/development/sprockets/da1acabb815f02640e2aedd90a85df93 +0 -0
  232. data/test/dummy/tmp/cache/assets/development/sprockets/de51a9a54870e5d9f22775e2e3bedf38 +0 -0
  233. data/test/dummy/tmp/cache/assets/development/sprockets/df139027ce9ac098fd00f4ab7611bbac +0 -0
  234. data/test/dummy/tmp/cache/assets/development/sprockets/e03b3a3f08af68514f0a4224b38dc19a +0 -0
  235. data/test/dummy/tmp/cache/assets/development/sprockets/e08a13a79de686909616cc3861bd2ff6 +0 -0
  236. data/test/dummy/tmp/cache/assets/development/sprockets/e0ca554821c153076d2dd8e72eb33cdb +0 -0
  237. data/test/dummy/tmp/cache/assets/development/sprockets/e4cb660bbc6515fd08140519e66368fd +0 -0
  238. data/test/dummy/tmp/cache/assets/development/sprockets/e6968aa068b3fe46c56ea816e7d3c6cf +0 -0
  239. data/test/dummy/tmp/cache/assets/development/sprockets/e736ecc7279b661ef9d3ca9882196708 +0 -0
  240. data/test/dummy/tmp/cache/assets/development/sprockets/eae7257fcd4b160c2d782e66ba0c5438 +0 -0
  241. data/test/dummy/tmp/cache/assets/development/sprockets/edbef6e0d0a4742346cf479f2c522eb0 +0 -0
  242. data/test/dummy/tmp/cache/assets/development/sprockets/ef21be926e9fa6ad4e7dbdd19e0fc91a +0 -0
  243. data/test/dummy/tmp/cache/assets/development/sprockets/ef79b2be98e4232ac86c5bd6dc8cf77f +0 -0
  244. data/test/dummy/tmp/cache/assets/development/sprockets/f1087ef68b351492e06aa6cfd82d0438 +0 -0
  245. data/test/dummy/tmp/cache/assets/development/sprockets/f22c23c07479937e88c5642915d72652 +0 -0
  246. data/test/dummy/tmp/cache/assets/development/sprockets/f3c90764c8cfc0c04c179baeeb54f7d9 +0 -0
  247. data/test/dummy/tmp/cache/assets/development/sprockets/f4e04263f04511317e283b7afd5ac9fc +0 -0
  248. data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  249. data/test/dummy/tmp/cache/assets/development/sprockets/f999e530403d0f45b1fb283186785dc5 +0 -0
  250. data/test/dummy/tmp/cache/assets/development/sprockets/f99bfcf75bfe60e1e9c19f03fd1c476c +0 -0
  251. data/test/dummy/tmp/cache/assets/development/sprockets/f9a99df6b5884accbebff708f1fa861d +0 -0
  252. data/test/dummy/tmp/cache/assets/development/sprockets/fa2a1a439527d340ac07907157929b8d +0 -0
  253. data/test/dummy/tmp/cache/assets/development/sprockets/fa735568b6074e46bd157a4391e6627f +0 -0
  254. data/test/dummy/tmp/cache/assets/development/sprockets/fb2945554eacf0950f8c100ed8f07cb8 +0 -0
  255. data/test/dummy/tmp/cache/assets/development/sprockets/fc543306aa02516980ce1817fc19d3d5 +0 -0
  256. data/test/dummy/tmp/cache/assets/development/sprockets/fd51120226fc9ccf01d5893be1032b5b +0 -0
  257. data/test/dummy/tmp/cache/assets/development/sprockets/fdee4c39a777bb7c2f1c9f29cad9601a +0 -0
  258. data/test/fixtures/polyblock/blocks.yml +13 -0
  259. data/test/helpers/polyblock/polyblocks_helper_test.rb +6 -0
  260. data/test/integration/navigation_test.rb +10 -0
  261. data/test/models/polyblock/block_test.rb +9 -0
  262. data/test/polyblock_test.rb +7 -0
  263. data/test/test_helper.rb +15 -0
  264. metadata +653 -0
@@ -0,0 +1,1632 @@
1
+ /*jshint curly:true, eqeqeq:true, laxbreak:true, noempty:false */
2
+ /*
3
+
4
+ The MIT License (MIT)
5
+
6
+ Copyright (c) 2007-2013 Einar Lielmanis and contributors.
7
+
8
+ Permission is hereby granted, free of charge, to any person
9
+ obtaining a copy of this software and associated documentation files
10
+ (the "Software"), to deal in the Software without restriction,
11
+ including without limitation the rights to use, copy, modify, merge,
12
+ publish, distribute, sublicense, and/or sell copies of the Software,
13
+ and to permit persons to whom the Software is furnished to do so,
14
+ subject to the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be
17
+ included in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
23
+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
24
+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ JS Beautifier
29
+ ---------------
30
+
31
+
32
+ Written by Einar Lielmanis, <einar@jsbeautifier.org>
33
+ http://jsbeautifier.org/
34
+
35
+ Originally converted to javascript by Vital, <vital76@gmail.com>
36
+ "End braces on own line" added by Chris J. Shull, <chrisjshull@gmail.com>
37
+ Parsing improvements for brace-less statements by Liam Newman <bitwiseman@gmail.com>
38
+
39
+
40
+ Usage:
41
+ js_beautify(js_source_text);
42
+ js_beautify(js_source_text, options);
43
+
44
+ The options are:
45
+ indent_size (default 4) - indentation size,
46
+ indent_char (default space) - character to indent with,
47
+ preserve_newlines (default true) - whether existing line breaks should be preserved,
48
+ max_preserve_newlines (default unlimited) - maximum number of line breaks to be preserved in one chunk,
49
+
50
+ jslint_happy (default false) - if true, then jslint-stricter mode is enforced.
51
+
52
+ jslint_happy !jslint_happy
53
+ ---------------------------------
54
+ function () function()
55
+
56
+ brace_style (default "collapse") - "collapse" | "expand" | "end-expand"
57
+ 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.
58
+
59
+ space_before_conditional (default true) - should the space before conditional statement be added, "if(true)" vs "if (true)",
60
+
61
+ unescape_strings (default false) - should printable characters in strings encoded in \xNN notation be unescaped, "example" vs "\x65\x78\x61\x6d\x70\x6c\x65"
62
+
63
+ wrap_line_length (default unlimited) - lines should wrap at next opportunity after this number of characters.
64
+ NOTE: This is not a hard limit. Lines will continue until a point where a newline would
65
+ be preserved if it were present.
66
+
67
+ e.g
68
+
69
+ js_beautify(js_source_text, {
70
+ 'indent_size': 1,
71
+ 'indent_char': '\t'
72
+ });
73
+
74
+ */
75
+
76
+
77
+ (function() {
78
+ function js_beautify(js_source_text, options) {
79
+ "use strict";
80
+ var beautifier = new Beautifier(js_source_text, options);
81
+ return beautifier.beautify();
82
+ }
83
+
84
+ function Beautifier(js_source_text, options) {
85
+ "use strict";
86
+ var input, output_lines;
87
+ var token_text, token_type, last_type, last_last_text, indent_string;
88
+ var flags, previous_flags, flag_store;
89
+ var whitespace, wordchar, punct, parser_pos, line_starters, digits;
90
+ var prefix;
91
+ var input_wanted_newline;
92
+ var output_wrapped, output_space_before_token;
93
+ var input_length, n_newlines, whitespace_before_token;
94
+ var handlers, MODE, opt;
95
+ var preindent_string = '';
96
+
97
+ whitespace = "\n\r\t ".split('');
98
+ wordchar = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$'.split('');
99
+ digits = '0123456789'.split('');
100
+
101
+ punct = '+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! !! , : ? ^ ^= |= ::';
102
+ punct += ' <%= <% %> <?= <? ?>'; // try to be a good boy and try not to break the markup language identifiers
103
+ punct = punct.split(' ');
104
+
105
+ // words which should always start on new line.
106
+ line_starters = 'continue,try,throw,return,var,if,switch,case,default,for,while,break,function'.split(',');
107
+
108
+ MODE = {
109
+ BlockStatement: 'BlockStatement', // 'BLOCK'
110
+ Statement: 'Statement', // 'STATEMENT'
111
+ ObjectLiteral: 'ObjectLiteral', // 'OBJECT',
112
+ ArrayLiteral: 'ArrayLiteral', //'[EXPRESSION]',
113
+ ForInitializer: 'ForInitializer', //'(FOR-EXPRESSION)',
114
+ Conditional: 'Conditional', //'(COND-EXPRESSION)',
115
+ Expression: 'Expression' //'(EXPRESSION)'
116
+ };
117
+
118
+ handlers = {
119
+ 'TK_START_EXPR': handle_start_expr,
120
+ 'TK_END_EXPR': handle_end_expr,
121
+ 'TK_START_BLOCK': handle_start_block,
122
+ 'TK_END_BLOCK': handle_end_block,
123
+ 'TK_WORD': handle_word,
124
+ 'TK_SEMICOLON': handle_semicolon,
125
+ 'TK_STRING': handle_string,
126
+ 'TK_EQUALS': handle_equals,
127
+ 'TK_OPERATOR': handle_operator,
128
+ 'TK_COMMA': handle_comma,
129
+ 'TK_BLOCK_COMMENT': handle_block_comment,
130
+ 'TK_INLINE_COMMENT': handle_inline_comment,
131
+ 'TK_COMMENT': handle_comment,
132
+ 'TK_DOT': handle_dot,
133
+ 'TK_UNKNOWN': handle_unknown
134
+ };
135
+
136
+ function create_flags(flags_base, mode) {
137
+ var next_indent_level = 0;
138
+ if (flags_base) {
139
+ next_indent_level = flags_base.indentation_level;
140
+ next_indent_level += (flags_base.var_line && flags_base.var_line_reindented) ? 1 : 0;
141
+ if (!just_added_newline() &&
142
+ flags_base.line_indent_level > next_indent_level) {
143
+ next_indent_level = flags_base.line_indent_level;
144
+ }
145
+ }
146
+
147
+ var next_flags = {
148
+ mode: mode,
149
+ parent: flags_base,
150
+ last_text: flags_base ? flags_base.last_text : '', // last token text
151
+ last_word: flags_base ? flags_base.last_word : '', // last 'TK_WORD' passed
152
+ var_line: false,
153
+ var_line_tainted: false,
154
+ var_line_reindented: false,
155
+ in_html_comment: false,
156
+ multiline_frame: false,
157
+ if_block: false,
158
+ do_block: false,
159
+ do_while: false,
160
+ in_case_statement: false, // switch(..){ INSIDE HERE }
161
+ in_case: false, // we're on the exact line with "case 0:"
162
+ case_body: false, // the indented case-action block
163
+ indentation_level: next_indent_level,
164
+ line_indent_level: flags_base ? flags_base.line_indent_level : next_indent_level,
165
+ start_line_index: output_lines.length,
166
+ ternary_depth: 0
167
+ }
168
+ return next_flags;
169
+ }
170
+
171
+ // Using object instead of string to allow for later expansion of info about each line
172
+
173
+ function create_output_line() {
174
+ return {
175
+ text: []
176
+ };
177
+ }
178
+
179
+ // Some interpreters have unexpected results with foo = baz || bar;
180
+ options = options ? options : {};
181
+ opt = {};
182
+
183
+ // compatibility
184
+ if (options.space_after_anon_function !== undefined && options.jslint_happy === undefined) {
185
+ options.jslint_happy = options.space_after_anon_function;
186
+ }
187
+ if (options.braces_on_own_line !== undefined) { //graceful handling of deprecated option
188
+ opt.brace_style = options.braces_on_own_line ? "expand" : "collapse";
189
+ }
190
+ opt.brace_style = options.brace_style ? options.brace_style : (opt.brace_style ? opt.brace_style : "collapse");
191
+
192
+ // graceful handling of deprecated option
193
+ if (opt.brace_style === "expand-strict") {
194
+ opt.brace_style = "expand";
195
+ }
196
+
197
+
198
+ opt.indent_size = options.indent_size ? parseInt(options.indent_size, 10) : 4;
199
+ opt.indent_char = options.indent_char ? options.indent_char : ' ';
200
+ opt.preserve_newlines = (options.preserve_newlines === undefined) ? true : options.preserve_newlines;
201
+ opt.break_chained_methods = (options.break_chained_methods === undefined) ? false : options.break_chained_methods;
202
+ opt.max_preserve_newlines = (options.max_preserve_newlines === undefined) ? 0 : parseInt(options.max_preserve_newlines, 10);
203
+ opt.space_in_paren = (options.space_in_paren === undefined) ? false : options.space_in_paren;
204
+ opt.jslint_happy = (options.jslint_happy === undefined) ? false : options.jslint_happy;
205
+ opt.keep_array_indentation = (options.keep_array_indentation === undefined) ? false : options.keep_array_indentation;
206
+ opt.space_before_conditional = (options.space_before_conditional === undefined) ? true : options.space_before_conditional;
207
+ opt.unescape_strings = (options.unescape_strings === undefined) ? false : options.unescape_strings;
208
+ opt.wrap_line_length = (options.wrap_line_length === undefined) ? 0 : parseInt(options.wrap_line_length, 10);
209
+ opt.e4x = (options.e4x === undefined) ? false : options.e4x;
210
+
211
+ if(options.indent_with_tabs){
212
+ opt.indent_char = '\t';
213
+ opt.indent_size = 1;
214
+ }
215
+
216
+ //----------------------------------
217
+ indent_string = '';
218
+ while (opt.indent_size > 0) {
219
+ indent_string += opt.indent_char;
220
+ opt.indent_size -= 1;
221
+ }
222
+
223
+ while (js_source_text && (js_source_text.charAt(0) === ' ' || js_source_text.charAt(0) === '\t')) {
224
+ preindent_string += js_source_text.charAt(0);
225
+ js_source_text = js_source_text.substring(1);
226
+ }
227
+ input = js_source_text;
228
+ // cache the source's length.
229
+ input_length = js_source_text.length;
230
+
231
+ last_type = 'TK_START_BLOCK'; // last token type
232
+ last_last_text = ''; // pre-last token text
233
+ output_lines = [create_output_line()];
234
+ output_wrapped = false;
235
+ output_space_before_token = false;
236
+ whitespace_before_token = [];
237
+
238
+ // Stack of parsing/formatting states, including MODE.
239
+ // We tokenize, parse, and output in an almost purely a forward-only stream of token input
240
+ // and formatted output. This makes the beautifier less accurate than full parsers
241
+ // but also far more tolerant of syntax errors.
242
+ //
243
+ // For example, the default mode is MODE.BlockStatement. If we see a '{' we push a new frame of type
244
+ // MODE.BlockStatement on the the stack, even though it could be object literal. If we later
245
+ // encounter a ":", we'll switch to to MODE.ObjectLiteral. If we then see a ";",
246
+ // most full parsers would die, but the beautifier gracefully falls back to
247
+ // MODE.BlockStatement and continues on.
248
+ flag_store = [];
249
+ set_mode(MODE.BlockStatement);
250
+
251
+ parser_pos = 0;
252
+
253
+ this.beautify = function() {
254
+ /*jshint onevar:true */
255
+ var t, i, keep_whitespace, sweet_code;
256
+
257
+ while (true) {
258
+ t = get_next_token();
259
+ token_text = t[0];
260
+ token_type = t[1];
261
+
262
+ if (token_type === 'TK_EOF') {
263
+ break;
264
+ }
265
+
266
+ keep_whitespace = opt.keep_array_indentation && is_array(flags.mode);
267
+ input_wanted_newline = n_newlines > 0;
268
+
269
+ if (keep_whitespace) {
270
+ for (i = 0; i < n_newlines; i += 1) {
271
+ print_newline(i > 0);
272
+ }
273
+ } else {
274
+ if (opt.max_preserve_newlines && n_newlines > opt.max_preserve_newlines) {
275
+ n_newlines = opt.max_preserve_newlines;
276
+ }
277
+
278
+ if (opt.preserve_newlines) {
279
+ if (n_newlines > 1) {
280
+ print_newline();
281
+ for (i = 1; i < n_newlines; i += 1) {
282
+ print_newline(true);
283
+ }
284
+ }
285
+ }
286
+ }
287
+
288
+ handlers[token_type]();
289
+
290
+ // The cleanest handling of inline comments is to treat them as though they aren't there.
291
+ // Just continue formatting and the behavior should be logical.
292
+ // Also ignore unknown tokens. Again, this should result in better behavior.
293
+ if (token_type !== 'TK_INLINE_COMMENT' && token_type !== 'TK_COMMENT' &&
294
+ token_type !== 'TK_UNKNOWN') {
295
+ last_last_text = flags.last_text;
296
+ last_type = token_type;
297
+ flags.last_text = token_text;
298
+ }
299
+ }
300
+
301
+
302
+ sweet_code = output_lines[0].text.join('');
303
+ for (var line_index = 1; line_index < output_lines.length; line_index++) {
304
+ sweet_code += '\n' + output_lines[line_index].text.join('');
305
+ }
306
+ sweet_code = sweet_code.replace(/[\r\n ]+$/, '');
307
+ return sweet_code;
308
+ };
309
+
310
+ function trim_output(eat_newlines) {
311
+ eat_newlines = (eat_newlines === undefined) ? false : eat_newlines;
312
+
313
+ if (output_lines.length) {
314
+ trim_output_line(output_lines[output_lines.length - 1], eat_newlines);
315
+
316
+ while (eat_newlines && output_lines.length > 1 &&
317
+ output_lines[output_lines.length - 1].text.length === 0) {
318
+ output_lines.pop();
319
+ trim_output_line(output_lines[output_lines.length - 1], eat_newlines);
320
+ }
321
+ }
322
+ }
323
+
324
+ function trim_output_line(line) {
325
+ while (line.text.length &&
326
+ (line.text[line.text.length - 1] === ' ' ||
327
+ line.text[line.text.length - 1] === indent_string ||
328
+ line.text[line.text.length - 1] === preindent_string)) {
329
+ line.text.pop();
330
+ }
331
+ }
332
+
333
+ function trim(s) {
334
+ return s.replace(/^\s+|\s+$/g, '');
335
+ }
336
+
337
+ // we could use just string.split, but
338
+ // IE doesn't like returning empty strings
339
+
340
+ function split_newlines(s) {
341
+ //return s.split(/\x0d\x0a|\x0a/);
342
+
343
+ s = s.replace(/\x0d/g, '');
344
+ var out = [],
345
+ idx = s.indexOf("\n");
346
+ while (idx !== -1) {
347
+ out.push(s.substring(0, idx));
348
+ s = s.substring(idx + 1);
349
+ idx = s.indexOf("\n");
350
+ }
351
+ if (s.length) {
352
+ out.push(s);
353
+ }
354
+ return out;
355
+ }
356
+
357
+ function just_added_newline() {
358
+ var line = output_lines[output_lines.length - 1];
359
+ return line.text.length === 0;
360
+ }
361
+
362
+ function just_added_blankline() {
363
+ if (just_added_newline()) {
364
+ if (output_lines.length === 1) {
365
+ return true; // start of the file and newline = blank
366
+ }
367
+
368
+ var line = output_lines[output_lines.length - 2];
369
+ return line.text.length === 0;
370
+ }
371
+ return false;
372
+ }
373
+
374
+ function allow_wrap_or_preserved_newline(force_linewrap) {
375
+ force_linewrap = (force_linewrap === undefined) ? false : force_linewrap;
376
+ if (opt.wrap_line_length && !force_linewrap) {
377
+ var line = output_lines[output_lines.length - 1];
378
+ var proposed_line_length = 0;
379
+ // never wrap the first token of a line.
380
+ if (line.text.length > 0) {
381
+ proposed_line_length = line.text.join('').length + token_text.length +
382
+ (output_space_before_token ? 1 : 0);
383
+ if (proposed_line_length >= opt.wrap_line_length) {
384
+ force_linewrap = true;
385
+ }
386
+ }
387
+ }
388
+ if (((opt.preserve_newlines && input_wanted_newline) || force_linewrap) && !just_added_newline()) {
389
+ print_newline(false, true);
390
+
391
+ // Expressions and array literals already indent their contents.
392
+ if (!(is_array(flags.mode) || is_expression(flags.mode))) {
393
+ output_wrapped = true;
394
+ }
395
+ }
396
+ }
397
+
398
+ function print_newline(force_newline, preserve_statement_flags) {
399
+ output_wrapped = false;
400
+ output_space_before_token = false;
401
+
402
+ if (!preserve_statement_flags) {
403
+ if (flags.last_text !== ';') {
404
+ while (flags.mode === MODE.Statement && !flags.if_block && !flags.do_block) {
405
+ restore_mode();
406
+ }
407
+ }
408
+ }
409
+
410
+ if (output_lines.length === 1 && just_added_newline()) {
411
+ return; // no newline on start of file
412
+ }
413
+
414
+ if (force_newline || !just_added_newline()) {
415
+ flags.multiline_frame = true;
416
+ output_lines.push(create_output_line());
417
+ }
418
+ }
419
+
420
+ function print_token_line_indentation() {
421
+ if (just_added_newline()) {
422
+ var line = output_lines[output_lines.length - 1];
423
+ if (opt.keep_array_indentation && is_array(flags.mode) && input_wanted_newline) {
424
+ // prevent removing of this whitespace as redundant
425
+ line.text.push('');
426
+ for (var i = 0; i < whitespace_before_token.length; i += 1) {
427
+ line.text.push(whitespace_before_token[i]);
428
+ }
429
+ } else {
430
+ if (preindent_string) {
431
+ line.text.push(preindent_string);
432
+ }
433
+
434
+ print_indent_string(flags.indentation_level +
435
+ (flags.var_line && flags.var_line_reindented ? 1 : 0) +
436
+ (output_wrapped ? 1 : 0));
437
+ }
438
+ }
439
+ }
440
+
441
+ function print_indent_string(level) {
442
+ // Never indent your first output indent at the start of the file
443
+ if (output_lines.length > 1) {
444
+ var line = output_lines[output_lines.length - 1];
445
+
446
+ flags.line_indent_level = level;
447
+ for (var i = 0; i < level; i += 1) {
448
+ line.text.push(indent_string);
449
+ }
450
+ }
451
+ }
452
+
453
+ function print_token_space_before() {
454
+ var line = output_lines[output_lines.length - 1];
455
+ if (output_space_before_token && line.text.length) {
456
+ var last_output = line.text[line.text.length - 1];
457
+ if (last_output !== ' ' && last_output !== indent_string) { // prevent occassional duplicate space
458
+ line.text.push(' ');
459
+ }
460
+ }
461
+ }
462
+
463
+ function print_token(printable_token) {
464
+ printable_token = printable_token || token_text;
465
+ print_token_line_indentation();
466
+ output_wrapped = false;
467
+ print_token_space_before();
468
+ output_space_before_token = false;
469
+ output_lines[output_lines.length - 1].text.push(printable_token);
470
+ }
471
+
472
+ function indent() {
473
+ flags.indentation_level += 1;
474
+ }
475
+
476
+ function deindent() {
477
+ if (flags.indentation_level > 0 &&
478
+ ((!flags.parent) || flags.indentation_level > flags.parent.indentation_level))
479
+ flags.indentation_level -= 1;
480
+ }
481
+
482
+ function remove_redundant_indentation(frame) {
483
+ // This implementation is effective but has some issues:
484
+ // - less than great performance due to array splicing
485
+ // - can cause line wrap to happen too soon due to indent removal
486
+ // after wrap points are calculated
487
+ // These issues are minor compared to ugly indentation.
488
+
489
+ if (frame.multiline_frame) return;
490
+
491
+ // remove one indent from each line inside this section
492
+ var index = frame.start_line_index;
493
+ var splice_index = 0;
494
+ var line;
495
+
496
+ while (index < output_lines.length) {
497
+ line = output_lines[index];
498
+ index++;
499
+
500
+ // skip empty lines
501
+ if (line.text.length === 0) {
502
+ continue;
503
+ }
504
+
505
+ // skip the preindent string if present
506
+ if (preindent_string && line.text[0] === preindent_string) {
507
+ splice_index = 1;
508
+ } else {
509
+ splice_index = 0;
510
+ }
511
+
512
+ // remove one indent, if present
513
+ if (line.text[splice_index] === indent_string) {
514
+ line.text.splice(splice_index, 1);
515
+ }
516
+ }
517
+ }
518
+
519
+ function set_mode(mode) {
520
+ if (flags) {
521
+ flag_store.push(flags);
522
+ previous_flags = flags;
523
+ } else {
524
+ previous_flags = create_flags(null, mode);
525
+ }
526
+
527
+ flags = create_flags(previous_flags, mode);
528
+ }
529
+
530
+ function is_array(mode) {
531
+ return mode === MODE.ArrayLiteral;
532
+ }
533
+
534
+ function is_expression(mode) {
535
+ return in_array(mode, [MODE.Expression, MODE.ForInitializer, MODE.Conditional]);
536
+ }
537
+
538
+ function restore_mode() {
539
+ if (flag_store.length > 0) {
540
+ previous_flags = flags;
541
+ flags = flag_store.pop();
542
+ }
543
+ }
544
+
545
+ function start_of_statement() {
546
+ if (
547
+ (flags.last_text === 'do' ||
548
+ (flags.last_text === 'else' && token_text !== 'if') ||
549
+ (last_type === 'TK_END_EXPR' && (previous_flags.mode === MODE.ForInitializer || previous_flags.mode === MODE.Conditional)))) {
550
+ // Issue #276:
551
+ // If starting a new statement with [if, for, while, do], push to a new line.
552
+ // if (a) if (b) if(c) d(); else e(); else f();
553
+ allow_wrap_or_preserved_newline(
554
+ in_array(token_text, ['do', 'for', 'if', 'while']));
555
+
556
+ set_mode(MODE.Statement);
557
+ // Issue #275:
558
+ // If starting on a newline, all of a statement should be indented.
559
+ // if not, use line wrapping logic for indent.
560
+ if (just_added_newline()) {
561
+ indent();
562
+ output_wrapped = false;
563
+ }
564
+ return true;
565
+ }
566
+ return false;
567
+ }
568
+
569
+ function all_lines_start_with(lines, c) {
570
+ for (var i = 0; i < lines.length; i++) {
571
+ var line = trim(lines[i]);
572
+ if (line.charAt(0) !== c) {
573
+ return false;
574
+ }
575
+ }
576
+ return true;
577
+ }
578
+
579
+ function is_special_word(word) {
580
+ return in_array(word, ['case', 'return', 'do', 'if', 'throw', 'else']);
581
+ }
582
+
583
+ function in_array(what, arr) {
584
+ for (var i = 0; i < arr.length; i += 1) {
585
+ if (arr[i] === what) {
586
+ return true;
587
+ }
588
+ }
589
+ return false;
590
+ }
591
+
592
+ function unescape_string(s) {
593
+ var esc = false,
594
+ out = '',
595
+ pos = 0,
596
+ s_hex = '',
597
+ escaped = 0,
598
+ c;
599
+
600
+ while (esc || pos < s.length) {
601
+
602
+ c = s.charAt(pos);
603
+ pos++;
604
+
605
+ if (esc) {
606
+ esc = false;
607
+ if (c === 'x') {
608
+ // simple hex-escape \x24
609
+ s_hex = s.substr(pos, 2);
610
+ pos += 2;
611
+ } else if (c === 'u') {
612
+ // unicode-escape, \u2134
613
+ s_hex = s.substr(pos, 4);
614
+ pos += 4;
615
+ } else {
616
+ // some common escape, e.g \n
617
+ out += '\\' + c;
618
+ continue;
619
+ }
620
+ if (!s_hex.match(/^[0123456789abcdefABCDEF]+$/)) {
621
+ // some weird escaping, bail out,
622
+ // leaving whole string intact
623
+ return s;
624
+ }
625
+
626
+ escaped = parseInt(s_hex, 16);
627
+
628
+ if (escaped >= 0x00 && escaped < 0x20) {
629
+ // leave 0x00...0x1f escaped
630
+ if (c === 'x') {
631
+ out += '\\x' + s_hex;
632
+ } else {
633
+ out += '\\u' + s_hex;
634
+ }
635
+ continue;
636
+ } else if (escaped === 0x22 || escaped === 0x27 || escaped === 0x5c) {
637
+ // single-quote, apostrophe, backslash - escape these
638
+ out += '\\' + String.fromCharCode(escaped);
639
+ } else if (c === 'x' && escaped > 0x7e && escaped <= 0xff) {
640
+ // we bail out on \x7f..\xff,
641
+ // leaving whole string escaped,
642
+ // as it's probably completely binary
643
+ return s;
644
+ } else {
645
+ out += String.fromCharCode(escaped);
646
+ }
647
+ } else if (c === '\\') {
648
+ esc = true;
649
+ } else {
650
+ out += c;
651
+ }
652
+ }
653
+ return out;
654
+ }
655
+
656
+ function is_next(find) {
657
+ var local_pos = parser_pos;
658
+ var c = input.charAt(local_pos);
659
+ while (in_array(c, whitespace) && c !== find) {
660
+ local_pos++;
661
+ if (local_pos >= input_length) {
662
+ return false;
663
+ }
664
+ c = input.charAt(local_pos);
665
+ }
666
+ return c === find;
667
+ }
668
+
669
+ function get_next_token() {
670
+ var i, resulting_string;
671
+
672
+ n_newlines = 0;
673
+
674
+ if (parser_pos >= input_length) {
675
+ return ['', 'TK_EOF'];
676
+ }
677
+
678
+ input_wanted_newline = false;
679
+ whitespace_before_token = [];
680
+
681
+ var c = input.charAt(parser_pos);
682
+ parser_pos += 1;
683
+
684
+ while (in_array(c, whitespace)) {
685
+
686
+ if (c === '\n') {
687
+ n_newlines += 1;
688
+ whitespace_before_token = [];
689
+ } else if (n_newlines) {
690
+ if (c === indent_string) {
691
+ whitespace_before_token.push(indent_string);
692
+ } else if (c !== '\r') {
693
+ whitespace_before_token.push(' ');
694
+ }
695
+ }
696
+
697
+ if (parser_pos >= input_length) {
698
+ return ['', 'TK_EOF'];
699
+ }
700
+
701
+ c = input.charAt(parser_pos);
702
+ parser_pos += 1;
703
+ }
704
+
705
+ if (in_array(c, wordchar)) {
706
+ if (parser_pos < input_length) {
707
+ while (in_array(input.charAt(parser_pos), wordchar)) {
708
+ c += input.charAt(parser_pos);
709
+ parser_pos += 1;
710
+ if (parser_pos === input_length) {
711
+ break;
712
+ }
713
+ }
714
+ }
715
+
716
+ // small and surprisingly unugly hack for 1E-10 representation
717
+ if (parser_pos !== input_length && c.match(/^[0-9]+[Ee]$/) && (input.charAt(parser_pos) === '-' || input.charAt(parser_pos) === '+')) {
718
+
719
+ var sign = input.charAt(parser_pos);
720
+ parser_pos += 1;
721
+
722
+ var t = get_next_token();
723
+ c += sign + t[0];
724
+ return [c, 'TK_WORD'];
725
+ }
726
+
727
+ if (c === 'in') { // hack for 'in' operator
728
+ return [c, 'TK_OPERATOR'];
729
+ }
730
+ return [c, 'TK_WORD'];
731
+ }
732
+
733
+ if (c === '(' || c === '[') {
734
+ return [c, 'TK_START_EXPR'];
735
+ }
736
+
737
+ if (c === ')' || c === ']') {
738
+ return [c, 'TK_END_EXPR'];
739
+ }
740
+
741
+ if (c === '{') {
742
+ return [c, 'TK_START_BLOCK'];
743
+ }
744
+
745
+ if (c === '}') {
746
+ return [c, 'TK_END_BLOCK'];
747
+ }
748
+
749
+ if (c === ';') {
750
+ return [c, 'TK_SEMICOLON'];
751
+ }
752
+
753
+ if (c === '/') {
754
+ var comment = '';
755
+ // peek for comment /* ... */
756
+ var inline_comment = true;
757
+ if (input.charAt(parser_pos) === '*') {
758
+ parser_pos += 1;
759
+ if (parser_pos < input_length) {
760
+ while (parser_pos < input_length && !(input.charAt(parser_pos) === '*' && input.charAt(parser_pos + 1) && input.charAt(parser_pos + 1) === '/')) {
761
+ c = input.charAt(parser_pos);
762
+ comment += c;
763
+ if (c === "\n" || c === "\r") {
764
+ inline_comment = false;
765
+ }
766
+ parser_pos += 1;
767
+ if (parser_pos >= input_length) {
768
+ break;
769
+ }
770
+ }
771
+ }
772
+ parser_pos += 2;
773
+ if (inline_comment && n_newlines === 0) {
774
+ return ['/*' + comment + '*/', 'TK_INLINE_COMMENT'];
775
+ } else {
776
+ return ['/*' + comment + '*/', 'TK_BLOCK_COMMENT'];
777
+ }
778
+ }
779
+ // peek for comment // ...
780
+ if (input.charAt(parser_pos) === '/') {
781
+ comment = c;
782
+ while (input.charAt(parser_pos) !== '\r' && input.charAt(parser_pos) !== '\n') {
783
+ comment += input.charAt(parser_pos);
784
+ parser_pos += 1;
785
+ if (parser_pos >= input_length) {
786
+ break;
787
+ }
788
+ }
789
+ return [comment, 'TK_COMMENT'];
790
+ }
791
+
792
+ }
793
+
794
+
795
+ if (c === "'" || c === '"' || // string
796
+ (
797
+ (c === '/') || // regexp
798
+ (opt.e4x && c === "<" && input.slice(parser_pos - 1).match(/^<([-a-zA-Z:0-9_.]+|{[^{}]*}|!\[CDATA\[[\s\S]*?\]\])\s*([-a-zA-Z:0-9_.]+=('[^']*'|"[^"]*"|{[^{}]*})\s*)*\/?\s*>/)) // xml
799
+ ) && ( // regex and xml can only appear in specific locations during parsing
800
+ (last_type === 'TK_WORD' && is_special_word(flags.last_text)) ||
801
+ (last_type === 'TK_END_EXPR' && in_array(previous_flags.mode, [MODE.Conditional, MODE.ForInitializer])) ||
802
+ (in_array(last_type, ['TK_COMMENT', 'TK_START_EXPR', 'TK_START_BLOCK',
803
+ 'TK_END_BLOCK', 'TK_OPERATOR', 'TK_EQUALS', 'TK_EOF', 'TK_SEMICOLON', 'TK_COMMA'
804
+ ]))
805
+ )) {
806
+
807
+ var sep = c,
808
+ esc = false,
809
+ has_char_escapes = false;
810
+
811
+ resulting_string = c;
812
+
813
+ if (parser_pos < input_length) {
814
+ if (sep === '/') {
815
+ //
816
+ // handle regexp
817
+ //
818
+ var in_char_class = false;
819
+ while (esc || in_char_class || input.charAt(parser_pos) !== sep) {
820
+ resulting_string += input.charAt(parser_pos);
821
+ if (!esc) {
822
+ esc = input.charAt(parser_pos) === '\\';
823
+ if (input.charAt(parser_pos) === '[') {
824
+ in_char_class = true;
825
+ } else if (input.charAt(parser_pos) === ']') {
826
+ in_char_class = false;
827
+ }
828
+ } else {
829
+ esc = false;
830
+ }
831
+ parser_pos += 1;
832
+ if (parser_pos >= input_length) {
833
+ // incomplete string/rexp when end-of-file reached.
834
+ // bail out with what had been received so far.
835
+ return [resulting_string, 'TK_STRING'];
836
+ }
837
+ }
838
+ } else if (opt.e4x && sep === '<') {
839
+ //
840
+ // handle e4x xml literals
841
+ //
842
+ var xmlRegExp = /<(\/?)([-a-zA-Z:0-9_.]+|{[^{}]*}|!\[CDATA\[[\s\S]*?\]\])\s*([-a-zA-Z:0-9_.]+=('[^']*'|"[^"]*"|{[^{}]*})\s*)*(\/?)\s*>/g;
843
+ var xmlStr = input.slice(parser_pos - 1);
844
+ var match = xmlRegExp.exec(xmlStr);
845
+ if (match && match.index === 0) {
846
+ var rootTag = match[2];
847
+ var depth = 0;
848
+ while (match) {
849
+ var isEndTag = !! match[1];
850
+ var tagName = match[2];
851
+ var isSingletonTag = ( !! match[match.length - 1]) || (tagName.slice(0, 8) === "![CDATA[");
852
+ if (tagName === rootTag && !isSingletonTag) {
853
+ if (isEndTag) {
854
+ --depth;
855
+ } else {
856
+ ++depth;
857
+ }
858
+ }
859
+ if (depth <= 0) {
860
+ break;
861
+ }
862
+ match = xmlRegExp.exec(xmlStr);
863
+ }
864
+ var xmlLength = match ? match.index + match[0].length : xmlStr.length;
865
+ parser_pos += xmlLength - 1;
866
+ return [xmlStr.slice(0, xmlLength), "TK_STRING"];
867
+ }
868
+ } else {
869
+ //
870
+ // handle string
871
+ //
872
+ while (esc || input.charAt(parser_pos) !== sep) {
873
+ resulting_string += input.charAt(parser_pos);
874
+ if (esc) {
875
+ if (input.charAt(parser_pos) === 'x' || input.charAt(parser_pos) === 'u') {
876
+ has_char_escapes = true;
877
+ }
878
+ esc = false;
879
+ } else {
880
+ esc = input.charAt(parser_pos) === '\\';
881
+ }
882
+ parser_pos += 1;
883
+ if (parser_pos >= input_length) {
884
+ // incomplete string/rexp when end-of-file reached.
885
+ // bail out with what had been received so far.
886
+ return [resulting_string, 'TK_STRING'];
887
+ }
888
+ }
889
+
890
+ }
891
+ }
892
+
893
+ parser_pos += 1;
894
+ resulting_string += sep;
895
+
896
+ if (has_char_escapes && opt.unescape_strings) {
897
+ resulting_string = unescape_string(resulting_string);
898
+ }
899
+
900
+ if (sep === '/') {
901
+ // regexps may have modifiers /regexp/MOD , so fetch those, too
902
+ while (parser_pos < input_length && in_array(input.charAt(parser_pos), wordchar)) {
903
+ resulting_string += input.charAt(parser_pos);
904
+ parser_pos += 1;
905
+ }
906
+ }
907
+ return [resulting_string, 'TK_STRING'];
908
+ }
909
+
910
+ if (c === '#') {
911
+
912
+
913
+ if (output_lines.length === 1 && output_lines[0].text.length === 0 &&
914
+ input.charAt(parser_pos) === '!') {
915
+ // shebang
916
+ resulting_string = c;
917
+ while (parser_pos < input_length && c !== '\n') {
918
+ c = input.charAt(parser_pos);
919
+ resulting_string += c;
920
+ parser_pos += 1;
921
+ }
922
+ return [trim(resulting_string) + '\n', 'TK_UNKNOWN'];
923
+ }
924
+
925
+
926
+
927
+ // Spidermonkey-specific sharp variables for circular references
928
+ // https://developer.mozilla.org/En/Sharp_variables_in_JavaScript
929
+ // http://mxr.mozilla.org/mozilla-central/source/js/src/jsscan.cpp around line 1935
930
+ var sharp = '#';
931
+ if (parser_pos < input_length && in_array(input.charAt(parser_pos), digits)) {
932
+ do {
933
+ c = input.charAt(parser_pos);
934
+ sharp += c;
935
+ parser_pos += 1;
936
+ } while (parser_pos < input_length && c !== '#' && c !== '=');
937
+ if (c === '#') {
938
+ //
939
+ } else if (input.charAt(parser_pos) === '[' && input.charAt(parser_pos + 1) === ']') {
940
+ sharp += '[]';
941
+ parser_pos += 2;
942
+ } else if (input.charAt(parser_pos) === '{' && input.charAt(parser_pos + 1) === '}') {
943
+ sharp += '{}';
944
+ parser_pos += 2;
945
+ }
946
+ return [sharp, 'TK_WORD'];
947
+ }
948
+ }
949
+
950
+ if (c === '<' && input.substring(parser_pos - 1, parser_pos + 3) === '<!--') {
951
+ parser_pos += 3;
952
+ c = '<!--';
953
+ while (input.charAt(parser_pos) !== '\n' && parser_pos < input_length) {
954
+ c += input.charAt(parser_pos);
955
+ parser_pos++;
956
+ }
957
+ flags.in_html_comment = true;
958
+ return [c, 'TK_COMMENT'];
959
+ }
960
+
961
+ if (c === '-' && flags.in_html_comment && input.substring(parser_pos - 1, parser_pos + 2) === '-->') {
962
+ flags.in_html_comment = false;
963
+ parser_pos += 2;
964
+ return ['-->', 'TK_COMMENT'];
965
+ }
966
+
967
+ if (c === '.') {
968
+ return [c, 'TK_DOT'];
969
+ }
970
+
971
+ if (in_array(c, punct)) {
972
+ while (parser_pos < input_length && in_array(c + input.charAt(parser_pos), punct)) {
973
+ c += input.charAt(parser_pos);
974
+ parser_pos += 1;
975
+ if (parser_pos >= input_length) {
976
+ break;
977
+ }
978
+ }
979
+
980
+ if (c === ',') {
981
+ return [c, 'TK_COMMA'];
982
+ } else if (c === '=') {
983
+ return [c, 'TK_EQUALS'];
984
+ } else {
985
+ return [c, 'TK_OPERATOR'];
986
+ }
987
+ }
988
+
989
+ return [c, 'TK_UNKNOWN'];
990
+ }
991
+
992
+ function handle_start_expr() {
993
+ if (start_of_statement()) {
994
+ // The conditional starts the statement if appropriate.
995
+ }
996
+
997
+ var next_mode = MODE.Expression;
998
+ if (token_text === '[') {
999
+
1000
+ if (last_type === 'TK_WORD' || flags.last_text === ')') {
1001
+ // this is array index specifier, break immediately
1002
+ // a[x], fn()[x]
1003
+ if (in_array(flags.last_text, line_starters)) {
1004
+ output_space_before_token = true;
1005
+ }
1006
+ set_mode(next_mode);
1007
+ print_token();
1008
+ indent();
1009
+ if (opt.space_in_paren) {
1010
+ output_space_before_token = true;
1011
+ }
1012
+ return;
1013
+ }
1014
+
1015
+ next_mode = MODE.ArrayLiteral;
1016
+ if (is_array(flags.mode)) {
1017
+ if (flags.last_text === '[' ||
1018
+ (flags.last_text === ',' && (last_last_text === ']' || last_last_text === '}'))) {
1019
+ // ], [ goes to new line
1020
+ // }, [ goes to new line
1021
+ if (!opt.keep_array_indentation) {
1022
+ print_newline();
1023
+ }
1024
+ }
1025
+ }
1026
+
1027
+ } else {
1028
+ if (flags.last_text === 'for') {
1029
+ next_mode = MODE.ForInitializer;
1030
+ } else if (in_array(flags.last_text, ['if', 'while'])) {
1031
+ next_mode = MODE.Conditional;
1032
+ } else {
1033
+ // next_mode = MODE.Expression;
1034
+ }
1035
+ }
1036
+
1037
+ if (flags.last_text === ';' || last_type === 'TK_START_BLOCK') {
1038
+ print_newline();
1039
+ } else if (last_type === 'TK_END_EXPR' || last_type === 'TK_START_EXPR' || last_type === 'TK_END_BLOCK' || flags.last_text === '.') {
1040
+ // TODO: Consider whether forcing this is required. Review failing tests when removed.
1041
+ allow_wrap_or_preserved_newline(input_wanted_newline);
1042
+ output_wrapped = false;
1043
+ // do nothing on (( and )( and ][ and ]( and .(
1044
+ } else if (last_type !== 'TK_WORD' && last_type !== 'TK_OPERATOR') {
1045
+ output_space_before_token = true;
1046
+ } else if (flags.last_word === 'function' || flags.last_word === 'typeof') {
1047
+ // function() vs function ()
1048
+ if (opt.jslint_happy) {
1049
+ output_space_before_token = true;
1050
+ }
1051
+ } else if (in_array(flags.last_text, line_starters) || flags.last_text === 'catch') {
1052
+ if (opt.space_before_conditional) {
1053
+ output_space_before_token = true;
1054
+ }
1055
+ }
1056
+
1057
+ // Support of this kind of newline preservation.
1058
+ // a = (b &&
1059
+ // (c || d));
1060
+ if (token_text === '(') {
1061
+ if (last_type === 'TK_EQUALS' || last_type === 'TK_OPERATOR') {
1062
+ if (flags.mode !== MODE.ObjectLiteral) {
1063
+ allow_wrap_or_preserved_newline();
1064
+ }
1065
+ }
1066
+ }
1067
+
1068
+ set_mode(next_mode);
1069
+ print_token();
1070
+ if (opt.space_in_paren) {
1071
+ output_space_before_token = true;
1072
+ }
1073
+
1074
+ // In all cases, if we newline while inside an expression it should be indented.
1075
+ indent();
1076
+ }
1077
+
1078
+ function handle_end_expr() {
1079
+ // statements inside expressions are not valid syntax, but...
1080
+ // statements must all be closed when their container closes
1081
+ while (flags.mode === MODE.Statement) {
1082
+ restore_mode();
1083
+ }
1084
+
1085
+ if (token_text === ']' && is_array(flags.mode) && flags.multiline_frame && !opt.keep_array_indentation) {
1086
+ print_newline();
1087
+ }
1088
+
1089
+ if (flags.multiline_frame) {
1090
+ allow_wrap_or_preserved_newline();
1091
+ }
1092
+ if (opt.space_in_paren) {
1093
+ if (last_type === 'TK_START_EXPR') {
1094
+ // () [] no inner space in empty parens like these, ever, ref #320
1095
+ trim_output();
1096
+ output_space_before_token = false;
1097
+ } else {
1098
+ output_space_before_token = true;
1099
+ }
1100
+ }
1101
+ if (token_text === ']' && opt.keep_array_indentation) {
1102
+ print_token();
1103
+ restore_mode();
1104
+ } else {
1105
+ restore_mode();
1106
+ print_token();
1107
+ }
1108
+ remove_redundant_indentation(previous_flags);
1109
+
1110
+ // do {} while () // no statement required after
1111
+ if (flags.do_while && previous_flags.mode === MODE.Conditional) {
1112
+ previous_flags.mode = MODE.Expression;
1113
+ flags.do_block = false;
1114
+ flags.do_while = false;
1115
+
1116
+ }
1117
+ }
1118
+
1119
+ function handle_start_block() {
1120
+ set_mode(MODE.BlockStatement);
1121
+
1122
+ var empty_braces = is_next('}');
1123
+ var empty_anonymous_function = empty_braces && flags.last_word === 'function' &&
1124
+ last_type === 'TK_END_EXPR';
1125
+
1126
+ if (opt.brace_style === "expand") {
1127
+ if (last_type !== 'TK_OPERATOR' &&
1128
+ (empty_anonymous_function ||
1129
+ last_type === 'TK_EQUALS' ||
1130
+ (is_special_word(flags.last_text) && flags.last_text !== 'else'))) {
1131
+ output_space_before_token = true;
1132
+ } else {
1133
+ print_newline();
1134
+ }
1135
+ } else { // collapse
1136
+ if (last_type !== 'TK_OPERATOR' && last_type !== 'TK_START_EXPR') {
1137
+ if (last_type === 'TK_START_BLOCK') {
1138
+ print_newline();
1139
+ } else {
1140
+ output_space_before_token = true;
1141
+ }
1142
+ } else {
1143
+ // if TK_OPERATOR or TK_START_EXPR
1144
+ if (is_array(previous_flags.mode) && flags.last_text === ',') {
1145
+ if (last_last_text === '}') {
1146
+ // }, { in array context
1147
+ output_space_before_token = true;
1148
+ } else {
1149
+ print_newline(); // [a, b, c, {
1150
+ }
1151
+ }
1152
+ }
1153
+ }
1154
+ print_token();
1155
+ indent();
1156
+ }
1157
+
1158
+ function handle_end_block() {
1159
+ // statements must all be closed when their container closes
1160
+ while (flags.mode === MODE.Statement) {
1161
+ restore_mode();
1162
+ }
1163
+ var empty_braces = last_type === 'TK_START_BLOCK';
1164
+
1165
+ if (opt.brace_style === "expand") {
1166
+ if (!empty_braces) {
1167
+ print_newline();
1168
+ }
1169
+ } else {
1170
+ // skip {}
1171
+ if (!empty_braces) {
1172
+ if (is_array(flags.mode) && opt.keep_array_indentation) {
1173
+ // we REALLY need a newline here, but newliner would skip that
1174
+ opt.keep_array_indentation = false;
1175
+ print_newline();
1176
+ opt.keep_array_indentation = true;
1177
+
1178
+ } else {
1179
+ print_newline();
1180
+ }
1181
+ }
1182
+ }
1183
+ restore_mode();
1184
+ print_token();
1185
+ }
1186
+
1187
+ function handle_word() {
1188
+ if (start_of_statement()) {
1189
+ // The conditional starts the statement if appropriate.
1190
+ } else if (input_wanted_newline && !is_expression(flags.mode) &&
1191
+ (last_type !== 'TK_OPERATOR' || (flags.last_text === '--' || flags.last_text === '++')) &&
1192
+ last_type !== 'TK_EQUALS' &&
1193
+ (opt.preserve_newlines || flags.last_text !== 'var')) {
1194
+
1195
+ print_newline();
1196
+ }
1197
+
1198
+ if (flags.do_block && !flags.do_while) {
1199
+ if (token_text === 'while') {
1200
+ // do {} ## while ()
1201
+ output_space_before_token = true;
1202
+ print_token();
1203
+ output_space_before_token = true;
1204
+ flags.do_while = true;
1205
+ return;
1206
+ } else {
1207
+ // do {} should always have while as the next word.
1208
+ // if we don't see the expected while, recover
1209
+ print_newline();
1210
+ flags.do_block = false;
1211
+ }
1212
+ }
1213
+
1214
+ // if may be followed by else, or not
1215
+ // Bare/inline ifs are tricky
1216
+ // Need to unwind the modes correctly: if (a) if (b) c(); else d(); else e();
1217
+ if (flags.if_block) {
1218
+ if (token_text !== 'else') {
1219
+ while (flags.mode === MODE.Statement) {
1220
+ restore_mode();
1221
+ }
1222
+ flags.if_block = false;
1223
+ }
1224
+ }
1225
+
1226
+ if (token_text === 'case' || (token_text === 'default' && flags.in_case_statement)) {
1227
+ print_newline();
1228
+ if (flags.case_body || opt.jslint_happy) {
1229
+ // switch cases following one another
1230
+ deindent();
1231
+ flags.case_body = false;
1232
+ }
1233
+ print_token();
1234
+ flags.in_case = true;
1235
+ flags.in_case_statement = true;
1236
+ return;
1237
+ }
1238
+
1239
+ if (token_text === 'function') {
1240
+ if (flags.var_line && last_type !== 'TK_EQUALS') {
1241
+ flags.var_line_reindented = true;
1242
+ }
1243
+ if ((just_added_newline() || flags.last_text === ';' || flags.last_text === '}') &&
1244
+ flags.last_text !== '{' && !is_array(flags.mode)) {
1245
+ // make sure there is a nice clean space of at least one blank line
1246
+ // before a new function definition, except in arrays
1247
+ if (!just_added_blankline()) {
1248
+ print_newline();
1249
+ print_newline(true);
1250
+ }
1251
+ }
1252
+ if (last_type === 'TK_WORD') {
1253
+ if (flags.last_text === 'get' || flags.last_text === 'set' || flags.last_text === 'new' || flags.last_text === 'return') {
1254
+ output_space_before_token = true;
1255
+ } else {
1256
+ print_newline();
1257
+ }
1258
+ } else if (last_type === 'TK_OPERATOR' || flags.last_text === '=') {
1259
+ // foo = function
1260
+ output_space_before_token = true;
1261
+ } else if (is_expression(flags.mode)) {
1262
+ // (function
1263
+ } else {
1264
+ print_newline();
1265
+ }
1266
+ }
1267
+
1268
+ if (last_type === 'TK_COMMA' || last_type === 'TK_START_EXPR' || last_type === 'TK_EQUALS' || last_type === 'TK_OPERATOR') {
1269
+ if (flags.mode !== MODE.ObjectLiteral) {
1270
+ allow_wrap_or_preserved_newline();
1271
+ }
1272
+ }
1273
+
1274
+ if (token_text === 'function') {
1275
+ print_token();
1276
+ flags.last_word = token_text;
1277
+ return;
1278
+ }
1279
+
1280
+ prefix = 'NONE';
1281
+
1282
+ if (last_type === 'TK_END_BLOCK') {
1283
+ if (!in_array(token_text, ['else', 'catch', 'finally'])) {
1284
+ prefix = 'NEWLINE';
1285
+ } else {
1286
+ if (opt.brace_style === "expand" || opt.brace_style === "end-expand") {
1287
+ prefix = 'NEWLINE';
1288
+ } else {
1289
+ prefix = 'SPACE';
1290
+ output_space_before_token = true;
1291
+ }
1292
+ }
1293
+ } else if (last_type === 'TK_SEMICOLON' && flags.mode === MODE.BlockStatement) {
1294
+ // TODO: Should this be for STATEMENT as well?
1295
+ prefix = 'NEWLINE';
1296
+ } else if (last_type === 'TK_SEMICOLON' && is_expression(flags.mode)) {
1297
+ prefix = 'SPACE';
1298
+ } else if (last_type === 'TK_STRING') {
1299
+ prefix = 'NEWLINE';
1300
+ } else if (last_type === 'TK_WORD') {
1301
+ prefix = 'SPACE';
1302
+ } else if (last_type === 'TK_START_BLOCK') {
1303
+ prefix = 'NEWLINE';
1304
+ } else if (last_type === 'TK_END_EXPR') {
1305
+ output_space_before_token = true;
1306
+ prefix = 'NEWLINE';
1307
+ }
1308
+
1309
+ if (in_array(token_text, line_starters) && flags.last_text !== ')') {
1310
+ if (flags.last_text === 'else') {
1311
+ prefix = 'SPACE';
1312
+ } else {
1313
+ prefix = 'NEWLINE';
1314
+ }
1315
+
1316
+ }
1317
+
1318
+ if (in_array(token_text, ['else', 'catch', 'finally'])) {
1319
+ if (last_type !== 'TK_END_BLOCK' || opt.brace_style === "expand" || opt.brace_style === "end-expand") {
1320
+ print_newline();
1321
+ } else {
1322
+ trim_output(true);
1323
+ var line = output_lines[output_lines.length - 1];
1324
+ // If we trimmed and there's something other than a close block before us
1325
+ // put a newline back in. Handles '} // comment' scenario.
1326
+ if (line.text[line.text.length - 1] !== '}') {
1327
+ print_newline();
1328
+ }
1329
+ output_space_before_token = true;
1330
+ }
1331
+ } else if (prefix === 'NEWLINE') {
1332
+ if (is_special_word(flags.last_text)) {
1333
+ // no newline between 'return nnn'
1334
+ output_space_before_token = true;
1335
+ } else if (last_type !== 'TK_END_EXPR') {
1336
+ if ((last_type !== 'TK_START_EXPR' || token_text !== 'var') && flags.last_text !== ':') {
1337
+ // no need to force newline on 'var': for (var x = 0...)
1338
+ if (token_text === 'if' && flags.last_word === 'else' && flags.last_text !== '{') {
1339
+ // no newline for } else if {
1340
+ output_space_before_token = true;
1341
+ } else {
1342
+ flags.var_line = false;
1343
+ flags.var_line_reindented = false;
1344
+ print_newline();
1345
+ }
1346
+ }
1347
+ } else if (in_array(token_text, line_starters) && flags.last_text !== ')') {
1348
+ flags.var_line = false;
1349
+ flags.var_line_reindented = false;
1350
+ print_newline();
1351
+ }
1352
+ } else if (is_array(flags.mode) && flags.last_text === ',' && last_last_text === '}') {
1353
+ print_newline(); // }, in lists get a newline treatment
1354
+ } else if (prefix === 'SPACE') {
1355
+ output_space_before_token = true;
1356
+ }
1357
+ print_token();
1358
+ flags.last_word = token_text;
1359
+
1360
+ if (token_text === 'var') {
1361
+ flags.var_line = true;
1362
+ flags.var_line_reindented = false;
1363
+ flags.var_line_tainted = false;
1364
+ }
1365
+
1366
+ if (token_text === 'do') {
1367
+ flags.do_block = true;
1368
+ }
1369
+
1370
+ if (token_text === 'if') {
1371
+ flags.if_block = true;
1372
+ }
1373
+ }
1374
+
1375
+ function handle_semicolon() {
1376
+ if (start_of_statement()) {
1377
+ // The conditional starts the statement if appropriate.
1378
+ // Semicolon can be the start (and end) of a statement
1379
+ output_space_before_token = false;
1380
+ }
1381
+ while (flags.mode === MODE.Statement && !flags.if_block && !flags.do_block) {
1382
+ restore_mode();
1383
+ }
1384
+ print_token();
1385
+ flags.var_line = false;
1386
+ flags.var_line_reindented = false;
1387
+ if (flags.mode === MODE.ObjectLiteral) {
1388
+ // if we're in OBJECT mode and see a semicolon, its invalid syntax
1389
+ // recover back to treating this as a BLOCK
1390
+ flags.mode = MODE.BlockStatement;
1391
+ }
1392
+ }
1393
+
1394
+ function handle_string() {
1395
+ if (start_of_statement()) {
1396
+ // The conditional starts the statement if appropriate.
1397
+ // One difference - strings want at least a space before
1398
+ output_space_before_token = true;
1399
+ } else if (last_type === 'TK_WORD') {
1400
+ output_space_before_token = true;
1401
+ } else if (last_type === 'TK_COMMA' || last_type === 'TK_START_EXPR' || last_type === 'TK_EQUALS' || last_type === 'TK_OPERATOR') {
1402
+ if (flags.mode !== MODE.ObjectLiteral) {
1403
+ allow_wrap_or_preserved_newline();
1404
+ }
1405
+ } else {
1406
+ print_newline();
1407
+ }
1408
+ print_token();
1409
+ }
1410
+
1411
+ function handle_equals() {
1412
+ if (flags.var_line) {
1413
+ // just got an '=' in a var-line, different formatting/line-breaking, etc will now be done
1414
+ flags.var_line_tainted = true;
1415
+ }
1416
+ output_space_before_token = true;
1417
+ print_token();
1418
+ output_space_before_token = true;
1419
+ }
1420
+
1421
+ function handle_comma() {
1422
+ if (flags.var_line) {
1423
+ if (is_expression(flags.mode) || last_type === 'TK_END_BLOCK') {
1424
+ // do not break on comma, for(var a = 1, b = 2)
1425
+ flags.var_line_tainted = false;
1426
+ }
1427
+
1428
+ if (flags.var_line) {
1429
+ flags.var_line_reindented = true;
1430
+ }
1431
+
1432
+ print_token();
1433
+
1434
+ if (flags.var_line_tainted) {
1435
+ flags.var_line_tainted = false;
1436
+ print_newline();
1437
+ } else {
1438
+ output_space_before_token = true;
1439
+ }
1440
+ return;
1441
+ }
1442
+
1443
+ if (last_type === 'TK_END_BLOCK' && flags.mode !== MODE.Expression) {
1444
+ print_token();
1445
+ if (flags.mode === MODE.ObjectLiteral && flags.last_text === '}') {
1446
+ print_newline();
1447
+ } else {
1448
+ output_space_before_token = true;
1449
+ }
1450
+ } else {
1451
+ if (flags.mode === MODE.ObjectLiteral) {
1452
+ print_token();
1453
+ print_newline();
1454
+ } else {
1455
+ // EXPR or DO_BLOCK
1456
+ print_token();
1457
+ output_space_before_token = true;
1458
+ }
1459
+ }
1460
+ }
1461
+
1462
+ function handle_operator() {
1463
+ var space_before = true;
1464
+ var space_after = true;
1465
+ if (is_special_word(flags.last_text)) {
1466
+ // "return" had a special handling in TK_WORD. Now we need to return the favor
1467
+ output_space_before_token = true;
1468
+ print_token();
1469
+ return;
1470
+ }
1471
+
1472
+ // hack for actionscript's import .*;
1473
+ if (token_text === '*' && last_type === 'TK_DOT' && !last_last_text.match(/^\d+$/)) {
1474
+ print_token();
1475
+ return;
1476
+ }
1477
+
1478
+ if (token_text === ':' && flags.in_case) {
1479
+ flags.case_body = true;
1480
+ indent();
1481
+ print_token();
1482
+ print_newline();
1483
+ flags.in_case = false;
1484
+ return;
1485
+ }
1486
+
1487
+ if (token_text === '::') {
1488
+ // no spaces around exotic namespacing syntax operator
1489
+ print_token();
1490
+ return;
1491
+ }
1492
+
1493
+ // http://www.ecma-international.org/ecma-262/5.1/#sec-7.9.1
1494
+ // if there is a newline between -- or ++ and anything else we should preserve it.
1495
+ if (input_wanted_newline && (token_text === '--' || token_text === '++')) {
1496
+ print_newline();
1497
+ }
1498
+
1499
+ 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(flags.last_text, line_starters) || flags.last_text === ','))) {
1500
+ // unary operators (and binary +/- pretending to be unary) special cases
1501
+
1502
+ space_before = false;
1503
+ space_after = false;
1504
+
1505
+ if (flags.last_text === ';' && is_expression(flags.mode)) {
1506
+ // for (;; ++i)
1507
+ // ^^^
1508
+ space_before = true;
1509
+ }
1510
+
1511
+ if (last_type === 'TK_WORD' && in_array(flags.last_text, line_starters)) {
1512
+ space_before = true;
1513
+ }
1514
+
1515
+ if ((flags.mode === MODE.BlockStatement || flags.mode === MODE.Statement) && (flags.last_text === '{' || flags.last_text === ';')) {
1516
+ // { foo; --i }
1517
+ // foo(); --bar;
1518
+ print_newline();
1519
+ }
1520
+ } else if (token_text === ':') {
1521
+ if (flags.ternary_depth === 0) {
1522
+ if (flags.mode === MODE.BlockStatement) {
1523
+ flags.mode = MODE.ObjectLiteral;
1524
+ }
1525
+ space_before = false;
1526
+ } else {
1527
+ flags.ternary_depth -= 1;
1528
+ }
1529
+ } else if (token_text === '?') {
1530
+ flags.ternary_depth += 1;
1531
+ }
1532
+ output_space_before_token = output_space_before_token || space_before;
1533
+ print_token();
1534
+ output_space_before_token = space_after;
1535
+ }
1536
+
1537
+ function handle_block_comment() {
1538
+ var lines = split_newlines(token_text);
1539
+ var j; // iterator for this case
1540
+ var javadoc = false;
1541
+
1542
+ // block comment starts with a new line
1543
+ print_newline(false, true);
1544
+ if (lines.length > 1) {
1545
+ if (all_lines_start_with(lines.slice(1), '*')) {
1546
+ javadoc = true;
1547
+ }
1548
+ }
1549
+
1550
+ // first line always indented
1551
+ print_token(lines[0]);
1552
+ for (j = 1; j < lines.length; j++) {
1553
+ print_newline(false, true);
1554
+ if (javadoc) {
1555
+ // javadoc: reformat and re-indent
1556
+ print_token(' ' + trim(lines[j]));
1557
+ } else {
1558
+ // normal comments output raw
1559
+ output_lines[output_lines.length - 1].text.push(lines[j]);
1560
+ }
1561
+ }
1562
+
1563
+ // for comments of more than one line, make sure there's a new line after
1564
+ print_newline(false, true);
1565
+ }
1566
+
1567
+ function handle_inline_comment() {
1568
+ output_space_before_token = true;
1569
+ print_token();
1570
+ output_space_before_token = true;
1571
+ }
1572
+
1573
+ function handle_comment() {
1574
+ if (input_wanted_newline) {
1575
+ print_newline(false, true);
1576
+ } else {
1577
+ trim_output(true);
1578
+ }
1579
+
1580
+ output_space_before_token = true;
1581
+ print_token();
1582
+ print_newline(false, true);
1583
+ }
1584
+
1585
+ function handle_dot() {
1586
+ if (is_special_word(flags.last_text)) {
1587
+ output_space_before_token = true;
1588
+ } else {
1589
+ // allow preserved newlines before dots in general
1590
+ // force newlines on dots after close paren when break_chained - for bar().baz()
1591
+ allow_wrap_or_preserved_newline(flags.last_text === ')' && opt.break_chained_methods);
1592
+ }
1593
+
1594
+ print_token();
1595
+ }
1596
+
1597
+ function handle_unknown() {
1598
+ print_token();
1599
+
1600
+ if (token_text[token_text.length - 1] === '\n') {
1601
+ print_newline();
1602
+ }
1603
+ }
1604
+ }
1605
+
1606
+
1607
+ if (typeof define === "function") {
1608
+ // Add support for require.js
1609
+ if (typeof define.amd === "undefined") {
1610
+ define(function(require, exports, module) {
1611
+ exports.js_beautify = js_beautify;
1612
+ });
1613
+ } else {
1614
+ // if is AMD ( https://github.com/amdjs/amdjs-api/wiki/AMD#defineamd-property- )
1615
+ define([], function() {
1616
+ return js_beautify;
1617
+ });
1618
+ }
1619
+
1620
+ } else if (typeof exports !== "undefined") {
1621
+ // Add support for CommonJS. Just put this file somewhere on your require.paths
1622
+ // and you will be able to `var js_beautify = require("beautify").js_beautify`.
1623
+ exports.js_beautify = js_beautify;
1624
+ } else if (typeof window !== "undefined") {
1625
+ // If we're running a web page and don't have either of the above, add our one global
1626
+ window.js_beautify = js_beautify;
1627
+ } else if (typeof global !== "undefined") {
1628
+ // If we don't even have window, try global.
1629
+ global.js_beautify = js_beautify;
1630
+ }
1631
+
1632
+ }());