haml 3.2.0.alpha.10 → 3.2.0.alpha.13

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of haml might be problematic. Click here for more details.

Files changed (389) hide show
  1. data/.yardopts +19 -7
  2. data/CHANGELOG.md +1224 -0
  3. data/FAQ.md +157 -0
  4. data/README.md +99 -62
  5. data/REFERENCE.md +1404 -0
  6. data/Rakefile +52 -341
  7. data/init.rb +1 -18
  8. data/lib/haml.rb +6 -30
  9. data/lib/haml/buffer.rb +37 -16
  10. data/lib/haml/compiler.rb +52 -13
  11. data/lib/haml/engine.rb +61 -44
  12. data/lib/haml/exec.rb +21 -4
  13. data/lib/haml/filters.rb +136 -166
  14. data/lib/haml/helpers.rb +37 -10
  15. data/lib/haml/helpers/action_view_extensions.rb +2 -1
  16. data/lib/haml/helpers/action_view_mods.rb +67 -181
  17. data/lib/haml/helpers/rails_323_textarea_fix.rb +39 -0
  18. data/lib/haml/helpers/xss_mods.rb +9 -11
  19. data/lib/haml/html.rb +22 -9
  20. data/lib/haml/html/erb.rb +1 -1
  21. data/lib/haml/parser.rb +22 -15
  22. data/lib/haml/railtie.rb +2 -13
  23. data/lib/haml/template.rb +18 -85
  24. data/lib/haml/template/options.rb +1 -1
  25. data/lib/haml/template/plugin.rb +15 -101
  26. data/lib/haml/util.rb +120 -603
  27. data/lib/haml/version.rb +1 -107
  28. data/test/{haml/engine_test.rb → engine_test.rb} +137 -143
  29. data/test/{haml/erb → erb}/_av_partial_1.erb +1 -1
  30. data/test/{haml/erb → erb}/_av_partial_2.erb +1 -1
  31. data/test/{haml/erb → erb}/action_view.erb +1 -1
  32. data/test/{haml/erb → erb}/standard.erb +0 -0
  33. data/test/filters_test.rb +141 -0
  34. data/test/gemfiles/Gemfile.rails-3.0.x +4 -6
  35. data/test/gemfiles/Gemfile.rails-3.1.x +5 -6
  36. data/test/gemfiles/Gemfile.rails-3.2.x +6 -0
  37. data/test/haml-spec/LICENSE +14 -0
  38. data/test/{haml/spec → haml-spec}/README.md +26 -17
  39. data/test/haml-spec/lua_haml_spec.lua +38 -0
  40. data/test/haml-spec/perl_haml_test.pl +81 -0
  41. data/test/haml-spec/ruby_haml_test.rb +23 -0
  42. data/test/{haml/spec → haml-spec}/tests.json +132 -54
  43. data/test/{haml/helper_test.rb → helper_test.rb} +50 -36
  44. data/test/{haml/html2haml → html2haml}/erb_tests.rb +0 -0
  45. data/test/{haml/html2haml_test.rb → html2haml_test.rb} +11 -5
  46. data/test/{haml/markaby → markaby}/standard.mab +0 -0
  47. data/test/{haml/mocks → mocks}/article.rb +0 -0
  48. data/test/{haml/results → results}/content_for_layout.xhtml +0 -0
  49. data/test/{haml/results → results}/eval_suppressed.xhtml +0 -0
  50. data/test/{haml/results → results}/helpers.xhtml +0 -0
  51. data/test/{haml/results → results}/helpful.xhtml +0 -0
  52. data/test/{haml/results → results}/just_stuff.xhtml +0 -0
  53. data/test/{haml/results → results}/list.xhtml +0 -0
  54. data/test/{haml/results → results}/nuke_inner_whitespace.xhtml +0 -0
  55. data/test/{haml/results → results}/nuke_outer_whitespace.xhtml +0 -0
  56. data/test/{haml/results → results}/original_engine.xhtml +0 -0
  57. data/test/{haml/results → results}/partial_layout.xhtml +0 -0
  58. data/test/{haml/results → results}/partials.xhtml +0 -0
  59. data/test/{haml/results → results}/render_layout.xhtml +0 -0
  60. data/test/{haml/results → results}/silent_script.xhtml +1 -1
  61. data/test/{haml/results → results}/standard.xhtml +0 -0
  62. data/test/{haml/results → results}/tag_parsing.xhtml +0 -0
  63. data/test/{haml/results → results}/very_basic.xhtml +0 -0
  64. data/test/{haml/results → results}/whitespace_handling.xhtml +46 -50
  65. data/test/{haml/template_test.rb → template_test.rb} +20 -81
  66. data/test/{haml/templates → templates}/_av_partial_1.haml +1 -1
  67. data/test/{haml/templates → templates}/_av_partial_1_ugly.haml +1 -1
  68. data/test/{haml/templates → templates}/_av_partial_2.haml +1 -1
  69. data/test/{haml/templates → templates}/_av_partial_2_ugly.haml +1 -1
  70. data/test/{haml/templates → templates}/_layout.erb +0 -0
  71. data/test/{haml/templates → templates}/_layout_for_partial.haml +0 -0
  72. data/test/{haml/templates → templates}/_partial.haml +0 -0
  73. data/test/{haml/templates → templates}/_text_area.haml +0 -0
  74. data/test/{haml/templates → templates}/action_view.haml +1 -1
  75. data/test/{haml/templates → templates}/action_view_ugly.haml +1 -1
  76. data/test/{haml/templates → templates}/breakage.haml +0 -0
  77. data/test/{haml/templates → templates}/content_for_layout.haml +0 -0
  78. data/test/{haml/templates → templates}/eval_suppressed.haml +0 -0
  79. data/test/{haml/templates → templates}/helpers.haml +0 -0
  80. data/test/{haml/templates → templates}/helpful.haml +0 -0
  81. data/test/{haml/templates → templates}/just_stuff.haml +0 -0
  82. data/test/{haml/templates → templates}/list.haml +0 -0
  83. data/test/{haml/templates → templates}/nuke_inner_whitespace.haml +0 -0
  84. data/test/{haml/templates → templates}/nuke_outer_whitespace.haml +0 -0
  85. data/test/{haml/templates → templates}/original_engine.haml +0 -0
  86. data/test/templates/partial_layout.haml +3 -0
  87. data/test/{haml/templates → templates}/partialize.haml +0 -0
  88. data/test/{haml/templates → templates}/partials.haml +0 -0
  89. data/test/{haml/templates → templates}/render_layout.haml +0 -0
  90. data/test/{haml/templates → templates}/silent_script.haml +2 -2
  91. data/test/{haml/templates → templates}/standard.haml +0 -0
  92. data/test/{haml/templates → templates}/standard_ugly.haml +0 -0
  93. data/test/{haml/templates → templates}/tag_parsing.haml +0 -0
  94. data/test/{haml/templates → templates}/very_basic.haml +0 -0
  95. data/test/{haml/templates → templates}/whitespace_handling.haml +0 -0
  96. data/test/test_helper.rb +42 -34
  97. data/test/util_test.rb +80 -0
  98. metadata +259 -427
  99. data/CONTRIBUTING +0 -3
  100. data/REVISION +0 -1
  101. data/VERSION +0 -1
  102. data/VERSION_NAME +0 -1
  103. data/extra/update_watch.rb +0 -13
  104. data/lib/haml/root.rb +0 -7
  105. data/lib/haml/shared.rb +0 -78
  106. data/lib/haml/template/patch.rb +0 -58
  107. data/lib/sass.rb +0 -8
  108. data/lib/sass/plugin.rb +0 -10
  109. data/lib/sass/rails2_shim.rb +0 -9
  110. data/lib/sass/rails3_shim.rb +0 -16
  111. data/test/benchmark.rb +0 -91
  112. data/test/gemfiles/Gemfile.rails-2.0.x +0 -8
  113. data/test/gemfiles/Gemfile.rails-2.0.x.lock +0 -38
  114. data/test/gemfiles/Gemfile.rails-2.1.x +0 -8
  115. data/test/gemfiles/Gemfile.rails-2.1.x.lock +0 -38
  116. data/test/gemfiles/Gemfile.rails-2.2.x +0 -8
  117. data/test/gemfiles/Gemfile.rails-2.2.x.lock +0 -38
  118. data/test/gemfiles/Gemfile.rails-2.3.x +0 -8
  119. data/test/gemfiles/Gemfile.rails-2.3.x.lock +0 -40
  120. data/test/gemfiles/Gemfile.rails-3.0.x.lock +0 -85
  121. data/test/gemfiles/Gemfile.rails-3.1.x.lock +0 -98
  122. data/test/gemfiles/Gemfile.rails-xss-2.3.x +0 -9
  123. data/test/gemfiles/Gemfile.rails-xss-2.3.x.lock +0 -42
  124. data/test/haml/results/filters.xhtml +0 -62
  125. data/test/haml/spec/lua_haml_spec.lua +0 -30
  126. data/test/haml/spec/ruby_haml_test.rb +0 -19
  127. data/test/haml/spec_test.rb +0 -44
  128. data/test/haml/templates/filters.haml +0 -66
  129. data/test/haml/templates/partial_layout.haml +0 -10
  130. data/test/haml/util_test.rb +0 -300
  131. data/test/linked_rails.rb +0 -42
  132. data/vendor/sass/CONTRIBUTING +0 -3
  133. data/vendor/sass/MIT-LICENSE +0 -20
  134. data/vendor/sass/README.md +0 -201
  135. data/vendor/sass/Rakefile +0 -339
  136. data/vendor/sass/TODO +0 -39
  137. data/vendor/sass/VERSION +0 -1
  138. data/vendor/sass/VERSION_NAME +0 -1
  139. data/vendor/sass/bin/sass +0 -8
  140. data/vendor/sass/bin/sass-convert +0 -7
  141. data/vendor/sass/bin/scss +0 -8
  142. data/vendor/sass/doc-src/FAQ.md +0 -35
  143. data/vendor/sass/doc-src/INDENTED_SYNTAX.md +0 -210
  144. data/vendor/sass/doc-src/SASS_CHANGELOG.md +0 -2327
  145. data/vendor/sass/doc-src/SASS_REFERENCE.md +0 -1965
  146. data/vendor/sass/doc-src/SCSS_FOR_SASS_USERS.md +0 -155
  147. data/vendor/sass/ext/extconf.rb +0 -10
  148. data/vendor/sass/extra/update_watch.rb +0 -13
  149. data/vendor/sass/init.rb +0 -18
  150. data/vendor/sass/lib/sass.rb +0 -73
  151. data/vendor/sass/lib/sass/cache_stores.rb +0 -15
  152. data/vendor/sass/lib/sass/cache_stores/base.rb +0 -86
  153. data/vendor/sass/lib/sass/cache_stores/chain.rb +0 -33
  154. data/vendor/sass/lib/sass/cache_stores/filesystem.rb +0 -60
  155. data/vendor/sass/lib/sass/cache_stores/memory.rb +0 -47
  156. data/vendor/sass/lib/sass/cache_stores/null.rb +0 -25
  157. data/vendor/sass/lib/sass/callbacks.rb +0 -66
  158. data/vendor/sass/lib/sass/css.rb +0 -295
  159. data/vendor/sass/lib/sass/engine.rb +0 -878
  160. data/vendor/sass/lib/sass/environment.rb +0 -166
  161. data/vendor/sass/lib/sass/error.rb +0 -201
  162. data/vendor/sass/lib/sass/exec.rb +0 -672
  163. data/vendor/sass/lib/sass/importers.rb +0 -22
  164. data/vendor/sass/lib/sass/importers/base.rb +0 -139
  165. data/vendor/sass/lib/sass/importers/filesystem.rb +0 -149
  166. data/vendor/sass/lib/sass/less.rb +0 -382
  167. data/vendor/sass/lib/sass/logger.rb +0 -15
  168. data/vendor/sass/lib/sass/logger/base.rb +0 -32
  169. data/vendor/sass/lib/sass/logger/log_level.rb +0 -49
  170. data/vendor/sass/lib/sass/plugin.rb +0 -132
  171. data/vendor/sass/lib/sass/plugin/compiler.rb +0 -383
  172. data/vendor/sass/lib/sass/plugin/configuration.rb +0 -123
  173. data/vendor/sass/lib/sass/plugin/generic.rb +0 -15
  174. data/vendor/sass/lib/sass/plugin/merb.rb +0 -48
  175. data/vendor/sass/lib/sass/plugin/rack.rb +0 -60
  176. data/vendor/sass/lib/sass/plugin/rails.rb +0 -47
  177. data/vendor/sass/lib/sass/plugin/staleness_checker.rb +0 -173
  178. data/vendor/sass/lib/sass/railtie.rb +0 -9
  179. data/vendor/sass/lib/sass/repl.rb +0 -58
  180. data/vendor/sass/lib/sass/root.rb +0 -7
  181. data/vendor/sass/lib/sass/script.rb +0 -40
  182. data/vendor/sass/lib/sass/script/bool.rb +0 -18
  183. data/vendor/sass/lib/sass/script/color.rb +0 -480
  184. data/vendor/sass/lib/sass/script/css_lexer.rb +0 -29
  185. data/vendor/sass/lib/sass/script/css_parser.rb +0 -31
  186. data/vendor/sass/lib/sass/script/funcall.rb +0 -175
  187. data/vendor/sass/lib/sass/script/functions.rb +0 -1386
  188. data/vendor/sass/lib/sass/script/interpolation.rb +0 -79
  189. data/vendor/sass/lib/sass/script/lexer.rb +0 -339
  190. data/vendor/sass/lib/sass/script/list.rb +0 -83
  191. data/vendor/sass/lib/sass/script/literal.rb +0 -250
  192. data/vendor/sass/lib/sass/script/node.rb +0 -99
  193. data/vendor/sass/lib/sass/script/number.rb +0 -452
  194. data/vendor/sass/lib/sass/script/operation.rb +0 -99
  195. data/vendor/sass/lib/sass/script/parser.rb +0 -474
  196. data/vendor/sass/lib/sass/script/string.rb +0 -51
  197. data/vendor/sass/lib/sass/script/string_interpolation.rb +0 -103
  198. data/vendor/sass/lib/sass/script/unary_operation.rb +0 -64
  199. data/vendor/sass/lib/sass/script/variable.rb +0 -59
  200. data/vendor/sass/lib/sass/scss.rb +0 -17
  201. data/vendor/sass/lib/sass/scss/css_parser.rb +0 -46
  202. data/vendor/sass/lib/sass/scss/parser.rb +0 -960
  203. data/vendor/sass/lib/sass/scss/rx.rb +0 -128
  204. data/vendor/sass/lib/sass/scss/sass_parser.rb +0 -11
  205. data/vendor/sass/lib/sass/scss/script_lexer.rb +0 -15
  206. data/vendor/sass/lib/sass/scss/script_parser.rb +0 -25
  207. data/vendor/sass/lib/sass/scss/static_parser.rb +0 -40
  208. data/vendor/sass/lib/sass/selector.rb +0 -361
  209. data/vendor/sass/lib/sass/selector/abstract_sequence.rb +0 -62
  210. data/vendor/sass/lib/sass/selector/comma_sequence.rb +0 -81
  211. data/vendor/sass/lib/sass/selector/sequence.rb +0 -233
  212. data/vendor/sass/lib/sass/selector/simple.rb +0 -113
  213. data/vendor/sass/lib/sass/selector/simple_sequence.rb +0 -134
  214. data/vendor/sass/lib/sass/shared.rb +0 -78
  215. data/vendor/sass/lib/sass/tree/charset_node.rb +0 -22
  216. data/vendor/sass/lib/sass/tree/comment_node.rb +0 -90
  217. data/vendor/sass/lib/sass/tree/debug_node.rb +0 -18
  218. data/vendor/sass/lib/sass/tree/directive_node.rb +0 -23
  219. data/vendor/sass/lib/sass/tree/each_node.rb +0 -24
  220. data/vendor/sass/lib/sass/tree/extend_node.rb +0 -29
  221. data/vendor/sass/lib/sass/tree/for_node.rb +0 -36
  222. data/vendor/sass/lib/sass/tree/function_node.rb +0 -27
  223. data/vendor/sass/lib/sass/tree/if_node.rb +0 -52
  224. data/vendor/sass/lib/sass/tree/import_node.rb +0 -68
  225. data/vendor/sass/lib/sass/tree/media_node.rb +0 -32
  226. data/vendor/sass/lib/sass/tree/mixin_def_node.rb +0 -27
  227. data/vendor/sass/lib/sass/tree/mixin_node.rb +0 -32
  228. data/vendor/sass/lib/sass/tree/node.rb +0 -201
  229. data/vendor/sass/lib/sass/tree/prop_node.rb +0 -148
  230. data/vendor/sass/lib/sass/tree/return_node.rb +0 -18
  231. data/vendor/sass/lib/sass/tree/root_node.rb +0 -28
  232. data/vendor/sass/lib/sass/tree/rule_node.rb +0 -136
  233. data/vendor/sass/lib/sass/tree/variable_node.rb +0 -30
  234. data/vendor/sass/lib/sass/tree/visitors/base.rb +0 -75
  235. data/vendor/sass/lib/sass/tree/visitors/check_nesting.rb +0 -133
  236. data/vendor/sass/lib/sass/tree/visitors/convert.rb +0 -260
  237. data/vendor/sass/lib/sass/tree/visitors/cssize.rb +0 -175
  238. data/vendor/sass/lib/sass/tree/visitors/deep_copy.rb +0 -87
  239. data/vendor/sass/lib/sass/tree/visitors/perform.rb +0 -332
  240. data/vendor/sass/lib/sass/tree/visitors/set_options.rb +0 -97
  241. data/vendor/sass/lib/sass/tree/visitors/to_css.rb +0 -210
  242. data/vendor/sass/lib/sass/tree/warn_node.rb +0 -18
  243. data/vendor/sass/lib/sass/tree/while_node.rb +0 -18
  244. data/vendor/sass/lib/sass/util.rb +0 -721
  245. data/vendor/sass/lib/sass/util/subset_map.rb +0 -101
  246. data/vendor/sass/lib/sass/version.rb +0 -112
  247. data/vendor/sass/rails/init.rb +0 -1
  248. data/vendor/sass/sass.gemspec +0 -33
  249. data/vendor/sass/test/Gemfile +0 -4
  250. data/vendor/sass/test/Gemfile.lock +0 -19
  251. data/vendor/sass/test/sass/cache_test.rb +0 -89
  252. data/vendor/sass/test/sass/callbacks_test.rb +0 -61
  253. data/vendor/sass/test/sass/conversion_test.rb +0 -1199
  254. data/vendor/sass/test/sass/css2sass_test.rb +0 -373
  255. data/vendor/sass/test/sass/data/hsl-rgb.txt +0 -319
  256. data/vendor/sass/test/sass/engine_test.rb +0 -2567
  257. data/vendor/sass/test/sass/extend_test.rb +0 -1348
  258. data/vendor/sass/test/sass/fixtures/test_staleness_check_across_importers.css +0 -1
  259. data/vendor/sass/test/sass/fixtures/test_staleness_check_across_importers.scss +0 -1
  260. data/vendor/sass/test/sass/functions_test.rb +0 -1038
  261. data/vendor/sass/test/sass/importer_test.rb +0 -192
  262. data/vendor/sass/test/sass/less_conversion_test.rb +0 -653
  263. data/vendor/sass/test/sass/logger_test.rb +0 -58
  264. data/vendor/sass/test/sass/mock_importer.rb +0 -49
  265. data/vendor/sass/test/sass/more_results/more1.css +0 -9
  266. data/vendor/sass/test/sass/more_results/more1_with_line_comments.css +0 -26
  267. data/vendor/sass/test/sass/more_results/more_import.css +0 -29
  268. data/vendor/sass/test/sass/more_templates/_more_partial.sass +0 -2
  269. data/vendor/sass/test/sass/more_templates/more1.sass +0 -23
  270. data/vendor/sass/test/sass/more_templates/more_import.sass +0 -11
  271. data/vendor/sass/test/sass/plugin_test.rb +0 -472
  272. data/vendor/sass/test/sass/results/alt.css +0 -4
  273. data/vendor/sass/test/sass/results/basic.css +0 -9
  274. data/vendor/sass/test/sass/results/compact.css +0 -5
  275. data/vendor/sass/test/sass/results/complex.css +0 -86
  276. data/vendor/sass/test/sass/results/compressed.css +0 -1
  277. data/vendor/sass/test/sass/results/expanded.css +0 -19
  278. data/vendor/sass/test/sass/results/if.css +0 -3
  279. data/vendor/sass/test/sass/results/import.css +0 -31
  280. data/vendor/sass/test/sass/results/import_charset.css +0 -4
  281. data/vendor/sass/test/sass/results/import_charset_1_8.css +0 -4
  282. data/vendor/sass/test/sass/results/import_charset_ibm866.css +0 -4
  283. data/vendor/sass/test/sass/results/line_numbers.css +0 -49
  284. data/vendor/sass/test/sass/results/mixins.css +0 -95
  285. data/vendor/sass/test/sass/results/multiline.css +0 -24
  286. data/vendor/sass/test/sass/results/nested.css +0 -22
  287. data/vendor/sass/test/sass/results/options.css +0 -1
  288. data/vendor/sass/test/sass/results/parent_ref.css +0 -13
  289. data/vendor/sass/test/sass/results/script.css +0 -16
  290. data/vendor/sass/test/sass/results/scss_import.css +0 -31
  291. data/vendor/sass/test/sass/results/scss_importee.css +0 -2
  292. data/vendor/sass/test/sass/results/subdir/nested_subdir/nested_subdir.css +0 -1
  293. data/vendor/sass/test/sass/results/subdir/subdir.css +0 -3
  294. data/vendor/sass/test/sass/results/units.css +0 -11
  295. data/vendor/sass/test/sass/results/warn.css +0 -0
  296. data/vendor/sass/test/sass/results/warn_imported.css +0 -0
  297. data/vendor/sass/test/sass/script_conversion_test.rb +0 -285
  298. data/vendor/sass/test/sass/script_test.rb +0 -514
  299. data/vendor/sass/test/sass/scss/css_test.rb +0 -922
  300. data/vendor/sass/test/sass/scss/rx_test.rb +0 -156
  301. data/vendor/sass/test/sass/scss/scss_test.rb +0 -1273
  302. data/vendor/sass/test/sass/scss/test_helper.rb +0 -37
  303. data/vendor/sass/test/sass/templates/_imported_charset_ibm866.sass +0 -4
  304. data/vendor/sass/test/sass/templates/_imported_charset_utf8.sass +0 -4
  305. data/vendor/sass/test/sass/templates/_partial.sass +0 -2
  306. data/vendor/sass/test/sass/templates/alt.sass +0 -16
  307. data/vendor/sass/test/sass/templates/basic.sass +0 -23
  308. data/vendor/sass/test/sass/templates/bork1.sass +0 -2
  309. data/vendor/sass/test/sass/templates/bork2.sass +0 -2
  310. data/vendor/sass/test/sass/templates/bork3.sass +0 -2
  311. data/vendor/sass/test/sass/templates/bork4.sass +0 -2
  312. data/vendor/sass/test/sass/templates/bork5.sass +0 -3
  313. data/vendor/sass/test/sass/templates/compact.sass +0 -17
  314. data/vendor/sass/test/sass/templates/complex.sass +0 -305
  315. data/vendor/sass/test/sass/templates/compressed.sass +0 -15
  316. data/vendor/sass/test/sass/templates/expanded.sass +0 -17
  317. data/vendor/sass/test/sass/templates/if.sass +0 -11
  318. data/vendor/sass/test/sass/templates/import.sass +0 -12
  319. data/vendor/sass/test/sass/templates/import_charset.sass +0 -7
  320. data/vendor/sass/test/sass/templates/import_charset_1_8.sass +0 -4
  321. data/vendor/sass/test/sass/templates/import_charset_ibm866.sass +0 -9
  322. data/vendor/sass/test/sass/templates/importee.less +0 -2
  323. data/vendor/sass/test/sass/templates/importee.sass +0 -19
  324. data/vendor/sass/test/sass/templates/line_numbers.sass +0 -13
  325. data/vendor/sass/test/sass/templates/mixin_bork.sass +0 -5
  326. data/vendor/sass/test/sass/templates/mixins.sass +0 -76
  327. data/vendor/sass/test/sass/templates/multiline.sass +0 -20
  328. data/vendor/sass/test/sass/templates/nested.sass +0 -25
  329. data/vendor/sass/test/sass/templates/nested_bork1.sass +0 -2
  330. data/vendor/sass/test/sass/templates/nested_bork2.sass +0 -2
  331. data/vendor/sass/test/sass/templates/nested_bork3.sass +0 -2
  332. data/vendor/sass/test/sass/templates/nested_bork4.sass +0 -2
  333. data/vendor/sass/test/sass/templates/nested_bork5.sass +0 -2
  334. data/vendor/sass/test/sass/templates/nested_import.sass +0 -2
  335. data/vendor/sass/test/sass/templates/nested_mixin_bork.sass +0 -6
  336. data/vendor/sass/test/sass/templates/options.sass +0 -2
  337. data/vendor/sass/test/sass/templates/parent_ref.sass +0 -25
  338. data/vendor/sass/test/sass/templates/script.sass +0 -101
  339. data/vendor/sass/test/sass/templates/scss_import.scss +0 -11
  340. data/vendor/sass/test/sass/templates/scss_importee.scss +0 -1
  341. data/vendor/sass/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +0 -2
  342. data/vendor/sass/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +0 -3
  343. data/vendor/sass/test/sass/templates/subdir/subdir.sass +0 -6
  344. data/vendor/sass/test/sass/templates/units.sass +0 -11
  345. data/vendor/sass/test/sass/templates/warn.sass +0 -3
  346. data/vendor/sass/test/sass/templates/warn_imported.sass +0 -4
  347. data/vendor/sass/test/sass/test_helper.rb +0 -8
  348. data/vendor/sass/test/sass/util/subset_map_test.rb +0 -91
  349. data/vendor/sass/test/sass/util_test.rb +0 -266
  350. data/vendor/sass/test/test_helper.rb +0 -69
  351. data/vendor/sass/vendor/fssm/Gemfile +0 -3
  352. data/vendor/sass/vendor/fssm/LICENSE +0 -20
  353. data/vendor/sass/vendor/fssm/README.markdown +0 -83
  354. data/vendor/sass/vendor/fssm/Rakefile +0 -11
  355. data/vendor/sass/vendor/fssm/example.rb +0 -12
  356. data/vendor/sass/vendor/fssm/fssm.gemspec +0 -24
  357. data/vendor/sass/vendor/fssm/lib/fssm.rb +0 -37
  358. data/vendor/sass/vendor/fssm/lib/fssm/backends/fsevents.rb +0 -36
  359. data/vendor/sass/vendor/fssm/lib/fssm/backends/inotify.rb +0 -26
  360. data/vendor/sass/vendor/fssm/lib/fssm/backends/polling.rb +0 -25
  361. data/vendor/sass/vendor/fssm/lib/fssm/backends/rbfsevent.rb +0 -42
  362. data/vendor/sass/vendor/fssm/lib/fssm/backends/rubycocoa/fsevents.rb +0 -131
  363. data/vendor/sass/vendor/fssm/lib/fssm/monitor.rb +0 -36
  364. data/vendor/sass/vendor/fssm/lib/fssm/path.rb +0 -94
  365. data/vendor/sass/vendor/fssm/lib/fssm/pathname.rb +0 -36
  366. data/vendor/sass/vendor/fssm/lib/fssm/state/directory.rb +0 -75
  367. data/vendor/sass/vendor/fssm/lib/fssm/state/file.rb +0 -24
  368. data/vendor/sass/vendor/fssm/lib/fssm/support.rb +0 -92
  369. data/vendor/sass/vendor/fssm/lib/fssm/tree.rb +0 -176
  370. data/vendor/sass/vendor/fssm/lib/fssm/version.rb +0 -3
  371. data/vendor/sass/vendor/fssm/profile/prof-cache.rb +0 -40
  372. data/vendor/sass/vendor/fssm/profile/prof-fssm-pathname.html +0 -1231
  373. data/vendor/sass/vendor/fssm/profile/prof-pathname-rubinius.rb +0 -35
  374. data/vendor/sass/vendor/fssm/profile/prof-pathname.rb +0 -68
  375. data/vendor/sass/vendor/fssm/profile/prof-plain-pathname.html +0 -988
  376. data/vendor/sass/vendor/fssm/profile/prof.html +0 -2379
  377. data/vendor/sass/vendor/fssm/spec/count_down_latch.rb +0 -151
  378. data/vendor/sass/vendor/fssm/spec/monitor_spec.rb +0 -202
  379. data/vendor/sass/vendor/fssm/spec/path_spec.rb +0 -96
  380. data/vendor/sass/vendor/fssm/spec/root/duck/quack.txt +0 -0
  381. data/vendor/sass/vendor/fssm/spec/root/file.css +0 -0
  382. data/vendor/sass/vendor/fssm/spec/root/file.rb +0 -0
  383. data/vendor/sass/vendor/fssm/spec/root/file.yml +0 -0
  384. data/vendor/sass/vendor/fssm/spec/root/moo/cow.txt +0 -0
  385. data/vendor/sass/vendor/fssm/spec/spec_helper.rb +0 -14
  386. data/vendor/sass/yard/callbacks.rb +0 -29
  387. data/vendor/sass/yard/default/fulldoc/html/css/common.sass +0 -26
  388. data/vendor/sass/yard/default/layout/html/footer.erb +0 -12
  389. data/vendor/sass/yard/inherited_hash.rb +0 -41
