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,838 @@
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
+
29
+ Style HTML
30
+ ---------------
31
+
32
+ Written by Nochum Sossonko, (nsossonko@hotmail.com)
33
+
34
+ Based on code initially developed by: Einar Lielmanis, <elfz@laacz.lv>
35
+ http://jsbeautifier.org/
36
+
37
+ Usage:
38
+ style_html(html_source);
39
+
40
+ style_html(html_source, options);
41
+
42
+ The options are:
43
+ indent_inner_html (default false) — indent <head> and <body> sections,
44
+ indent_size (default 4) — indentation size,
45
+ indent_char (default space) — character to indent with,
46
+ wrap_line_length (default 250) - maximum amount of characters per line (0 = disable)
47
+ brace_style (default "collapse") - "collapse" | "expand" | "end-expand"
48
+ 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.
49
+ unformatted (defaults to inline tags) - list of tags, that shouldn't be reformatted
50
+ indent_scripts (default normal) - "keep"|"separate"|"normal"
51
+ preserve_newlines (default true) - whether existing line breaks before elements should be preserved
52
+ Only works before elements, not inside tags or for text.
53
+ max_preserve_newlines (default unlimited) - maximum number of line breaks to be preserved in one chunk
54
+ indent_handlebars (default false) - format and indent {{#foo}} and {{/foo}}
55
+
56
+ e.g.
57
+
58
+ style_html(html_source, {
59
+ 'indent_inner_html': false,
60
+ 'indent_size': 2,
61
+ 'indent_char': ' ',
62
+ 'wrap_line_length': 78,
63
+ 'brace_style': 'expand',
64
+ 'unformatted': ['a', 'sub', 'sup', 'b', 'i', 'u'],
65
+ 'preserve_newlines': true,
66
+ 'max_preserve_newlines': 5,
67
+ 'indent_handlebars': false
68
+ });
69
+ */
70
+
71
+ (function() {
72
+
73
+ function trim(s) {
74
+ return s.replace(/^\s+|\s+$/g, '');
75
+ }
76
+
77
+ function ltrim(s) {
78
+ return s.replace(/^\s+/g, '');
79
+ }
80
+
81
+ function style_html(html_source, options, js_beautify, css_beautify) {
82
+ //Wrapper function to invoke all the necessary constructors and deal with the output.
83
+
84
+ var multi_parser,
85
+ indent_inner_html,
86
+ indent_size,
87
+ indent_character,
88
+ wrap_line_length,
89
+ brace_style,
90
+ unformatted,
91
+ preserve_newlines,
92
+ max_preserve_newlines;
93
+
94
+ options = options || {};
95
+
96
+ // backwards compatibility to 1.3.4
97
+ if (options.wrap_line_length === undefined && options.max_char !== undefined) {
98
+ options.wrap_line_length = options.max_char;
99
+ }
100
+
101
+ indent_inner_html = options.indent_inner_html || false;
102
+ indent_size = parseInt(options.indent_size || 4, 10);
103
+ indent_character = options.indent_char || ' ';
104
+ brace_style = options.brace_style || 'collapse';
105
+ wrap_line_length = options.wrap_line_length === 0 ? 32786 : parseInt(options.wrap_line_length || 250, 10);
106
+ unformatted = options.unformatted || ['a', 'span', 'bdo', 'em', 'strong', 'dfn', 'code', 'samp', 'kbd', 'var', 'cite', 'abbr', 'acronym', 'q', 'sub', 'sup', 'tt', 'i', 'b', 'big', 'small', 'u', 's', 'strike', 'font', 'ins', 'del', 'pre', 'address', 'dt', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
107
+ preserve_newlines = options.preserve_newlines || true;
108
+ max_preserve_newlines = preserve_newlines ? parseInt(options.max_preserve_newlines || 32786, 10) : 0;
109
+ indent_handlebars = options.indent_handlebars || false;
110
+
111
+ function Parser() {
112
+
113
+ this.pos = 0; //Parser position
114
+ this.token = '';
115
+ this.current_mode = 'CONTENT'; //reflects the current Parser mode: TAG/CONTENT
116
+ this.tags = { //An object to hold tags, their position, and their parent-tags, initiated with default values
117
+ parent: 'parent1',
118
+ parentcount: 1,
119
+ parent1: ''
120
+ };
121
+ this.tag_type = '';
122
+ this.token_text = this.last_token = this.last_text = this.token_type = '';
123
+ this.newlines = 0;
124
+ this.indent_content = indent_inner_html;
125
+
126
+ this.Utils = { //Uilities made available to the various functions
127
+ whitespace: "\n\r\t ".split(''),
128
+ single_token: 'br,input,link,meta,!doctype,basefont,base,area,hr,wbr,param,img,isindex,?xml,embed,?php,?,?='.split(','), //all the single tags for HTML
129
+ extra_liners: 'head,body,/html'.split(','), //for tags that need a line of whitespace before them
130
+ in_array: function(what, arr) {
131
+ for (var i = 0; i < arr.length; i++) {
132
+ if (what === arr[i]) {
133
+ return true;
134
+ }
135
+ }
136
+ return false;
137
+ }
138
+ };
139
+
140
+ this.traverse_whitespace = function() {
141
+ var input_char = '';
142
+
143
+ input_char = this.input.charAt(this.pos);
144
+ if (this.Utils.in_array(input_char, this.Utils.whitespace)) {
145
+ this.newlines = 0;
146
+ while (this.Utils.in_array(input_char, this.Utils.whitespace)) {
147
+ if (preserve_newlines && input_char === '\n' && this.newlines <= max_preserve_newlines) {
148
+ this.newlines += 1;
149
+ }
150
+
151
+ this.pos++;
152
+ input_char = this.input.charAt(this.pos);
153
+ }
154
+ return true;
155
+ }
156
+ return false;
157
+ };
158
+
159
+ this.get_content = function() { //function to capture regular content between tags
160
+
161
+ var input_char = '',
162
+ content = [],
163
+ space = false; //if a space is needed
164
+
165
+ while (this.input.charAt(this.pos) !== '<') {
166
+ if (this.pos >= this.input.length) {
167
+ return content.length ? content.join('') : ['', 'TK_EOF'];
168
+ }
169
+
170
+ if (this.traverse_whitespace()) {
171
+ if (content.length) {
172
+ space = true;
173
+ }
174
+ continue; //don't want to insert unnecessary space
175
+ }
176
+
177
+ if (indent_handlebars) {
178
+ // Handlebars parsing is complicated.
179
+ // {{#foo}} and {{/foo}} are formatted tags.
180
+ // {{something}} should get treated as content, except:
181
+ // {{else}} specifically behaves like {{#if}} and {{/if}}
182
+ var peek3 = this.input.substr(this.pos, 3);
183
+ if (peek3 === '{{#' || peek3 === '{{/') {
184
+ // These are tags and not content.
185
+ break;
186
+ } else if (this.input.substr(this.pos, 2) === '{{') {
187
+ if (this.get_tag(true) === '{{else}}') {
188
+ break;
189
+ }
190
+ }
191
+ }
192
+
193
+ input_char = this.input.charAt(this.pos);
194
+ this.pos++;
195
+
196
+ if (space) {
197
+ if (this.line_char_count >= this.wrap_line_length) { //insert a line when the wrap_line_length is reached
198
+ this.print_newline(false, content);
199
+ this.print_indentation(content);
200
+ } else {
201
+ this.line_char_count++;
202
+ content.push(' ');
203
+ }
204
+ space = false;
205
+ }
206
+ this.line_char_count++;
207
+ content.push(input_char); //letter at-a-time (or string) inserted to an array
208
+ }
209
+ return content.length ? content.join('') : '';
210
+ };
211
+
212
+ this.get_contents_to = function(name) { //get the full content of a script or style to pass to js_beautify
213
+ if (this.pos === this.input.length) {
214
+ return ['', 'TK_EOF'];
215
+ }
216
+ var input_char = '';
217
+ var content = '';
218
+ var reg_match = new RegExp('</' + name + '\\s*>', 'igm');
219
+ reg_match.lastIndex = this.pos;
220
+ var reg_array = reg_match.exec(this.input);
221
+ var end_script = reg_array ? reg_array.index : this.input.length; //absolute end of script
222
+ if (this.pos < end_script) { //get everything in between the script tags
223
+ content = this.input.substring(this.pos, end_script);
224
+ this.pos = end_script;
225
+ }
226
+ return content;
227
+ };
228
+
229
+ this.record_tag = function(tag) { //function to record a tag and its parent in this.tags Object
230
+ if (this.tags[tag + 'count']) { //check for the existence of this tag type
231
+ this.tags[tag + 'count']++;
232
+ this.tags[tag + this.tags[tag + 'count']] = this.indent_level; //and record the present indent level
233
+ } else { //otherwise initialize this tag type
234
+ this.tags[tag + 'count'] = 1;
235
+ this.tags[tag + this.tags[tag + 'count']] = this.indent_level; //and record the present indent level
236
+ }
237
+ this.tags[tag + this.tags[tag + 'count'] + 'parent'] = this.tags.parent; //set the parent (i.e. in the case of a div this.tags.div1parent)
238
+ this.tags.parent = tag + this.tags[tag + 'count']; //and make this the current parent (i.e. in the case of a div 'div1')
239
+ };
240
+
241
+ this.retrieve_tag = function(tag) { //function to retrieve the opening tag to the corresponding closer
242
+ if (this.tags[tag + 'count']) { //if the openener is not in the Object we ignore it
243
+ var temp_parent = this.tags.parent; //check to see if it's a closable tag.
244
+ while (temp_parent) { //till we reach '' (the initial value);
245
+ if (tag + this.tags[tag + 'count'] === temp_parent) { //if this is it use it
246
+ break;
247
+ }
248
+ temp_parent = this.tags[temp_parent + 'parent']; //otherwise keep on climbing up the DOM Tree
249
+ }
250
+ if (temp_parent) { //if we caught something
251
+ this.indent_level = this.tags[tag + this.tags[tag + 'count']]; //set the indent_level accordingly
252
+ this.tags.parent = this.tags[temp_parent + 'parent']; //and set the current parent
253
+ }
254
+ delete this.tags[tag + this.tags[tag + 'count'] + 'parent']; //delete the closed tags parent reference...
255
+ delete this.tags[tag + this.tags[tag + 'count']]; //...and the tag itself
256
+ if (this.tags[tag + 'count'] === 1) {
257
+ delete this.tags[tag + 'count'];
258
+ } else {
259
+ this.tags[tag + 'count']--;
260
+ }
261
+ }
262
+ };
263
+
264
+ this.indent_to_tag = function(tag) {
265
+ // Match the indentation level to the last use of this tag, but don't remove it.
266
+ if (!this.tags[tag + 'count']) {
267
+ return;
268
+ }
269
+ var temp_parent = this.tags.parent;
270
+ while (temp_parent) {
271
+ if (tag + this.tags[tag + 'count'] === temp_parent) {
272
+ break;
273
+ }
274
+ temp_parent = this.tags[temp_parent + 'parent'];
275
+ }
276
+ if (temp_parent) {
277
+ this.indent_level = this.tags[tag + this.tags[tag + 'count']];
278
+ }
279
+ };
280
+
281
+ this.get_tag = function(peek) { //function to get a full tag and parse its type
282
+ var input_char = '',
283
+ content = [],
284
+ comment = '',
285
+ space = false,
286
+ tag_start, tag_end,
287
+ tag_start_char,
288
+ orig_pos = this.pos,
289
+ orig_line_char_count = this.line_char_count;
290
+
291
+ peek = peek !== undefined ? peek : false;
292
+
293
+ do {
294
+ if (this.pos >= this.input.length) {
295
+ if (peek) {
296
+ this.pos = orig_pos;
297
+ this.line_char_count = orig_line_char_count;
298
+ }
299
+ return content.length ? content.join('') : ['', 'TK_EOF'];
300
+ }
301
+
302
+ input_char = this.input.charAt(this.pos);
303
+ this.pos++;
304
+
305
+ if (this.Utils.in_array(input_char, this.Utils.whitespace)) { //don't want to insert unnecessary space
306
+ space = true;
307
+ continue;
308
+ }
309
+
310
+ if (input_char === "'" || input_char === '"') {
311
+ input_char += this.get_unformatted(input_char);
312
+ space = true;
313
+
314
+ }
315
+
316
+ if (input_char === '=') { //no space before =
317
+ space = false;
318
+ }
319
+
320
+ if (content.length && content[content.length - 1] !== '=' && input_char !== '>' && space) {
321
+ //no space after = or before >
322
+ if (this.line_char_count >= this.wrap_line_length) {
323
+ this.print_newline(false, content);
324
+ this.print_indentation(content);
325
+ } else {
326
+ content.push(' ');
327
+ this.line_char_count++;
328
+ }
329
+ space = false;
330
+ }
331
+
332
+ if (indent_handlebars && tag_start_char === '<') {
333
+ // When inside an angle-bracket tag, put spaces around
334
+ // handlebars not inside of strings.
335
+ if ((input_char + this.input.charAt(this.pos)) === '{{') {
336
+ input_char += this.get_unformatted('}}');
337
+ if (content.length && content[content.length - 1] !== ' ' && content[content.length - 1] !== '<') {
338
+ input_char = ' ' + input_char;
339
+ }
340
+ space = true;
341
+ }
342
+ }
343
+
344
+ if (input_char === '<' && !tag_start_char) {
345
+ tag_start = this.pos - 1;
346
+ tag_start_char = '<';
347
+ }
348
+
349
+ if (indent_handlebars && !tag_start_char) {
350
+ if (content.length >= 2 && content[content.length - 1] === '{' && content[content.length - 2] == '{') {
351
+ if (input_char === '#' || input_char === '/') {
352
+ tag_start = this.pos - 3;
353
+ } else {
354
+ tag_start = this.pos - 2;
355
+ }
356
+ tag_start_char = '{';
357
+ }
358
+ }
359
+
360
+ this.line_char_count++;
361
+ content.push(input_char); //inserts character at-a-time (or string)
362
+
363
+ if (content[1] && content[1] === '!') { //if we're in a comment, do something special
364
+ // We treat all comments as literals, even more than preformatted tags
365
+ // we just look for the appropriate close tag
366
+ content = [this.get_comment(tag_start)];
367
+ break;
368
+ }
369
+
370
+ if (indent_handlebars && tag_start_char === '{' && content.length > 2 && content[content.length - 2] === '}' && content[content.length - 1] === '}') {
371
+ break;
372
+ }
373
+ } while (input_char !== '>');
374
+
375
+ var tag_complete = content.join('');
376
+ var tag_index;
377
+ var tag_offset;
378
+
379
+ if (tag_complete.indexOf(' ') !== -1) { //if there's whitespace, thats where the tag name ends
380
+ tag_index = tag_complete.indexOf(' ');
381
+ } else if (tag_complete[0] === '{') {
382
+ tag_index = tag_complete.indexOf('}');
383
+ } else { //otherwise go with the tag ending
384
+ tag_index = tag_complete.indexOf('>');
385
+ }
386
+ if (tag_complete[0] === '<' || !indent_handlebars) {
387
+ tag_offset = 1;
388
+ } else {
389
+ tag_offset = tag_complete[2] === '#' ? 3 : 2;
390
+ }
391
+ var tag_check = tag_complete.substring(tag_offset, tag_index).toLowerCase();
392
+ if (tag_complete.charAt(tag_complete.length - 2) === '/' ||
393
+ this.Utils.in_array(tag_check, this.Utils.single_token)) { //if this tag name is a single tag type (either in the list or has a closing /)
394
+ if (!peek) {
395
+ this.tag_type = 'SINGLE';
396
+ }
397
+ } else if (indent_handlebars && tag_complete[0] === '{' && tag_check === 'else') {
398
+ if (!peek) {
399
+ this.indent_to_tag('if');
400
+ this.tag_type = 'HANDLEBARS_ELSE';
401
+ this.indent_content = true;
402
+ this.traverse_whitespace();
403
+ }
404
+ } else if (tag_check === 'script') { //for later script handling
405
+ if (!peek) {
406
+ this.record_tag(tag_check);
407
+ this.tag_type = 'SCRIPT';
408
+ }
409
+ } else if (tag_check === 'style') { //for future style handling (for now it justs uses get_content)
410
+ if (!peek) {
411
+ this.record_tag(tag_check);
412
+ this.tag_type = 'STYLE';
413
+ }
414
+ } else if (this.is_unformatted(tag_check, unformatted)) { // do not reformat the "unformatted" tags
415
+ comment = this.get_unformatted('</' + tag_check + '>', tag_complete); //...delegate to get_unformatted function
416
+ content.push(comment);
417
+ // Preserve collapsed whitespace either before or after this tag.
418
+ if (tag_start > 0 && this.Utils.in_array(this.input.charAt(tag_start - 1), this.Utils.whitespace)) {
419
+ content.splice(0, 0, this.input.charAt(tag_start - 1));
420
+ }
421
+ tag_end = this.pos - 1;
422
+ if (this.Utils.in_array(this.input.charAt(tag_end + 1), this.Utils.whitespace)) {
423
+ content.push(this.input.charAt(tag_end + 1));
424
+ }
425
+ this.tag_type = 'SINGLE';
426
+ } else if (tag_check.charAt(0) === '!') { //peek for <! comment
427
+ // for comments content is already correct.
428
+ if (!peek) {
429
+ this.tag_type = 'SINGLE';
430
+ this.traverse_whitespace();
431
+ }
432
+ } else if (!peek) {
433
+ if (tag_check.charAt(0) === '/') { //this tag is a double tag so check for tag-ending
434
+ this.retrieve_tag(tag_check.substring(1)); //remove it and all ancestors
435
+ this.tag_type = 'END';
436
+ this.traverse_whitespace();
437
+ } else { //otherwise it's a start-tag
438
+ this.record_tag(tag_check); //push it on the tag stack
439
+ if (tag_check.toLowerCase() !== 'html') {
440
+ this.indent_content = true;
441
+ }
442
+ this.tag_type = 'START';
443
+
444
+ // Allow preserving of newlines after a start tag
445
+ this.traverse_whitespace();
446
+ }
447
+ if (this.Utils.in_array(tag_check, this.Utils.extra_liners)) { //check if this double needs an extra line
448
+ this.print_newline(false, this.output);
449
+ if (this.output.length && this.output[this.output.length - 2] !== '\n') {
450
+ this.print_newline(true, this.output);
451
+ }
452
+ }
453
+ }
454
+
455
+ if (peek) {
456
+ this.pos = orig_pos;
457
+ this.line_char_count = orig_line_char_count;
458
+ }
459
+
460
+ return content.join(''); //returns fully formatted tag
461
+ };
462
+
463
+ this.get_comment = function(start_pos) { //function to return comment content in its entirety
464
+ // this is will have very poor perf, but will work for now.
465
+ var comment = '',
466
+ delimiter = '>',
467
+ matched = false;
468
+
469
+ this.pos = start_pos;
470
+ input_char = this.input.charAt(this.pos);
471
+ this.pos++;
472
+
473
+ while (this.pos <= this.input.length) {
474
+ comment += input_char;
475
+
476
+ // only need to check for the delimiter if the last chars match
477
+ if (comment[comment.length - 1] === delimiter[delimiter.length - 1] &&
478
+ comment.indexOf(delimiter) !== -1) {
479
+ break;
480
+ }
481
+
482
+ // only need to search for custom delimiter for the first few characters
483
+ if (!matched && comment.length < 10) {
484
+ if (comment.indexOf('<![if') === 0) { //peek for <![if conditional comment
485
+ delimiter = '<![endif]>';
486
+ matched = true;
487
+ } else if (comment.indexOf('<![cdata[') === 0) { //if it's a <[cdata[ comment...
488
+ delimiter = ']]>';
489
+ matched = true;
490
+ } else if (comment.indexOf('<![') === 0) { // some other ![ comment? ...
491
+ delimiter = ']>';
492
+ matched = true;
493
+ } else if (comment.indexOf('<!--') === 0) { // <!-- comment ...
494
+ delimiter = '-->';
495
+ matched = true;
496
+ }
497
+ }
498
+
499
+ input_char = this.input.charAt(this.pos);
500
+ this.pos++;
501
+ }
502
+
503
+ return comment;
504
+ };
505
+
506
+ this.get_unformatted = function(delimiter, orig_tag) { //function to return unformatted content in its entirety
507
+
508
+ if (orig_tag && orig_tag.toLowerCase().indexOf(delimiter) !== -1) {
509
+ return '';
510
+ }
511
+ var input_char = '';
512
+ var content = '';
513
+ var min_index = 0;
514
+ var space = true;
515
+ do {
516
+
517
+ if (this.pos >= this.input.length) {
518
+ return content;
519
+ }
520
+
521
+ input_char = this.input.charAt(this.pos);
522
+ this.pos++;
523
+
524
+ if (this.Utils.in_array(input_char, this.Utils.whitespace)) {
525
+ if (!space) {
526
+ this.line_char_count--;
527
+ continue;
528
+ }
529
+ if (input_char === '\n' || input_char === '\r') {
530
+ content += '\n';
531
+ /* Don't change tab indention for unformatted blocks. If using code for html editing, this will greatly affect <pre> tags if they are specified in the 'unformatted array'
532
+ for (var i=0; i<this.indent_level; i++) {
533
+ content += this.indent_string;
534
+ }
535
+ space = false; //...and make sure other indentation is erased
536
+ */
537
+ this.line_char_count = 0;
538
+ continue;
539
+ }
540
+ }
541
+ content += input_char;
542
+ this.line_char_count++;
543
+ space = true;
544
+
545
+ if (indent_handlebars && input_char === '{' && content.length && content[content.length - 2] === '{') {
546
+ // Handlebars expressions in strings should also be unformatted.
547
+ content += this.get_unformatted('}}');
548
+ // These expressions are opaque. Ignore delimiters found in them.
549
+ min_index = content.length;
550
+ }
551
+ } while (content.toLowerCase().indexOf(delimiter, min_index) === -1);
552
+ return content;
553
+ };
554
+
555
+ this.get_token = function() { //initial handler for token-retrieval
556
+ var token;
557
+
558
+ if (this.last_token === 'TK_TAG_SCRIPT' || this.last_token === 'TK_TAG_STYLE') { //check if we need to format javascript
559
+ var type = this.last_token.substr(7);
560
+ token = this.get_contents_to(type);
561
+ if (typeof token !== 'string') {
562
+ return token;
563
+ }
564
+ return [token, 'TK_' + type];
565
+ }
566
+ if (this.current_mode === 'CONTENT') {
567
+ token = this.get_content();
568
+ if (typeof token !== 'string') {
569
+ return token;
570
+ } else {
571
+ return [token, 'TK_CONTENT'];
572
+ }
573
+ }
574
+
575
+ if (this.current_mode === 'TAG') {
576
+ token = this.get_tag();
577
+ if (typeof token !== 'string') {
578
+ return token;
579
+ } else {
580
+ var tag_name_type = 'TK_TAG_' + this.tag_type;
581
+ return [token, tag_name_type];
582
+ }
583
+ }
584
+ };
585
+
586
+ this.get_full_indent = function(level) {
587
+ level = this.indent_level + level || 0;
588
+ if (level < 1) {
589
+ return '';
590
+ }
591
+
592
+ return Array(level + 1).join(this.indent_string);
593
+ };
594
+
595
+ this.is_unformatted = function(tag_check, unformatted) {
596
+ //is this an HTML5 block-level link?
597
+ if (!this.Utils.in_array(tag_check, unformatted)) {
598
+ return false;
599
+ }
600
+
601
+ if (tag_check.toLowerCase() !== 'a' || !this.Utils.in_array('a', unformatted)) {
602
+ return true;
603
+ }
604
+
605
+ //at this point we have an tag; is its first child something we want to remain
606
+ //unformatted?
607
+ var next_tag = this.get_tag(true /* peek. */ );
608
+
609
+ // tets next_tag to see if it is just html tag (no external content)
610
+ var tag = (next_tag || "").match(/^\s*<\s*\/?([a-z]*)\s*[^>]*>\s*$/);
611
+
612
+ // if next_tag comes back but is not an isolated tag, then
613
+ // let's treat the 'a' tag as having content
614
+ // and respect the unformatted option
615
+ if (!tag || this.Utils.in_array(tag, unformatted)) {
616
+ return true;
617
+ } else {
618
+ return false;
619
+ }
620
+ };
621
+
622
+ this.printer = function(js_source, indent_character, indent_size, wrap_line_length, brace_style) { //handles input/output and some other printing functions
623
+
624
+ this.input = js_source || ''; //gets the input for the Parser
625
+ this.output = [];
626
+ this.indent_character = indent_character;
627
+ this.indent_string = '';
628
+ this.indent_size = indent_size;
629
+ this.brace_style = brace_style;
630
+ this.indent_level = 0;
631
+ this.wrap_line_length = wrap_line_length;
632
+ this.line_char_count = 0; //count to see if wrap_line_length was exceeded
633
+
634
+ for (var i = 0; i < this.indent_size; i++) {
635
+ this.indent_string += this.indent_character;
636
+ }
637
+
638
+ this.print_newline = function(force, arr) {
639
+ this.line_char_count = 0;
640
+ if (!arr || !arr.length) {
641
+ return;
642
+ }
643
+ if (force || (arr[arr.length - 1] !== '\n')) { //we might want the extra line
644
+ arr.push('\n');
645
+ }
646
+ };
647
+
648
+ this.print_indentation = function(arr) {
649
+ for (var i = 0; i < this.indent_level; i++) {
650
+ arr.push(this.indent_string);
651
+ this.line_char_count += this.indent_string.length;
652
+ }
653
+ };
654
+
655
+ this.print_token = function(text) {
656
+ if (text || text !== '') {
657
+ if (this.output.length && this.output[this.output.length - 1] === '\n') {
658
+ this.print_indentation(this.output);
659
+ text = ltrim(text);
660
+ }
661
+ }
662
+ this.print_token_raw(text);
663
+ };
664
+
665
+ this.print_token_raw = function(text) {
666
+ if (text && text !== '') {
667
+ if (text.length > 1 && text[text.length - 1] === '\n') {
668
+ // unformatted tags can grab newlines as their last character
669
+ this.output.push(text.slice(0, -1));
670
+ this.print_newline(false, this.output);
671
+ } else {
672
+ this.output.push(text);
673
+ }
674
+ }
675
+
676
+ for (var n = 0; n < this.newlines; n++) {
677
+ this.print_newline(n > 0, this.output);
678
+ }
679
+ this.newlines = 0;
680
+ };
681
+
682
+ this.indent = function() {
683
+ this.indent_level++;
684
+ };
685
+
686
+ this.unindent = function() {
687
+ if (this.indent_level > 0) {
688
+ this.indent_level--;
689
+ }
690
+ };
691
+ };
692
+ return this;
693
+ }
694
+
695
+ /*_____________________--------------------_____________________*/
696
+
697
+ multi_parser = new Parser(); //wrapping functions Parser
698
+ multi_parser.printer(html_source, indent_character, indent_size, wrap_line_length, brace_style); //initialize starting values
699
+
700
+ while (true) {
701
+ var t = multi_parser.get_token();
702
+ multi_parser.token_text = t[0];
703
+ multi_parser.token_type = t[1];
704
+
705
+ if (multi_parser.token_type === 'TK_EOF') {
706
+ break;
707
+ }
708
+
709
+ switch (multi_parser.token_type) {
710
+ case 'TK_TAG_START':
711
+ multi_parser.print_newline(false, multi_parser.output);
712
+ multi_parser.print_token(multi_parser.token_text);
713
+ if (multi_parser.indent_content) {
714
+ multi_parser.indent();
715
+ multi_parser.indent_content = false;
716
+ }
717
+ multi_parser.current_mode = 'CONTENT';
718
+ break;
719
+ case 'TK_TAG_STYLE':
720
+ case 'TK_TAG_SCRIPT':
721
+ multi_parser.print_newline(false, multi_parser.output);
722
+ multi_parser.print_token(multi_parser.token_text);
723
+ multi_parser.current_mode = 'CONTENT';
724
+ break;
725
+ case 'TK_TAG_END':
726
+ //Print new line only if the tag has no content and has child
727
+ if (multi_parser.last_token === 'TK_CONTENT' && multi_parser.last_text === '') {
728
+ var tag_name = multi_parser.token_text.match(/\w+/)[0];
729
+ var tag_extracted_from_last_output = null;
730
+ if (multi_parser.output.length) {
731
+ tag_extracted_from_last_output = multi_parser.output[multi_parser.output.length - 1].match(/(?:<|{{#)\s*(\w+)/);
732
+ }
733
+ if (tag_extracted_from_last_output === null ||
734
+ tag_extracted_from_last_output[1] !== tag_name) {
735
+ multi_parser.print_newline(false, multi_parser.output);
736
+ }
737
+ }
738
+ multi_parser.print_token(multi_parser.token_text);
739
+ multi_parser.current_mode = 'CONTENT';
740
+ break;
741
+ case 'TK_TAG_SINGLE':
742
+ // Don't add a newline before elements that should remain unformatted.
743
+ var tag_check = multi_parser.token_text.match(/^\s*<([a-z]+)/i);
744
+ if (!tag_check || !multi_parser.Utils.in_array(tag_check[1], unformatted)) {
745
+ multi_parser.print_newline(false, multi_parser.output);
746
+ }
747
+ multi_parser.print_token(multi_parser.token_text);
748
+ multi_parser.current_mode = 'CONTENT';
749
+ break;
750
+ case 'TK_TAG_HANDLEBARS_ELSE':
751
+ multi_parser.print_token(multi_parser.token_text);
752
+ if (multi_parser.indent_content) {
753
+ multi_parser.indent();
754
+ multi_parser.indent_content = false;
755
+ }
756
+ multi_parser.current_mode = 'CONTENT';
757
+ break;
758
+ case 'TK_CONTENT':
759
+ multi_parser.print_token(multi_parser.token_text);
760
+ multi_parser.current_mode = 'TAG';
761
+ break;
762
+ case 'TK_STYLE':
763
+ case 'TK_SCRIPT':
764
+ if (multi_parser.token_text !== '') {
765
+ multi_parser.print_newline(false, multi_parser.output);
766
+ var text = multi_parser.token_text,
767
+ _beautifier,
768
+ script_indent_level = 1;
769
+ if (multi_parser.token_type === 'TK_SCRIPT') {
770
+ _beautifier = typeof js_beautify === 'function' && js_beautify;
771
+ } else if (multi_parser.token_type === 'TK_STYLE') {
772
+ _beautifier = typeof css_beautify === 'function' && css_beautify;
773
+ }
774
+
775
+ if (options.indent_scripts === "keep") {
776
+ script_indent_level = 0;
777
+ } else if (options.indent_scripts === "separate") {
778
+ script_indent_level = -multi_parser.indent_level;
779
+ }
780
+
781
+ var indentation = multi_parser.get_full_indent(script_indent_level);
782
+ if (_beautifier) {
783
+ // call the Beautifier if avaliable
784
+ text = _beautifier(text.replace(/^\s*/, indentation), options);
785
+ } else {
786
+ // simply indent the string otherwise
787
+ var white = text.match(/^\s*/)[0];
788
+ var _level = white.match(/[^\n\r]*$/)[0].split(multi_parser.indent_string).length - 1;
789
+ var reindent = multi_parser.get_full_indent(script_indent_level - _level);
790
+ text = text.replace(/^\s*/, indentation)
791
+ .replace(/\r\n|\r|\n/g, '\n' + reindent)
792
+ .replace(/\s+$/, '');
793
+ }
794
+ if (text) {
795
+ multi_parser.print_token_raw(indentation + trim(text));
796
+ multi_parser.print_newline(false, multi_parser.output);
797
+ }
798
+ }
799
+ multi_parser.current_mode = 'TAG';
800
+ break;
801
+ }
802
+ multi_parser.last_token = multi_parser.token_type;
803
+ multi_parser.last_text = multi_parser.token_text;
804
+ }
805
+ return multi_parser.output.join('');
806
+ }
807
+
808
+ if (typeof define === "function") {
809
+ // Add support for require.js
810
+ define(["./beautify.js", "./beautify-css.js"], function(js_beautify, css_beautify) {
811
+ return {
812
+ html_beautify: function(html_source, options) {
813
+ return style_html(html_source, options, js_beautify, css_beautify);
814
+ }
815
+ };
816
+ });
817
+ } else if (typeof exports !== "undefined") {
818
+ // Add support for CommonJS. Just put this file somewhere on your require.paths
819
+ // and you will be able to `var html_beautify = require("beautify").html_beautify`.
820
+ var js_beautify = require('./beautify.js').js_beautify;
821
+ var css_beautify = require('./beautify-css.js').css_beautify;
822
+
823
+ exports.html_beautify = function(html_source, options) {
824
+ return style_html(html_source, options, js_beautify, css_beautify);
825
+ };
826
+ } else if (typeof window !== "undefined") {
827
+ // If we're running a web page and don't have either of the above, add our one global
828
+ window.html_beautify = function(html_source, options) {
829
+ return style_html(html_source, options, window.js_beautify, window.css_beautify);
830
+ };
831
+ } else if (typeof global !== "undefined") {
832
+ // If we don't even have window, try global.
833
+ global.html_beautify = function(html_source, options) {
834
+ return style_html(html_source, options, global.js_beautify, global.css_beautify);
835
+ };
836
+ }
837
+
838
+ }());