@@ -1,94 +1,19 @@
1
1
  require 'erb'
2
2
  require 'set'
3
- require 'enumerator'
4
3
  require 'stringio'
5
4
  require 'strscan'
6
- require 'rbconfig'
7
-
8
- require 'haml/root'
9
5
 
10
6
  module Haml
11
7
  # A module containing various useful functions.
12
8
  module Util
13
9
  extend self
14
10
 
15
- # An array of ints representing the Ruby version number.
16
- # @api public
17
- RUBY_VERSION = ::RUBY_VERSION.split(".").map {|s| s.to_i}
18
-
19
- # The Ruby engine we're running under. Defaults to `"ruby"`
20
- # if the top-level constant is undefined.
21
- # @api public
22
- RUBY_ENGINE = defined?(::RUBY_ENGINE) ? ::RUBY_ENGINE : "ruby"
23
-
24
- @@version_comparison_cache = {}
25
-
26
11
  # Returns the path of a file relative to the Haml root directory.
27
12
  #
28
13
  # @param file [String] The filename relative to the Haml root
29
14
  # @return [String] The filename relative to the the working directory
30
15
  def scope(file)
31
- File.join(Haml::ROOT_DIR, file)
32
- end
33
-
34
- # Converts an array of `[key, value]` pairs to a hash.
35
- #
36
- # @example
37
- # to_hash([[:foo, "bar"], [:baz, "bang"]])
38
- # #=> {:foo => "bar", :baz => "bang"}
39
- # @param arr [Array<(Object, Object)>] An array of pairs
40
- # @return [Hash] A hash
41
- def to_hash(arr)
42
- Hash[arr.compact]
43
- end
44
-
45
- # Maps the keys in a hash according to a block.
46
- #
47
- # @example
48
- # map_keys({:foo => "bar", :baz => "bang"}) {|k| k.to_s}
49
- # #=> {"foo" => "bar", "baz" => "bang"}
50
- # @param hash [Hash] The hash to map
51
- # @yield [key] A block in which the keys are transformed
52
- # @yieldparam key [Object] The key that should be mapped
53
- # @yieldreturn [Object] The new value for the key
54
- # @return [Hash] The mapped hash
55
- # @see #map_vals
56
- # @see #map_hash
57
- def map_keys(hash)
58
- to_hash(hash.map {|k, v| [yield(k), v]})
59
- end
60
-
61
- # Maps the values in a hash according to a block.
62
- #
63
- # @example
64
- # map_values({:foo => "bar", :baz => "bang"}) {|v| v.to_sym}
65
- # #=> {:foo => :bar, :baz => :bang}
66
- # @param hash [Hash] The hash to map
67
- # @yield [value] A block in which the values are transformed
68
- # @yieldparam value [Object] The value that should be mapped
69
- # @yieldreturn [Object] The new value for the value
70
- # @return [Hash] The mapped hash
71
- # @see #map_keys
72
- # @see #map_hash
73
- def map_vals(hash)
74
- to_hash(hash.map {|k, v| [k, yield(v)]})
75
- end
76
-
77
- # Maps the key-value pairs of a hash according to a block.
78
- #
79
- # @example
80
- # map_hash({:foo => "bar", :baz => "bang"}) {|k, v| [k.to_s, v.to_sym]}
81
- # #=> {"foo" => :bar, "baz" => :bang}
82
- # @param hash [Hash] The hash to map
83
- # @yield [key, value] A block in which the key-value pairs are transformed
84
- # @yieldparam [key] The hash key
85
- # @yieldparam [value] The hash value
86
- # @yieldreturn [(Object, Object)] The new value for the `[key, value]` pair
87
- # @return [Hash] The mapped hash
88
- # @see #map_keys
89
- # @see #map_vals
90
- def map_hash(hash, &block)
91
- to_hash(hash.map(&block))
16
+ File.expand_path("../../../#{file}", __FILE__)
92
17
  end
93
18
 
94
19
  # Computes the powerset of the given array.
@@ -110,116 +35,6 @@ module Haml
110
35
  end
111
36
  end
112
37
 
113
- # Restricts a number to falling within a given range.
114
- # Returns the number if it falls within the range,
115
- # or the closest value in the range if it doesn't.
116
- #
117
- # @param value [Numeric]
118
- # @param range [Range<Numeric>]
119
- # @return [Numeric]
120
- def restrict(value, range)
121
- [[value, range.first].max, range.last].min
122
- end
123
-
124
- # Concatenates all strings that are adjacent in an array,
125
- # while leaving other elements as they are.
126
- #
127
- # @example
128
- # merge_adjacent_strings([1, "foo", "bar", 2, "baz"])
129
- # #=> [1, "foobar", 2, "baz"]
130
- # @param arr [Array]
131
- # @return [Array] The enumerable with strings merged
132
- def merge_adjacent_strings(arr)
133
- # Optimize for the common case of one element
134
- return arr if arr.size < 2
135
- arr.inject([]) do |a, e|
136
- if e.is_a?(String)
137
- if a.last.is_a?(String)
138
- a.last << e
139
- else
140
- a << e.dup
141
- end
142
- else
143
- a << e
144
- end
145
- a
146
- end
147
- end
148
-
149
- # Intersperses a value in an enumerable, as would be done with `Array#join`
150
- # but without concatenating the array together afterwards.
151
- #
152
- # @param enum [Enumerable]
153
- # @param val
154
- # @return [Array]
155
- def intersperse(enum, val)
156
- enum.inject([]) {|a, e| a << e << val}[0...-1]
157
- end
158
-
159
- # Substitutes a sub-array of one array with another sub-array.
160
- #
161
- # @param ary [Array] The array in which to make the substitution
162
- # @param from [Array] The sequence of elements to replace with `to`
163
- # @param to [Array] The sequence of elements to replace `from` with
164
- def substitute(ary, from, to)
165
- res = ary.dup
166
- i = 0
167
- while i < res.size
168
- if res[i...i+from.size] == from
169
- res[i...i+from.size] = to
170
- end
171
- i += 1
172
- end
173
- res
174
- end
175
-
176
- # Destructively strips whitespace from the beginning and end
177
- # of the first and last elements, respectively,
178
- # in the array (if those elements are strings).
179
- #
180
- # @param arr [Array]
181
- # @return [Array] `arr`
182
- def strip_string_array(arr)
183
- arr.first.lstrip! if arr.first.is_a?(String)
184
- arr.last.rstrip! if arr.last.is_a?(String)
185
- arr
186
- end
187
-
188
- # Return an array of all possible paths through the given arrays.
189
- #
190
- # @param arrs [Array<Array>]
191
- # @return [Array<Arrays>]
192
- #
193
- # @example
194
- # paths([[1, 2], [3, 4], [5]]) #=>
195
- # # [[1, 3, 5],
196
- # # [2, 3, 5],
197
- # # [1, 4, 5],
198
- # # [2, 4, 5]]
199
- def paths(arrs)
200
- arrs.inject([[]]) do |paths, arr|
201
- flatten(arr.map {|e| paths.map {|path| path + [e]}}, 1)
202
- end
203
- end
204
-
205
- # Computes a single longest common subsequence for `x` and `y`.
206
- # If there are more than one longest common subsequences,
207
- # the one returned is that which starts first in `x`.
208
- #
209
- # @param x [Array]
210
- # @param y [Array]
211
- # @yield [a, b] An optional block to use in place of a check for equality
212
- # between elements of `x` and `y`.
213
- # @yieldreturn [Object, nil] If the two values register as equal,
214
- # this will return the value to use in the LCS array.
215
- # @return [Array] The LCS
216
- def lcs(x, y, &block)
217
- x = [nil, *x]
218
- y = [nil, *y]
219
- block ||= proc {|a, b| a == b && a}
220
- lcs_backtrace(lcs_table(x, y, &block), x, y, x.size-1, y.size-1, &block)
221
- end
222
-
223
38
  # Returns information about the caller of the previous method.
224
39
  #
225
40
  # @param entry [String] An entry in the `#caller` list, or a similarly formatted string
@@ -233,83 +48,6 @@ module Haml
233
48
  info
234
49
  end
235
50
 
236
- # Returns whether one version string represents a more recent version than another.
237
- #
238
- # @param v1 [String] A version string.
239
- # @param v2 [String] Another version string.
240
- # @return [Boolean]
241
- def version_gt(v1, v2)
242
- # Construct an array to make sure the shorter version is padded with nil
243
- Array.new([v1.length, v2.length].max).zip(v1.split("."), v2.split(".")) do |_, p1, p2|
244
- p1 ||= "0"
245
- p2 ||= "0"
246
- release1 = p1 =~ /^[0-9]+$/
247
- release2 = p2 =~ /^[0-9]+$/
248
- if release1 && release2
249
- # Integer comparison if both are full releases
250
- p1, p2 = p1.to_i, p2.to_i
251
- next if p1 == p2
252
- return p1 > p2
253
- elsif !release1 && !release2
254
- # String comparison if both are prereleases
255
- next if p1 == p2
256
- return p1 > p2
257
- else
258
- # If only one is a release, that one is newer
259
- return release1
260
- end
261
- end
262
- end
263
-
264
- # Returns whether one version string represents the same or a more
265
- # recent version than another.
266
- #
267
- # @param v1 [String] A version string.
268
- # @param v2 [String] Another version string.
269
- # @return [Boolean]
270
- def version_geq(v1, v2)
271
- k = "#{v1}#{v2}"
272
- return @@version_comparison_cache.fetch(k) if @@version_comparison_cache.key?(k)
273
- @@version_comparison_cache[k] = version_gt(v1, v2) || !version_gt(v2, v1)
274
- end
275
-
276
- # A wrapper for `Marshal.dump` that calls `#_before_dump` on the object
277
- # before dumping it, `#_after_dump` afterwards.
278
- # It also calls `#_around_dump` and passes it a block in which the object is dumped.
279
- #
280
- # If any of these methods are undefined, they are not called.
281
- #
282
- # @param obj [Object] The object to dump.
283
- # @return [String] The dumped data.
284
- def dump(obj)
285
- obj._before_dump if obj.respond_to?(:_before_dump)
286
- return Marshal.dump(obj) unless obj.respond_to?(:_around_dump)
287
- res = nil
288
- obj._around_dump {res = Marshal.dump(obj)}
289
- res
290
- ensure
291
- obj._after_dump if obj.respond_to?(:_after_dump)
292
- end
293
-
294
- # A wrapper for `Marshal.load` that calls `#_after_load` on the object
295
- # after loading it, if it's defined.
296
- #
297
- # @param data [String] The data to load.
298
- # @return [Object] The loaded object.
299
- def load(data)
300
- obj = Marshal.load(data)
301
- obj._after_load if obj.respond_to?(:_after_load)
302
- obj
303
- end
304
-
305
- # Throws a NotImplementedError for an abstract method.
306
- #
307
- # @param obj [Object] `self`
308
- # @raise [NotImplementedError]
309
- def abstract(obj)
310
- raise NotImplementedError.new("#{obj.class} must implement ##{caller_info[2]}")
311
- end
312
-
313
51
  # Silence all output to STDERR within a block.
314
52
  #
315
53
  # @yield A block in which no output will be printed to STDERR
@@ -320,105 +58,6 @@ module Haml
320
58
  $stderr = the_real_stderr
321
59
  end
322
60
 
323
- @@silence_warnings = false
324
- # Silences all Haml warnings within a block.
325
- #
326
- # @yield A block in which no Haml warnings will be printed
327
- def silence_haml_warnings
328
- old_silence_warnings = @@silence_warnings
329
- @@silence_warnings = true
330
- yield
331
- ensure
332
- @@silence_warnings = old_silence_warnings
333
- end
334
-
335
- # The same as `Kernel#warn`, but is silenced by \{#silence\_haml\_warnings}.
336
- #
337
- # @param msg [String]
338
- def haml_warn(msg)
339
- return if @@silence_warnings
340
- warn(msg)
341
- end
342
-
343
- # Try loading Sass. If the `sass` gem isn't installed,
344
- # print a warning and load from the vendored gem.
345
- #
346
- # @return [Boolean] True if Sass was successfully loaded from the `sass` gem,
347
- # false otherwise.
348
- def try_sass
349
- return true if defined?(::SASS_BEGUN_TO_LOAD)
350
- begin
351
- require 'sass/version'
352
- loaded = Sass.respond_to?(:version) && Sass.version[:major] &&
353
- Sass.version[:minor] && ((Sass.version[:major] > 3 && Sass.version[:minor] > 1) ||
354
- ((Sass.version[:major] == 3 && Sass.version[:minor] == 1) &&
355
- (Sass.version[:prerelease] || Sass.version[:name] != "Bleeding Edge")))
356
- rescue LoadError => e
357
- loaded = false
358
- end
359
-
360
- unless loaded
361
- haml_warn(<<WARNING)
362
- Sass is in the process of being separated from Haml,
363
- and will no longer be bundled at all in Haml 3.2.0.
364
- Please install the 'sass' gem if you want to use Sass.
365
- WARNING
366
- $".delete('sass/version')
367
- $LOAD_PATH.unshift(scope("vendor/sass/lib"))
368
- end
369
- loaded
370
- end
371
-
372
- ## Cross Rails Version Compatibility
373
-
374
- # Returns the root of the Rails application,
375
- # if this is running in a Rails context.
376
- # Returns `nil` if no such root is defined.
377
- #
378
- # @return [String, nil]
379
- def rails_root
380
- if defined?(::Rails.root)
381
- return ::Rails.root.to_s if ::Rails.root
382
- raise "ERROR: Rails.root is nil!"
383
- end
384
- return RAILS_ROOT.to_s if defined?(RAILS_ROOT)
385
- return nil
386
- end
387
-
388
- # Returns the environment of the Rails application,
389
- # if this is running in a Rails context.
390
- # Returns `nil` if no such environment is defined.
391
- #
392
- # @return [String, nil]
393
- def rails_env
394
- return ::Rails.env.to_s if defined?(::Rails.env)
395
- return RAILS_ENV.to_s if defined?(RAILS_ENV)
396
- return nil
397
- end
398
-
399
- # Returns whether this environment is using ActionPack
400
- # version 3.0.0 or greater.
401
- #
402
- # @return [Boolean]
403
- def ap_geq_3?
404
- ap_geq?("3.0.0.beta1")
405
- end
406
-
407
- # Returns whether this environment is using ActionPack
408
- # of a version greater than or equal to that specified.
409
- #
410
- # @param version [String] The string version number to check against.
411
- # Should be greater than or equal to Rails 3,
412
- # because otherwise ActionPack::VERSION isn't autoloaded
413
- # @return [Boolean]
414
- def ap_geq?(version)
415
- # The ActionPack module is always loaded automatically in Rails >= 3
416
- return false unless defined?(ActionPack) && defined?(ActionPack::VERSION) &&
417
- defined?(ActionPack::VERSION::STRING)
418
-
419
- version_geq(ActionPack::VERSION::STRING, version)
420
- end
421
-
422
61
  # Returns an ActionView::Template* class.
423
62
  # In pre-3.0 versions of Rails, most of these classes
424
63
  # were of the form `ActionView::TemplateFoo`,
@@ -455,65 +94,6 @@ WARNING
455
94
  text.html_safe!
456
95
  end
457
96
 
458
- # Assert that a given object (usually a String) is HTML safe
459
- # according to Rails' XSS handling, if it's loaded.
460
- #
461
- # @param text [Object]
462
- def assert_html_safe!(text)
463
- return unless rails_xss_safe? && text && !text.to_s.html_safe?
464
- raise Haml::Error.new("Expected #{text.inspect} to be HTML-safe.")
465
- end
466
-
467
- # The class for the Rails SafeBuffer XSS protection class.
468
- # This varies depending on Rails version.
469
- #
470
- # @return [Class]
471
- def rails_safe_buffer_class
472
- # It's important that we check ActiveSupport first,
473
- # because in Rails 2.3.6 ActionView::SafeBuffer exists
474
- # but is a deprecated proxy object.
475
- return ActiveSupport::SafeBuffer if defined?(ActiveSupport::SafeBuffer)
476
- return ActionView::SafeBuffer
477
- end
478
-
479
- ## Cross-OS Compatibility
480
-
481
- # Whether or not this is running on Windows.
482
- #
483
- # @return [Boolean]
484
- def windows?
485
- RbConfig::CONFIG['host_os'] =~ /mswin|windows|mingw/i
486
- end
487
-
488
- # Whether or not this is running on IronRuby.
489
- #
490
- # @return [Boolean]
491
- def ironruby?
492
- RUBY_ENGINE == "ironruby"
493
- end
494
-
495
- ## Cross-Ruby-Version Compatibility
496
-
497
- # Whether or not this is running under Ruby 1.8 or lower.
498
- #
499
- # Note that IronRuby counts as Ruby 1.8,
500
- # because it doesn't support the Ruby 1.9 encoding API.
501
- #
502
- # @return [Boolean]
503
- def ruby1_8?
504
- # IronRuby says its version is 1.9, but doesn't support any of the encoding APIs.
505
- # We have to fall back to 1.8 behavior.
506
- ironruby? || (Haml::Util::RUBY_VERSION[0] == 1 && Haml::Util::RUBY_VERSION[1] < 9)
507
- end
508
-
509
- # Whether or not this is running under Ruby 1.8.6 or lower.
510
- # Note that lower versions are not officially supported.
511
- #
512
- # @return [Boolean]
513
- def ruby1_8_6?
514
- ruby1_8? && Haml::Util::RUBY_VERSION[2] < 7
515
- end
516
-
517
97
  # Checks that the encoding of a string is valid in Ruby 1.9
518
98
  # and cleans up potential encoding gotchas like the UTF-8 BOM.
519
99
  # If it's not, yields an error string describing the invalid character
@@ -524,175 +104,74 @@ WARNING
524
104
  # Only yields if there is an encoding error
525
105
  # @yieldparam msg [String] The error message to be raised
526
106
  # @return [String] `str`, potentially with encoding gotchas like BOMs removed
527
- def check_encoding(str)
528
- if ruby1_8?
529
- return str.gsub(/\A\xEF\xBB\xBF/, '') # Get rid of the UTF-8 BOM
530
- elsif str.valid_encoding?
531
- # Get rid of the Unicode BOM if possible
532
- if str.encoding.name =~ /^UTF-(8|16|32)(BE|LE)?$/
533
- return str.gsub(Regexp.new("\\A\uFEFF".encode(str.encoding.name)), '')
534
- else
535
- return str
536
- end
107
+ if RUBY_VERSION < "1.9"
108
+ def check_encoding(str)
109
+ str.gsub(/\A\xEF\xBB\xBF/, '') # Get rid of the UTF-8 BOM
537
110
  end
111
+ else
112
+
113
+ def check_encoding(str)
114
+ if str.valid_encoding?
115
+ # Get rid of the Unicode BOM if possible
116
+ if str.encoding.name =~ /^UTF-(8|16|32)(BE|LE)?$/
117
+ return str.gsub(Regexp.new("\\A\uFEFF".encode(str.encoding.name)), '')
118
+ else
119
+ return str
120
+ end
121
+ end
538
122
 
539
- encoding = str.encoding
540
- newlines = Regexp.new("\r\n|\r|\n".encode(encoding).force_encoding("binary"))
541
- str.force_encoding("binary").split(newlines).each_with_index do |line, i|
542
- begin
543
- line.encode(encoding)
544
- rescue Encoding::UndefinedConversionError => e
545
- yield <<MSG.rstrip, i + 1
123
+ encoding = str.encoding
124
+ newlines = Regexp.new("\r\n|\r|\n".encode(encoding).force_encoding("binary"))
125
+ str.force_encoding("binary").split(newlines).each_with_index do |line, i|
126
+ begin
127
+ line.encode(encoding)
128
+ rescue Encoding::UndefinedConversionError => e
129
+ yield <<MSG.rstrip, i + 1
546
130
  Invalid #{encoding.name} character #{e.error_char.dump}
547
131
  MSG
132
+ end
548
133
  end
134
+ return str
549
135
  end
550
- return str
551
136
  end
552
137
 
553
- # Like {\#check\_encoding}, but also checks for a Ruby-style `-# coding:` comment
554
- # at the beginning of the template and uses that encoding if it exists.
555
- #
556
- # The Haml encoding rules are simple.
557
- # If a `-# coding:` comment exists,
558
- # we assume that that's the original encoding of the document.
559
- # Otherwise, we use whatever encoding Ruby has.
560
- #
561
- # Haml uses the same rules for parsing coding comments as Ruby.
562
- # This means that it can understand Emacs-style comments
563
- # (e.g. `-*- encoding: "utf-8" -*-`),
564
- # and also that it cannot understand non-ASCII-compatible encodings
565
- # such as `UTF-16` and `UTF-32`.
566
- #
567
- # @param str [String] The Haml template of which to check the encoding
568
- # @yield [msg] A block in which an encoding error can be raised.
569
- # Only yields if there is an encoding error
570
- # @yieldparam msg [String] The error message to be raised
571
- # @return [String] The original string encoded properly
572
- # @raise [ArgumentError] if the document declares an unknown encoding
573
- def check_haml_encoding(str, &block)
574
- return check_encoding(str, &block) if ruby1_8?
575
- str = str.dup if str.frozen?
576
-
577
- bom, encoding = parse_haml_magic_comment(str)
578
- if encoding; str.force_encoding(encoding)
579
- elsif bom; str.force_encoding("UTF-8")
580
- end
581
-
582
- return check_encoding(str, &block)
583
- end
584
-
585
- unless ruby1_8?
586
- # @private
587
- def _enc(string, encoding)
588
- string.encode(encoding).force_encoding("BINARY")
138
+ if RUBY_VERSION < "1.9"
139
+ # Like {\#check\_encoding}, but also checks for a Ruby-style `-# coding:` comment
140
+ # at the beginning of the template and uses that encoding if it exists.
141
+ #
142
+ # The Haml encoding rules are simple.
143
+ # If a `-# coding:` comment exists,
144
+ # we assume that that's the original encoding of the document.
145
+ # Otherwise, we use whatever encoding Ruby has.
146
+ #
147
+ # Haml uses the same rules for parsing coding comments as Ruby.
148
+ # This means that it can understand Emacs-style comments
149
+ # (e.g. `-*- encoding: "utf-8" -*-`),
150
+ # and also that it cannot understand non-ASCII-compatible encodings
151
+ # such as `UTF-16` and `UTF-32`.
152
+ #
153
+ # @param str [String] The Haml template of which to check the encoding
154
+ # @yield [msg] A block in which an encoding error can be raised.
155
+ # Only yields if there is an encoding error
156
+ # @yieldparam msg [String] The error message to be raised
157
+ # @return [String] The original string encoded properly
158
+ # @raise [ArgumentError] if the document declares an unknown encoding
159
+ def check_haml_encoding(str, &block)
160
+ check_encoding(str, &block)
589
161
  end
162
+ else
163
+ def check_haml_encoding(str, &block)
164
+ str = str.dup if str.frozen?
590
165
 
591
- # We could automatically add in any non-ASCII-compatible encodings here,
592
- # but there's not really a good way to do that
593
- # without manually checking that each encoding
594
- # encodes all ASCII characters properly,
595
- # which takes long enough to affect the startup time of the CLI.
596
- ENCODINGS_TO_CHECK = %w[UTF-8 UTF-16BE UTF-16LE UTF-32BE UTF-32LE]
166
+ bom, encoding = parse_haml_magic_comment(str)
167
+ if encoding; str.force_encoding(encoding)
168
+ elsif bom; str.force_encoding("UTF-8")
169
+ end
597
170
 
598
- CHARSET_REGEXPS = Hash.new do |h, e|
599
- h[e] =
600
- begin
601
- # /\A(?:\uFEFF)?@charset "(.*?)"|\A(\uFEFF)/
602
- Regexp.new(/\A(?:#{_enc("\uFEFF", e)})?#{
603
- _enc('@charset "', e)}(.*?)#{_enc('"', e)}|\A(#{
604
- _enc("\uFEFF", e)})/)
605
- rescue
606
- # /\A@charset "(.*?)"/
607
- Regexp.new(/\A#{_enc('@charset "', e)}(.*?)#{_enc('"', e)}/)
608
- end
171
+ return check_encoding(str, &block)
609
172
  end
610
173
  end
611
174
 
612
- # Checks to see if a class has a given method.
613
- # For example:
614
- #
615
- # Haml::Util.has?(:public_instance_method, String, :gsub) #=> true
616
- #
617
- # Method collections like `Class#instance_methods`
618
- # return strings in Ruby 1.8 and symbols in Ruby 1.9 and on,
619
- # so this handles checking for them in a compatible way.
620
- #
621
- # @param attr [#to_s] The (singular) name of the method-collection method
622
- # (e.g. `:instance_methods`, `:private_methods`)
623
- # @param klass [Module] The class to check the methods of which to check
624
- # @param method [String, Symbol] The name of the method do check for
625
- # @return [Boolean] Whether or not the given collection has the given method
626
- def has?(attr, klass, method)
627
- klass.send("#{attr}s").include?(ruby1_8? ? method.to_s : method.to_sym)
628
- end
629
-
630
- # A version of `Enumerable#enum_with_index` that works in Ruby 1.8 and 1.9.
631
- #
632
- # @param enum [Enumerable] The enumerable to get the enumerator for
633
- # @return [Enumerator] The with-index enumerator
634
- def enum_with_index(enum)
635
- ruby1_8? ? enum.enum_with_index : enum.each_with_index
636
- end
637
-
638
- # A version of `Enumerable#enum_cons` that works in Ruby 1.8 and 1.9.
639
- #
640
- # @param enum [Enumerable] The enumerable to get the enumerator for
641
- # @param n [Fixnum] The size of each cons
642
- # @return [Enumerator] The consed enumerator
643
- def enum_cons(enum, n)
644
- ruby1_8? ? enum.enum_cons(n) : enum.each_cons(n)
645
- end
646
-
647
- # A version of `Enumerable#enum_slice` that works in Ruby 1.8 and 1.9.
648
- #
649
- # @param enum [Enumerable] The enumerable to get the enumerator for
650
- # @param n [Fixnum] The size of each slice
651
- # @return [Enumerator] The consed enumerator
652
- def enum_slice(enum, n)
653
- ruby1_8? ? enum.enum_slice(n) : enum.each_slice(n)
654
- end
655
-
656
- # Returns the ASCII code of the given character.
657
- #
658
- # @param c [String] All characters but the first are ignored.
659
- # @return [Fixnum] The ASCII code of `c`.
660
- def ord(c)
661
- ruby1_8? ? c[0] : c.ord
662
- end
663
-
664
- # Flattens the first `n` nested arrays in a cross-version manner.
665
- #
666
- # @param arr [Array] The array to flatten
667
- # @param n [Fixnum] The number of levels to flatten
668
- # @return [Array] The flattened array
669
- def flatten(arr, n)
670
- return arr.flatten(n) unless ruby1_8_6?
671
- return arr if n == 0
672
- arr.inject([]) {|res, e| e.is_a?(Array) ? res.concat(flatten(e, n - 1)) : res << e}
673
- end
674
-
675
- # Returns the hash code for a set in a cross-version manner.
676
- # Aggravatingly, this is order-dependent in Ruby 1.8.6.
677
- #
678
- # @param set [Set]
679
- # @return [Fixnum] The order-independent hashcode of `set`
680
- def set_hash(set)
681
- return set.hash unless ruby1_8_6?
682
- set.map {|e| e.hash}.uniq.sort.hash
683
- end
684
-
685
- # Tests the hash-equality of two sets in a cross-version manner.
686
- # Aggravatingly, this is order-dependent in Ruby 1.8.6.
687
- #
688
- # @param set1 [Set]
689
- # @param set2 [Set]
690
- # @return [Boolean] Whether or not the sets are hashcode equal
691
- def set_eql?(set1, set2)
692
- return set1.eql?(set2) unless ruby1_8_6?
693
- set1.to_a.uniq.sort_by {|e| e.hash}.eql?(set2.to_a.uniq.sort_by {|e| e.hash})
694
- end
695
-
696
175
  # Like `Object#inspect`, but preserves non-ASCII characters rather than escaping them under Ruby 1.9.2.
697
176
  # This is necessary so that the precompiled Haml template can be `#encode`d into `@options[:encoding]`
698
177
  # before being evaluated.
@@ -700,7 +179,7 @@ MSG
700
179
  # @param obj {Object}
701
180
  # @return {String}
702
181
  def inspect_obj(obj)
703
- return obj.inspect unless version_geq(::RUBY_VERSION, "1.9.2")
182
+ return obj.inspect unless (::RUBY_VERSION >= "1.9.2")
704
183
  return ':' + inspect_obj(obj.to_s) if obj.is_a?(Symbol)
705
184
  return obj.inspect unless obj.is_a?(String)
706
185
  '"' + obj.gsub(/[\x00-\x7F]+/) {|s| s.inspect[1...-1]} + '"'
@@ -756,7 +235,6 @@ MSG
756
235
  # (**not** to the ERB template)
757
236
  # @param vars [Array<Symbol>] The names of the static boolean variables
758
237
  # to be made available to the ERB template
759
- # @param erb [String] The template for the method code
760
238
  def def_static_method(klass, name, args, *vars)
761
239
  erb = vars.pop
762
240
  info = caller_info
@@ -779,39 +257,78 @@ METHOD
779
257
  "#{name}_#{vars.map {|v| !!v}.join('_')}"
780
258
  end
781
259
 
782
- private
260
+ # Scans through a string looking for the interoplation-opening `#{`
261
+ # and, when it's found, yields the scanner to the calling code
262
+ # so it can handle it properly.
263
+ #
264
+ # The scanner will have any backslashes immediately in front of the `#{`
265
+ # as the second capture group (`scan[2]`),
266
+ # and the text prior to that as the first (`scan[1]`).
267
+ #
268
+ # @yieldparam scan [StringScanner] The scanner scanning through the string
269
+ # @return [String] The text remaining in the scanner after all `#{`s have been processed
270
+ def handle_interpolation(str)
271
+ scan = StringScanner.new(str)
272
+ yield scan while scan.scan(/(.*?)(\\*)\#\{/)
273
+ scan.rest
274
+ end
783
275
 
784
- # Calculates the memoization table for the Least Common Subsequence algorithm.
785
- # Algorithm from [Wikipedia](http://en.wikipedia.org/wiki/Longest_common_subsequence_problem#Computing_the_length_of_the_LCS)
786
- def lcs_table(x, y)
787
- c = Array.new(x.size) {[]}
788
- x.size.times {|i| c[i][0] = 0}
789
- y.size.times {|j| c[0][j] = 0}
790
- (1...x.size).each do |i|
791
- (1...y.size).each do |j|
792
- c[i][j] =
793
- if yield x[i], y[j]
794
- c[i-1][j-1] + 1
795
- else
796
- [c[i][j-1], c[i-1][j]].max
797
- end
798
- end
276
+ # Moves a scanner through a balanced pair of characters.
277
+ # For example:
278
+ #
279
+ # Foo (Bar (Baz bang) bop) (Bang (bop bip))
280
+ # ^ ^
281
+ # from to
282
+ #
283
+ # @param scanner [StringScanner] The string scanner to move
284
+ # @param start [Character] The character opening the balanced pair.
285
+ # A `Fixnum` in 1.8, a `String` in 1.9
286
+ # @param finish [Character] The character closing the balanced pair.
287
+ # A `Fixnum` in 1.8, a `String` in 1.9
288
+ # @param count [Fixnum] The number of opening characters matched
289
+ # before calling this method
290
+ # @return [(String, String)] The string matched within the balanced pair
291
+ # and the rest of the string.
292
+ # `["Foo (Bar (Baz bang) bop)", " (Bang (bop bip))"]` in the example above.
293
+ def balance(scanner, start, finish, count = 0)
294
+ str = ''
295
+ scanner = StringScanner.new(scanner) unless scanner.is_a? StringScanner
296
+ regexp = Regexp.new("(.*?)[\\#{start.chr}\\#{finish.chr}]", Regexp::MULTILINE)
297
+ while scanner.scan(regexp)
298
+ str << scanner.matched
299
+ count += 1 if scanner.matched[-1] == start
300
+ count -= 1 if scanner.matched[-1] == finish
301
+ return [str.strip, scanner.rest] if count == 0
799
302
  end
800
- return c
801
303
  end
802
304
 
803
- # Computes a single longest common subsequence for arrays x and y.
804
- # Algorithm from [Wikipedia](http://en.wikipedia.org/wiki/Longest_common_subsequence_problem#Reading_out_an_LCS)
805
- def lcs_backtrace(c, x, y, i, j, &block)
806
- return [] if i == 0 || j == 0
807
- if v = yield(x[i], y[j])
808
- return lcs_backtrace(c, x, y, i-1, j-1, &block) << v
305
+ # Formats a string for use in error messages about indentation.
306
+ #
307
+ # @param indentation [String] The string used for indentation
308
+ # @param was [Boolean] Whether or not to add `"was"` or `"were"`
309
+ # (depending on how many characters were in `indentation`)
310
+ # @return [String] The name of the indentation (e.g. `"12 spaces"`, `"1 tab"`)
311
+ def human_indentation(indentation, was = false)
312
+ if !indentation.include?(?\t)
313
+ noun = 'space'
314
+ elsif !indentation.include?(?\s)
315
+ noun = 'tab'
316
+ else
317
+ return indentation.inspect + (was ? ' was' : '')
318
+ end
319
+
320
+ singular = indentation.length == 1
321
+ if was
322
+ was = singular ? ' was' : ' were'
323
+ else
324
+ was = ''
809
325
  end
810
326
 
811
- return lcs_backtrace(c, x, y, i, j-1, &block) if c[i][j-1] > c[i-1][j]
812
- return lcs_backtrace(c, x, y, i-1, j, &block)
327
+ "#{indentation.length} #{noun}#{'s' unless singular}#{was}"
813
328
  end
814
329
 
330
+ private
331
+
815
332
  # Parses a magic comment at the beginning of a Haml file.
816
333
  # The parsing rules are basically the same as Ruby's.
817
334
  #