haml_ejs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (358) hide show
  1. data/.yardopts +11 -0
  2. data/CONTRIBUTING +3 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +68 -0
  5. data/Rakefile +419 -0
  6. data/VERSION +1 -0
  7. data/VERSION_NAME +1 -0
  8. data/bin/haml +9 -0
  9. data/bin/html2haml +7 -0
  10. data/extra/update_watch.rb +13 -0
  11. data/init.rb +18 -0
  12. data/lib/haml.rb +49 -0
  13. data/lib/haml/buffer.rb +297 -0
  14. data/lib/haml/compiler.rb +486 -0
  15. data/lib/haml/engine.rb +312 -0
  16. data/lib/haml/error.rb +22 -0
  17. data/lib/haml/exec.rb +362 -0
  18. data/lib/haml/filters.rb +388 -0
  19. data/lib/haml/haml_ejs.rb +57 -0
  20. data/lib/haml/helpers.rb +608 -0
  21. data/lib/haml/helpers/action_view_extensions.rb +57 -0
  22. data/lib/haml/helpers/action_view_mods.rb +257 -0
  23. data/lib/haml/helpers/xss_mods.rb +165 -0
  24. data/lib/haml/html.rb +412 -0
  25. data/lib/haml/html/erb.rb +141 -0
  26. data/lib/haml/parser.rb +760 -0
  27. data/lib/haml/railtie.rb +19 -0
  28. data/lib/haml/root.rb +7 -0
  29. data/lib/haml/shared.rb +78 -0
  30. data/lib/haml/template.rb +99 -0
  31. data/lib/haml/template/options.rb +16 -0
  32. data/lib/haml/template/patch.rb +58 -0
  33. data/lib/haml/template/plugin.rb +123 -0
  34. data/lib/haml/util.rb +842 -0
  35. data/lib/haml/version.rb +109 -0
  36. data/lib/sass.rb +8 -0
  37. data/lib/sass/plugin.rb +10 -0
  38. data/lib/sass/rails2_shim.rb +9 -0
  39. data/lib/sass/rails3_shim.rb +16 -0
  40. data/rails/init.rb +1 -0
  41. data/test/benchmark.rb +91 -0
  42. data/test/gemfiles/Gemfile.rails-2.0.x +8 -0
  43. data/test/gemfiles/Gemfile.rails-2.0.x.lock +38 -0
  44. data/test/gemfiles/Gemfile.rails-2.1.x +8 -0
  45. data/test/gemfiles/Gemfile.rails-2.1.x.lock +38 -0
  46. data/test/gemfiles/Gemfile.rails-2.2.x +8 -0
  47. data/test/gemfiles/Gemfile.rails-2.2.x.lock +38 -0
  48. data/test/gemfiles/Gemfile.rails-2.3.x +8 -0
  49. data/test/gemfiles/Gemfile.rails-2.3.x.lock +40 -0
  50. data/test/gemfiles/Gemfile.rails-3.0.x +8 -0
  51. data/test/gemfiles/Gemfile.rails-3.0.x.lock +85 -0
  52. data/test/gemfiles/Gemfile.rails-3.1.x +8 -0
  53. data/test/gemfiles/Gemfile.rails-3.1.x.lock +98 -0
  54. data/test/gemfiles/Gemfile.rails-xss-2.3.x +9 -0
  55. data/test/gemfiles/Gemfile.rails-xss-2.3.x.lock +42 -0
  56. data/test/haml-ejs/haml-ejs_test.rb +22 -0
  57. data/test/haml-ejs/templates/conditional.input +3 -0
  58. data/test/haml-ejs/templates/conditional.output +3 -0
  59. data/test/haml-ejs/templates/conditional_and_interpolation.input +2 -0
  60. data/test/haml-ejs/templates/conditional_and_interpolation.output +3 -0
  61. data/test/haml-ejs/templates/conditional_else.input +5 -0
  62. data/test/haml-ejs/templates/conditional_else.output +5 -0
  63. data/test/haml-ejs/templates/conditional_else_elsif.input +7 -0
  64. data/test/haml-ejs/templates/conditional_else_elsif.output +7 -0
  65. data/test/haml-ejs/templates/conditional_elsif.input +5 -0
  66. data/test/haml-ejs/templates/conditional_elsif.output +5 -0
  67. data/test/haml-ejs/templates/conditional_unless.input +3 -0
  68. data/test/haml-ejs/templates/conditional_unless.output +3 -0
  69. data/test/haml-ejs/templates/conditional_unless_else.input +5 -0
  70. data/test/haml-ejs/templates/conditional_unless_else.output +5 -0
  71. data/test/haml-ejs/templates/conditional_unless_elsif_else.input +5 -0
  72. data/test/haml-ejs/templates/conditional_unless_elsif_else.output +5 -0
  73. data/test/haml-ejs/templates/interpolation.input +2 -0
  74. data/test/haml-ejs/templates/interpolation.output +1 -0
  75. data/test/haml-ejs/templates/iteration.input +2 -0
  76. data/test/haml-ejs/templates/iteration.output +3 -0
  77. data/test/haml-ejs/templates/suite.input +26 -0
  78. data/test/haml-ejs/templates/suite.output +27 -0
  79. data/test/haml/engine_test.rb +1925 -0
  80. data/test/haml/erb/_av_partial_1.erb +12 -0
  81. data/test/haml/erb/_av_partial_2.erb +8 -0
  82. data/test/haml/erb/action_view.erb +62 -0
  83. data/test/haml/erb/standard.erb +55 -0
  84. data/test/haml/helper_test.rb +454 -0
  85. data/test/haml/html2haml/erb_tests.rb +440 -0
  86. data/test/haml/html2haml_test.rb +336 -0
  87. data/test/haml/markaby/standard.mab +52 -0
  88. data/test/haml/mocks/article.rb +6 -0
  89. data/test/haml/results/content_for_layout.xhtml +12 -0
  90. data/test/haml/results/eval_suppressed.xhtml +9 -0
  91. data/test/haml/results/filters.xhtml +62 -0
  92. data/test/haml/results/helpers.xhtml +70 -0
  93. data/test/haml/results/helpful.xhtml +10 -0
  94. data/test/haml/results/just_stuff.xhtml +70 -0
  95. data/test/haml/results/list.xhtml +12 -0
  96. data/test/haml/results/nuke_inner_whitespace.xhtml +40 -0
  97. data/test/haml/results/nuke_outer_whitespace.xhtml +148 -0
  98. data/test/haml/results/original_engine.xhtml +20 -0
  99. data/test/haml/results/partial_layout.xhtml +5 -0
  100. data/test/haml/results/partials.xhtml +21 -0
  101. data/test/haml/results/render_layout.xhtml +3 -0
  102. data/test/haml/results/silent_script.xhtml +74 -0
  103. data/test/haml/results/standard.xhtml +162 -0
  104. data/test/haml/results/tag_parsing.xhtml +23 -0
  105. data/test/haml/results/very_basic.xhtml +5 -0
  106. data/test/haml/results/whitespace_handling.xhtml +89 -0
  107. data/test/haml/spec/README.md +97 -0
  108. data/test/haml/spec/lua_haml_spec.lua +30 -0
  109. data/test/haml/spec/ruby_haml_test.rb +19 -0
  110. data/test/haml/spec/tests.json +534 -0
  111. data/test/haml/spec_test.rb +44 -0
  112. data/test/haml/template_test.rb +419 -0
  113. data/test/haml/templates/_av_partial_1.haml +9 -0
  114. data/test/haml/templates/_av_partial_1_ugly.haml +9 -0
  115. data/test/haml/templates/_av_partial_2.haml +5 -0
  116. data/test/haml/templates/_av_partial_2_ugly.haml +5 -0
  117. data/test/haml/templates/_layout.erb +3 -0
  118. data/test/haml/templates/_layout_for_partial.haml +3 -0
  119. data/test/haml/templates/_partial.haml +8 -0
  120. data/test/haml/templates/_text_area.haml +3 -0
  121. data/test/haml/templates/action_view.haml +47 -0
  122. data/test/haml/templates/action_view_ugly.haml +47 -0
  123. data/test/haml/templates/breakage.haml +8 -0
  124. data/test/haml/templates/content_for_layout.haml +8 -0
  125. data/test/haml/templates/eval_suppressed.haml +11 -0
  126. data/test/haml/templates/filters.haml +66 -0
  127. data/test/haml/templates/helpers.haml +55 -0
  128. data/test/haml/templates/helpful.haml +11 -0
  129. data/test/haml/templates/just_stuff.haml +85 -0
  130. data/test/haml/templates/list.haml +12 -0
  131. data/test/haml/templates/nuke_inner_whitespace.haml +32 -0
  132. data/test/haml/templates/nuke_outer_whitespace.haml +144 -0
  133. data/test/haml/templates/original_engine.haml +17 -0
  134. data/test/haml/templates/partial_layout.haml +10 -0
  135. data/test/haml/templates/partialize.haml +1 -0
  136. data/test/haml/templates/partials.haml +12 -0
  137. data/test/haml/templates/render_layout.haml +2 -0
  138. data/test/haml/templates/silent_script.haml +40 -0
  139. data/test/haml/templates/standard.haml +43 -0
  140. data/test/haml/templates/standard_ugly.haml +43 -0
  141. data/test/haml/templates/tag_parsing.haml +21 -0
  142. data/test/haml/templates/very_basic.haml +4 -0
  143. data/test/haml/templates/whitespace_handling.haml +87 -0
  144. data/test/haml/util_test.rb +300 -0
  145. data/test/linked_rails.rb +42 -0
  146. data/test/test_helper.rb +75 -0
  147. data/vendor/sass/CONTRIBUTING +3 -0
  148. data/vendor/sass/MIT-LICENSE +20 -0
  149. data/vendor/sass/README.md +201 -0
  150. data/vendor/sass/Rakefile +339 -0
  151. data/vendor/sass/TODO +39 -0
  152. data/vendor/sass/VERSION +1 -0
  153. data/vendor/sass/VERSION_NAME +1 -0
  154. data/vendor/sass/bin/sass +8 -0
  155. data/vendor/sass/bin/sass-convert +7 -0
  156. data/vendor/sass/bin/scss +8 -0
  157. data/vendor/sass/doc-src/FAQ.md +35 -0
  158. data/vendor/sass/doc-src/INDENTED_SYNTAX.md +210 -0
  159. data/vendor/sass/doc-src/SASS_CHANGELOG.md +2214 -0
  160. data/vendor/sass/doc-src/SASS_REFERENCE.md +1957 -0
  161. data/vendor/sass/doc-src/SCSS_FOR_SASS_USERS.md +155 -0
  162. data/vendor/sass/ext/extconf.rb +10 -0
  163. data/vendor/sass/extra/update_watch.rb +13 -0
  164. data/vendor/sass/init.rb +18 -0
  165. data/vendor/sass/lib/sass.rb +72 -0
  166. data/vendor/sass/lib/sass/cache_stores.rb +15 -0
  167. data/vendor/sass/lib/sass/cache_stores/base.rb +84 -0
  168. data/vendor/sass/lib/sass/cache_stores/chain.rb +33 -0
  169. data/vendor/sass/lib/sass/cache_stores/filesystem.rb +58 -0
  170. data/vendor/sass/lib/sass/cache_stores/memory.rb +47 -0
  171. data/vendor/sass/lib/sass/cache_stores/null.rb +25 -0
  172. data/vendor/sass/lib/sass/callbacks.rb +66 -0
  173. data/vendor/sass/lib/sass/css.rb +294 -0
  174. data/vendor/sass/lib/sass/engine.rb +862 -0
  175. data/vendor/sass/lib/sass/environment.rb +155 -0
  176. data/vendor/sass/lib/sass/error.rb +201 -0
  177. data/vendor/sass/lib/sass/exec.rb +659 -0
  178. data/vendor/sass/lib/sass/importers.rb +22 -0
  179. data/vendor/sass/lib/sass/importers/base.rb +138 -0
  180. data/vendor/sass/lib/sass/importers/filesystem.rb +144 -0
  181. data/vendor/sass/lib/sass/less.rb +382 -0
  182. data/vendor/sass/lib/sass/plugin.rb +136 -0
  183. data/vendor/sass/lib/sass/plugin/compiler.rb +358 -0
  184. data/vendor/sass/lib/sass/plugin/configuration.rb +125 -0
  185. data/vendor/sass/lib/sass/plugin/generic.rb +15 -0
  186. data/vendor/sass/lib/sass/plugin/merb.rb +48 -0
  187. data/vendor/sass/lib/sass/plugin/rack.rb +60 -0
  188. data/vendor/sass/lib/sass/plugin/rails.rb +47 -0
  189. data/vendor/sass/lib/sass/plugin/staleness_checker.rb +173 -0
  190. data/vendor/sass/lib/sass/railtie.rb +9 -0
  191. data/vendor/sass/lib/sass/repl.rb +58 -0
  192. data/vendor/sass/lib/sass/root.rb +7 -0
  193. data/vendor/sass/lib/sass/script.rb +40 -0
  194. data/vendor/sass/lib/sass/script/bool.rb +18 -0
  195. data/vendor/sass/lib/sass/script/color.rb +480 -0
  196. data/vendor/sass/lib/sass/script/css_lexer.rb +29 -0
  197. data/vendor/sass/lib/sass/script/css_parser.rb +31 -0
  198. data/vendor/sass/lib/sass/script/funcall.rb +162 -0
  199. data/vendor/sass/lib/sass/script/functions.rb +1343 -0
  200. data/vendor/sass/lib/sass/script/interpolation.rb +70 -0
  201. data/vendor/sass/lib/sass/script/lexer.rb +334 -0
  202. data/vendor/sass/lib/sass/script/list.rb +76 -0
  203. data/vendor/sass/lib/sass/script/literal.rb +245 -0
  204. data/vendor/sass/lib/sass/script/node.rb +91 -0
  205. data/vendor/sass/lib/sass/script/number.rb +429 -0
  206. data/vendor/sass/lib/sass/script/operation.rb +91 -0
  207. data/vendor/sass/lib/sass/script/parser.rb +467 -0
  208. data/vendor/sass/lib/sass/script/string.rb +51 -0
  209. data/vendor/sass/lib/sass/script/string_interpolation.rb +94 -0
  210. data/vendor/sass/lib/sass/script/unary_operation.rb +57 -0
  211. data/vendor/sass/lib/sass/script/variable.rb +54 -0
  212. data/vendor/sass/lib/sass/scss.rb +17 -0
  213. data/vendor/sass/lib/sass/scss/css_parser.rb +46 -0
  214. data/vendor/sass/lib/sass/scss/parser.rb +920 -0
  215. data/vendor/sass/lib/sass/scss/rx.rb +127 -0
  216. data/vendor/sass/lib/sass/scss/sass_parser.rb +11 -0
  217. data/vendor/sass/lib/sass/scss/script_lexer.rb +15 -0
  218. data/vendor/sass/lib/sass/scss/script_parser.rb +25 -0
  219. data/vendor/sass/lib/sass/scss/static_parser.rb +40 -0
  220. data/vendor/sass/lib/sass/selector.rb +361 -0
  221. data/vendor/sass/lib/sass/selector/abstract_sequence.rb +62 -0
  222. data/vendor/sass/lib/sass/selector/comma_sequence.rb +81 -0
  223. data/vendor/sass/lib/sass/selector/sequence.rb +233 -0
  224. data/vendor/sass/lib/sass/selector/simple.rb +113 -0
  225. data/vendor/sass/lib/sass/selector/simple_sequence.rb +134 -0
  226. data/vendor/sass/lib/sass/shared.rb +78 -0
  227. data/vendor/sass/lib/sass/tree/charset_node.rb +22 -0
  228. data/vendor/sass/lib/sass/tree/comment_node.rb +77 -0
  229. data/vendor/sass/lib/sass/tree/debug_node.rb +18 -0
  230. data/vendor/sass/lib/sass/tree/directive_node.rb +23 -0
  231. data/vendor/sass/lib/sass/tree/each_node.rb +24 -0
  232. data/vendor/sass/lib/sass/tree/extend_node.rb +29 -0
  233. data/vendor/sass/lib/sass/tree/for_node.rb +36 -0
  234. data/vendor/sass/lib/sass/tree/function_node.rb +27 -0
  235. data/vendor/sass/lib/sass/tree/if_node.rb +65 -0
  236. data/vendor/sass/lib/sass/tree/import_node.rb +68 -0
  237. data/vendor/sass/lib/sass/tree/media_node.rb +32 -0
  238. data/vendor/sass/lib/sass/tree/mixin_def_node.rb +27 -0
  239. data/vendor/sass/lib/sass/tree/mixin_node.rb +32 -0
  240. data/vendor/sass/lib/sass/tree/node.rb +204 -0
  241. data/vendor/sass/lib/sass/tree/prop_node.rb +155 -0
  242. data/vendor/sass/lib/sass/tree/return_node.rb +18 -0
  243. data/vendor/sass/lib/sass/tree/root_node.rb +28 -0
  244. data/vendor/sass/lib/sass/tree/rule_node.rb +129 -0
  245. data/vendor/sass/lib/sass/tree/variable_node.rb +30 -0
  246. data/vendor/sass/lib/sass/tree/visitors/base.rb +75 -0
  247. data/vendor/sass/lib/sass/tree/visitors/check_nesting.rb +134 -0
  248. data/vendor/sass/lib/sass/tree/visitors/convert.rb +255 -0
  249. data/vendor/sass/lib/sass/tree/visitors/cssize.rb +175 -0
  250. data/vendor/sass/lib/sass/tree/visitors/perform.rb +301 -0
  251. data/vendor/sass/lib/sass/tree/visitors/to_css.rb +216 -0
  252. data/vendor/sass/lib/sass/tree/warn_node.rb +18 -0
  253. data/vendor/sass/lib/sass/tree/while_node.rb +18 -0
  254. data/vendor/sass/lib/sass/util.rb +669 -0
  255. data/vendor/sass/lib/sass/util/subset_map.rb +101 -0
  256. data/vendor/sass/lib/sass/version.rb +112 -0
  257. data/vendor/sass/rails/init.rb +1 -0
  258. data/vendor/sass/sass.gemspec +32 -0
  259. data/vendor/sass/test/sass/cache_test.rb +74 -0
  260. data/vendor/sass/test/sass/callbacks_test.rb +61 -0
  261. data/vendor/sass/test/sass/conversion_test.rb +1203 -0
  262. data/vendor/sass/test/sass/css2sass_test.rb +364 -0
  263. data/vendor/sass/test/sass/data/hsl-rgb.txt +319 -0
  264. data/vendor/sass/test/sass/engine_test.rb +2469 -0
  265. data/vendor/sass/test/sass/extend_test.rb +1348 -0
  266. data/vendor/sass/test/sass/functions_test.rb +1025 -0
  267. data/vendor/sass/test/sass/importer_test.rb +82 -0
  268. data/vendor/sass/test/sass/less_conversion_test.rb +653 -0
  269. data/vendor/sass/test/sass/mock_importer.rb +49 -0
  270. data/vendor/sass/test/sass/more_results/more1.css +9 -0
  271. data/vendor/sass/test/sass/more_results/more1_with_line_comments.css +26 -0
  272. data/vendor/sass/test/sass/more_results/more_import.css +29 -0
  273. data/vendor/sass/test/sass/more_templates/_more_partial.sass +2 -0
  274. data/vendor/sass/test/sass/more_templates/more1.sass +23 -0
  275. data/vendor/sass/test/sass/more_templates/more_import.sass +11 -0
  276. data/vendor/sass/test/sass/plugin_test.rb +469 -0
  277. data/vendor/sass/test/sass/results/alt.css +4 -0
  278. data/vendor/sass/test/sass/results/basic.css +9 -0
  279. data/vendor/sass/test/sass/results/compact.css +5 -0
  280. data/vendor/sass/test/sass/results/complex.css +86 -0
  281. data/vendor/sass/test/sass/results/compressed.css +1 -0
  282. data/vendor/sass/test/sass/results/expanded.css +19 -0
  283. data/vendor/sass/test/sass/results/if.css +3 -0
  284. data/vendor/sass/test/sass/results/import.css +31 -0
  285. data/vendor/sass/test/sass/results/import_charset.css +4 -0
  286. data/vendor/sass/test/sass/results/import_charset_1_8.css +4 -0
  287. data/vendor/sass/test/sass/results/import_charset_ibm866.css +4 -0
  288. data/vendor/sass/test/sass/results/line_numbers.css +49 -0
  289. data/vendor/sass/test/sass/results/mixins.css +95 -0
  290. data/vendor/sass/test/sass/results/multiline.css +24 -0
  291. data/vendor/sass/test/sass/results/nested.css +22 -0
  292. data/vendor/sass/test/sass/results/options.css +1 -0
  293. data/vendor/sass/test/sass/results/parent_ref.css +13 -0
  294. data/vendor/sass/test/sass/results/script.css +16 -0
  295. data/vendor/sass/test/sass/results/scss_import.css +31 -0
  296. data/vendor/sass/test/sass/results/scss_importee.css +2 -0
  297. data/vendor/sass/test/sass/results/subdir/nested_subdir/nested_subdir.css +1 -0
  298. data/vendor/sass/test/sass/results/subdir/subdir.css +3 -0
  299. data/vendor/sass/test/sass/results/units.css +11 -0
  300. data/vendor/sass/test/sass/results/warn.css +0 -0
  301. data/vendor/sass/test/sass/results/warn_imported.css +0 -0
  302. data/vendor/sass/test/sass/script_conversion_test.rb +283 -0
  303. data/vendor/sass/test/sass/script_test.rb +496 -0
  304. data/vendor/sass/test/sass/scss/css_test.rb +916 -0
  305. data/vendor/sass/test/sass/scss/rx_test.rb +156 -0
  306. data/vendor/sass/test/sass/scss/scss_test.rb +1249 -0
  307. data/vendor/sass/test/sass/scss/test_helper.rb +37 -0
  308. data/vendor/sass/test/sass/templates/_imported_charset_ibm866.sass +4 -0
  309. data/vendor/sass/test/sass/templates/_imported_charset_utf8.sass +4 -0
  310. data/vendor/sass/test/sass/templates/_partial.sass +2 -0
  311. data/vendor/sass/test/sass/templates/alt.sass +16 -0
  312. data/vendor/sass/test/sass/templates/basic.sass +23 -0
  313. data/vendor/sass/test/sass/templates/bork1.sass +2 -0
  314. data/vendor/sass/test/sass/templates/bork2.sass +2 -0
  315. data/vendor/sass/test/sass/templates/bork3.sass +2 -0
  316. data/vendor/sass/test/sass/templates/bork4.sass +2 -0
  317. data/vendor/sass/test/sass/templates/compact.sass +17 -0
  318. data/vendor/sass/test/sass/templates/complex.sass +305 -0
  319. data/vendor/sass/test/sass/templates/compressed.sass +15 -0
  320. data/vendor/sass/test/sass/templates/expanded.sass +17 -0
  321. data/vendor/sass/test/sass/templates/if.sass +11 -0
  322. data/vendor/sass/test/sass/templates/import.sass +12 -0
  323. data/vendor/sass/test/sass/templates/import_charset.sass +7 -0
  324. data/vendor/sass/test/sass/templates/import_charset_1_8.sass +4 -0
  325. data/vendor/sass/test/sass/templates/import_charset_ibm866.sass +9 -0
  326. data/vendor/sass/test/sass/templates/importee.less +2 -0
  327. data/vendor/sass/test/sass/templates/importee.sass +19 -0
  328. data/vendor/sass/test/sass/templates/line_numbers.sass +13 -0
  329. data/vendor/sass/test/sass/templates/mixin_bork.sass +5 -0
  330. data/vendor/sass/test/sass/templates/mixins.sass +76 -0
  331. data/vendor/sass/test/sass/templates/multiline.sass +20 -0
  332. data/vendor/sass/test/sass/templates/nested.sass +25 -0
  333. data/vendor/sass/test/sass/templates/nested_bork1.sass +2 -0
  334. data/vendor/sass/test/sass/templates/nested_bork2.sass +2 -0
  335. data/vendor/sass/test/sass/templates/nested_bork3.sass +2 -0
  336. data/vendor/sass/test/sass/templates/nested_bork4.sass +2 -0
  337. data/vendor/sass/test/sass/templates/nested_import.sass +2 -0
  338. data/vendor/sass/test/sass/templates/nested_mixin_bork.sass +6 -0
  339. data/vendor/sass/test/sass/templates/options.sass +2 -0
  340. data/vendor/sass/test/sass/templates/parent_ref.sass +25 -0
  341. data/vendor/sass/test/sass/templates/script.sass +101 -0
  342. data/vendor/sass/test/sass/templates/scss_import.scss +11 -0
  343. data/vendor/sass/test/sass/templates/scss_importee.scss +1 -0
  344. data/vendor/sass/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +2 -0
  345. data/vendor/sass/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +3 -0
  346. data/vendor/sass/test/sass/templates/subdir/subdir.sass +6 -0
  347. data/vendor/sass/test/sass/templates/units.sass +11 -0
  348. data/vendor/sass/test/sass/templates/warn.sass +3 -0
  349. data/vendor/sass/test/sass/templates/warn_imported.sass +4 -0
  350. data/vendor/sass/test/sass/test_helper.rb +8 -0
  351. data/vendor/sass/test/sass/util/subset_map_test.rb +91 -0
  352. data/vendor/sass/test/sass/util_test.rb +254 -0
  353. data/vendor/sass/test/test_helper.rb +69 -0
  354. data/vendor/sass/yard/callbacks.rb +29 -0
  355. data/vendor/sass/yard/default/fulldoc/html/css/common.sass +26 -0
  356. data/vendor/sass/yard/default/layout/html/footer.erb +12 -0
  357. data/vendor/sass/yard/inherited_hash.rb +41 -0
  358. metadata +458 -0
@@ -0,0 +1,388 @@
1
+ module Haml
2
+ # The module containing the default Haml filters,
3
+ # as well as the base module, {Haml::Filters::Base}.
4
+ #
5
+ # @see Haml::Filters::Base
6
+ module Filters
7
+ # @return [{String => Haml::Filters::Base}] a hash of filter names to classes
8
+ def self.defined
9
+ @defined ||= {}
10
+ end
11
+
12
+ # The base module for Haml filters.
13
+ # User-defined filters should be modules including this module.
14
+ # The name of the filter is taken by downcasing the module name.
15
+ # For instance, if the module is named `FooBar`, the filter will be `:foobar`.
16
+ #
17
+ # A user-defined filter should override either \{#render} or {\#compile}.
18
+ # \{#render} is the most common.
19
+ # It takes a string, the filter source,
20
+ # and returns another string, the result of the filter.
21
+ # For example, the following will define a filter named `:sass`:
22
+ #
23
+ # module Haml::Filters::Sass
24
+ # include Haml::Filters::Base
25
+ #
26
+ # def render(text)
27
+ # ::Sass::Engine.new(text).render
28
+ # end
29
+ # end
30
+ #
31
+ # For details on overriding \{#compile}, see its documentation.
32
+ #
33
+ # Note that filters overriding \{#render} automatically support `#{}`
34
+ # for interpolating Ruby code.
35
+ # Those overriding \{#compile} will need to add such support manually
36
+ # if it's desired.
37
+ module Base
38
+ # This method is automatically called when {Base} is included in a module.
39
+ # It automatically defines a filter
40
+ # with the downcased name of that module.
41
+ # For example, if the module is named `FooBar`, the filter will be `:foobar`.
42
+ #
43
+ # @param base [Module, Class] The module that this is included in
44
+ def self.included(base)
45
+ Filters.defined[base.name.split("::").last.downcase] = base
46
+ base.extend(base)
47
+ end
48
+
49
+ # Takes the source text that should be passed to the filter
50
+ # and returns the result of running the filter on that string.
51
+ #
52
+ # This should be overridden in most individual filter modules
53
+ # to render text with the given filter.
54
+ # If \{#compile} is overridden, however, \{#render} doesn't need to be.
55
+ #
56
+ # @param text [String] The source text for the filter to process
57
+ # @return [String] The filtered result
58
+ # @raise [Haml::Error] if it's not overridden
59
+ def render(text)
60
+ raise Error.new("#{self.inspect}#render not defined!")
61
+ end
62
+
63
+ # Same as \{#render}, but takes a {Haml::Engine} options hash as well.
64
+ # It's only safe to rely on options made available in {Haml::Engine#options\_for\_buffer}.
65
+ #
66
+ # @see #render
67
+ # @param text [String] The source text for the filter to process
68
+ # @return [String] The filtered result
69
+ # @raise [Haml::Error] if it or \{#render} isn't overridden
70
+ def render_with_options(text, options)
71
+ render(text)
72
+ end
73
+
74
+ # Same as \{#compile}, but requires the necessary files first.
75
+ # *This is used by {Haml::Engine} and is not intended to be overridden or used elsewhere.*
76
+ #
77
+ # @see #compile
78
+ def internal_compile(*args)
79
+ resolve_lazy_requires
80
+ compile(*args)
81
+ end
82
+
83
+ # This should be overridden when a filter needs to have access to the Haml evaluation context.
84
+ # Rather than applying a filter to a string at compile-time,
85
+ # \{#compile} uses the {Haml::Compiler} instance to compile the string to Ruby code
86
+ # that will be executed in the context of the active Haml template.
87
+ #
88
+ # Warning: the {Haml::Compiler} interface is neither well-documented
89
+ # nor guaranteed to be stable.
90
+ # If you want to make use of it, you'll probably need to look at the source code
91
+ # and should test your filter when upgrading to new Haml versions.
92
+ #
93
+ # @param compiler [Haml::Compiler] The compiler instance
94
+ # @param text [String] The text of the filter
95
+ # @raise [Haml::Error] if none of \{#compile}, \{#render}, and \{#render_with_options} are overridden
96
+ def compile(compiler, text)
97
+ resolve_lazy_requires
98
+ filter = self
99
+ compiler.instance_eval do
100
+ if contains_interpolation?(text)
101
+ return if options[:suppress_eval]
102
+
103
+ text = unescape_interpolation(text).gsub(/(\\+)n/) do |s|
104
+ escapes = $1.size
105
+ next s if escapes % 2 == 0
106
+ ("\\" * (escapes - 1)) + "\n"
107
+ end
108
+ # We need to add a newline at the beginning to get the
109
+ # filter lines to line up (since the Haml filter contains
110
+ # a line that doesn't show up in the source, namely the
111
+ # filter name). Then we need to escape the trailing
112
+ # newline so that the whole filter block doesn't take up
113
+ # too many.
114
+ text = "\n" + text.sub(/\n"\Z/, "\\n\"")
115
+ push_script <<RUBY.rstrip, :escape_html => false
116
+ find_and_preserve(#{filter.inspect}.render_with_options(#{text}, _hamlout.options))
117
+ RUBY
118
+ return
119
+ end
120
+
121
+ rendered = Haml::Helpers::find_and_preserve(filter.render_with_options(text, compiler.options), compiler.options[:preserve])
122
+
123
+ if !options[:ugly]
124
+ push_text(rendered.rstrip.gsub("\n", "\n#{' ' * @output_tabs}"))
125
+ else
126
+ push_text(rendered.rstrip)
127
+ end
128
+ end
129
+ end
130
+
131
+ # This becomes a class method of modules that include {Base}.
132
+ # It allows the module to specify one or more Ruby files
133
+ # that Haml should try to require when compiling the filter.
134
+ #
135
+ # The first file specified is tried first, then the second, etc.
136
+ # If none are found, the compilation throws an exception.
137
+ #
138
+ # For example:
139
+ #
140
+ # module Haml::Filters::Markdown
141
+ # lazy_require 'rdiscount', 'peg_markdown', 'maruku', 'bluecloth', 'kramdown'
142
+ #
143
+ # ...
144
+ # end
145
+ #
146
+ # @param reqs [Array<String>] The requires to run
147
+ def lazy_require(*reqs)
148
+ @lazy_requires = reqs
149
+ end
150
+
151
+ private
152
+
153
+ def resolve_lazy_requires
154
+ return unless @lazy_requires
155
+
156
+ @lazy_requires[0...-1].each do |req|
157
+ begin
158
+ @required = req
159
+ require @required
160
+ return
161
+ rescue LoadError; end # RCov doesn't see this, but it is run
162
+ end
163
+
164
+ begin
165
+ @required = @lazy_requires[-1]
166
+ require @required
167
+ rescue LoadError => e
168
+ classname = self.name.match(/\w+$/)[0]
169
+
170
+ if @lazy_requires.size == 1
171
+ raise Error.new("Can't run #{classname} filter; required file '#{@lazy_requires.first}' not found")
172
+ else
173
+ raise Error.new("Can't run #{classname} filter; required #{@lazy_requires.map { |r| "'#{r}'" }.join(' or ')}, but none were found")
174
+ end
175
+ end
176
+ end
177
+ end
178
+ end
179
+ end
180
+
181
+ begin
182
+ require 'rubygems'
183
+ rescue LoadError; end
184
+
185
+ module Haml
186
+ module Filters
187
+ # Does not parse the filtered text.
188
+ # This is useful for large blocks of text without HTML tags,
189
+ # when you don't want lines starting with `.` or `-`
190
+ # to be parsed.
191
+ module Plain
192
+ include Base
193
+
194
+ # @see Base#render
195
+ def render(text); text; end
196
+ end
197
+
198
+ # Surrounds the filtered text with `<script>` and CDATA tags.
199
+ # Useful for including inline Javascript.
200
+ module Javascript
201
+ include Base
202
+
203
+ # @see Base#render_with_options
204
+ def render_with_options(text, options)
205
+ if options[:format] == :html5
206
+ type = ''
207
+ else
208
+ type = " type=#{options[:attr_wrapper]}text/javascript#{options[:attr_wrapper]}"
209
+ end
210
+
211
+ <<END
212
+ <script#{type}>
213
+ //<![CDATA[
214
+ #{text.rstrip.gsub("\n", "\n ")}
215
+ //]]>
216
+ </script>
217
+ END
218
+ end
219
+ end
220
+
221
+ # Surrounds the filtered text with `<style>` and CDATA tags.
222
+ # Useful for including inline CSS.
223
+ module Css
224
+ include Base
225
+
226
+ # @see Base#render_with_options
227
+ def render_with_options(text, options)
228
+ if options[:format] == :html5
229
+ type = ''
230
+ else
231
+ type = " type=#{options[:attr_wrapper]}text/css#{options[:attr_wrapper]}"
232
+ end
233
+
234
+ <<END
235
+ <style#{type}>
236
+ /*<![CDATA[*/
237
+ #{text.rstrip.gsub("\n", "\n ")}
238
+ /*]]>*/
239
+ </style>
240
+ END
241
+ end
242
+ end
243
+
244
+ # Surrounds the filtered text with CDATA tags.
245
+ module Cdata
246
+ include Base
247
+
248
+ # @see Base#render
249
+ def render(text)
250
+ "<![CDATA[#{("\n" + text).rstrip.gsub("\n", "\n ")}\n]]>"
251
+ end
252
+ end
253
+
254
+ # Works the same as {Plain}, but HTML-escapes the text
255
+ # before placing it in the document.
256
+ module Escaped
257
+ include Base
258
+
259
+ # @see Base#render
260
+ def render(text)
261
+ Haml::Helpers.html_escape text
262
+ end
263
+ end
264
+
265
+ # Parses the filtered text with the normal Ruby interpreter.
266
+ # All output sent to `$stdout`, such as with `puts`,
267
+ # is output into the Haml document.
268
+ # Not available if the {file:HAML_REFERENCE.md#suppress_eval-option `:suppress_eval`} option is set to true.
269
+ # The Ruby code is evaluated in the same context as the Haml template.
270
+ module Ruby
271
+ include Base
272
+ lazy_require 'stringio'
273
+
274
+ # @see Base#compile
275
+ def compile(compiler, text)
276
+ return if compiler.options[:suppress_eval]
277
+ compiler.instance_eval do
278
+ push_silent <<-FIRST.gsub("\n", ';') + text + <<-LAST.gsub("\n", ';')
279
+ _haml_old_stdout = $stdout
280
+ $stdout = StringIO.new(_hamlout.buffer, 'a')
281
+ FIRST
282
+ _haml_old_stdout, $stdout = $stdout, _haml_old_stdout
283
+ _haml_old_stdout.close
284
+ LAST
285
+ end
286
+ end
287
+ end
288
+
289
+ # Inserts the filtered text into the template with whitespace preserved.
290
+ # `preserve`d blocks of text aren't indented,
291
+ # and newlines are replaced with the HTML escape code for newlines,
292
+ # to preserve nice-looking output.
293
+ #
294
+ # @see Haml::Helpers#preserve
295
+ module Preserve
296
+ include Base
297
+
298
+ # @see Base#render
299
+ def render(text)
300
+ Haml::Helpers.preserve text
301
+ end
302
+ end
303
+
304
+ # Parses the filtered text with {Sass} to produce CSS output.
305
+ module Sass
306
+ include Base
307
+ lazy_require 'sass/plugin'
308
+
309
+ # @see Base#render
310
+ def render(text)
311
+ ::Sass::Engine.new(text, ::Sass::Plugin.engine_options).render
312
+ end
313
+ end
314
+
315
+ # Parses the filtered text with ERB.
316
+ # Not available if the {file:HAML_REFERENCE.md#suppress_eval-option `:suppress_eval`} option is set to true.
317
+ # Embedded Ruby code is evaluated in the same context as the Haml template.
318
+ module ERB
319
+ include Base
320
+ lazy_require 'erb'
321
+
322
+ # @see Base#compile
323
+ def compile(compiler, text)
324
+ return if compiler.options[:suppress_eval]
325
+ src = ::ERB.new(text).src.sub(/^#coding:.*?\n/, '').
326
+ sub(/^_erbout = '';/, "")
327
+ compiler.send(:push_silent, src)
328
+ end
329
+ end
330
+
331
+ # Parses the filtered text with [Textile](http://www.textism.com/tools/textile).
332
+ # Only works if [RedCloth](http://redcloth.org) is installed.
333
+ module Textile
334
+ include Base
335
+ lazy_require 'redcloth'
336
+
337
+ # @see Base#render
338
+ def render(text)
339
+ ::RedCloth.new(text).to_html(:textile)
340
+ end
341
+ end
342
+ # An alias for the Textile filter,
343
+ # since the only available Textile parser is RedCloth.
344
+ # @api public
345
+ RedCloth = Textile
346
+ Filters.defined['redcloth'] = RedCloth
347
+
348
+ # Parses the filtered text with [Markdown](http://daringfireball.net/projects/markdown).
349
+ # Only works if [RDiscount](https://github.com/rtomayko/rdiscount),
350
+ # [RPeg-Markdown](https://github.com/rtomayko/rpeg-markdown),
351
+ # [Maruku](http://maruku.rubyforge.org),
352
+ # [Kramdown](https://github.com/gettalong/kramdown),
353
+ # or [BlueCloth](http://www.deveiate.org/projects/BlueCloth) are installed.
354
+ module Markdown
355
+ include Base
356
+ lazy_require 'rdiscount', 'peg_markdown', 'maruku', 'bluecloth', 'kramdown'
357
+
358
+ # @see Base#render
359
+ def render(text)
360
+ engine = case @required
361
+ when 'rdiscount'
362
+ ::RDiscount
363
+ when 'peg_markdown'
364
+ ::PEGMarkdown
365
+ when 'maruku'
366
+ ::Maruku
367
+ when 'bluecloth'
368
+ ::BlueCloth
369
+ when 'kramdown'
370
+ ::Kramdown::Document
371
+ end
372
+ engine.new(text).to_html
373
+ end
374
+ end
375
+
376
+ # Parses the filtered text with [Maruku](http://maruku.rubyforge.org),
377
+ # which has some non-standard extensions to Markdown.
378
+ module Maruku
379
+ include Base
380
+ lazy_require 'maruku'
381
+
382
+ # @see Base#render
383
+ def render(text)
384
+ ::Maruku.new(text).to_html
385
+ end
386
+ end
387
+ end
388
+ end
@@ -0,0 +1,57 @@
1
+ module HamlEjs
2
+ def self.open_interpolate
3
+ @open_interpolate
4
+ end
5
+
6
+ def self.close_interpolate
7
+ @close_interpolate
8
+ end
9
+
10
+ def self.open_evaluate
11
+ @open_evaluate
12
+ end
13
+
14
+ def self.close_evaluate
15
+ @close_evaluate
16
+ end
17
+
18
+ def self.open_interpolate= sigil
19
+ @open_interpolate = sigil
20
+ end
21
+
22
+ def self.close_interpolate= sigil
23
+ @close_interpolate = sigil
24
+ end
25
+
26
+ def self.open_evaluate= sigil
27
+ @open_evaluate = sigil
28
+ end
29
+
30
+ def self.close_evaluate= sigil
31
+ @close_evaluate = sigil
32
+ end
33
+
34
+ def self.iterate
35
+ @iterate
36
+ end
37
+
38
+ def self.iterate= sigil
39
+ @iterate = sigil
40
+ end
41
+
42
+ def self.enabled
43
+ @enabled
44
+ end
45
+
46
+ def self.enabled= bool
47
+ @enabled = bool
48
+ end
49
+
50
+ self.open_interpolate = "<%="
51
+ self.close_interpolate = "%>"
52
+ self.open_evaluate = "<%"
53
+ self.close_evaluate = "%>"
54
+ self.iterate = "$.each"
55
+ self.enabled = true
56
+ end
57
+
@@ -0,0 +1,608 @@
1
+ module Haml
2
+ # This module contains various helpful methods to make it easier to do various tasks.
3
+ # {Haml::Helpers} is automatically included in the context
4
+ # that a Haml template is parsed in, so all these methods are at your
5
+ # disposal from within the template.
6
+ module Helpers
7
+ # An object that raises an error when \{#to\_s} is called.
8
+ # It's used to raise an error when the return value of a helper is used
9
+ # when it shouldn't be.
10
+ class ErrorReturn
11
+ # @param message [String] The error message to raise when \{#to\_s} is called
12
+ def initialize(method)
13
+ @message = <<MESSAGE
14
+ #{method} outputs directly to the Haml template.
15
+ Disregard its return value and use the - operator,
16
+ or use capture_haml to get the value as a String.
17
+ MESSAGE
18
+ end
19
+
20
+ # Raises an error.
21
+ #
22
+ # @raise [Haml::Error] The error
23
+ def to_s
24
+ raise Haml::Error.new(@message)
25
+ rescue Haml::Error => e
26
+ e.backtrace.shift
27
+
28
+ # If the ErrorReturn is used directly in the template,
29
+ # we don't want Haml's stuff to get into the backtrace,
30
+ # so we get rid of the format_script line.
31
+ #
32
+ # We also have to subtract one from the Haml line number
33
+ # since the value is passed to format_script the line after
34
+ # it's actually used.
35
+ if e.backtrace.first =~ /^\(eval\):\d+:in `format_script/
36
+ e.backtrace.shift
37
+ e.backtrace.first.gsub!(/^\(haml\):(\d+)/) {|s| "(haml):#{$1.to_i - 1}"}
38
+ end
39
+ raise e
40
+ end
41
+
42
+ # @return [String] A human-readable string representation
43
+ def inspect
44
+ "Haml::Helpers::ErrorReturn(#{@message.inspect})"
45
+ end
46
+ end
47
+
48
+ self.extend self
49
+
50
+ @@action_view_defined = false
51
+
52
+ # @return [Boolean] Whether or not ActionView is loaded
53
+ def self.action_view?
54
+ @@action_view_defined
55
+ end
56
+
57
+ # Note: this does **not** need to be called when using Haml helpers
58
+ # normally in Rails.
59
+ #
60
+ # Initializes the current object as though it were in the same context
61
+ # as a normal ActionView instance using Haml.
62
+ # This is useful if you want to use the helpers in a context
63
+ # other than the normal setup with ActionView.
64
+ # For example:
65
+ #
66
+ # context = Object.new
67
+ # class << context
68
+ # include Haml::Helpers
69
+ # end
70
+ # context.init_haml_helpers
71
+ # context.haml_tag :p, "Stuff"
72
+ #
73
+ def init_haml_helpers
74
+ @haml_buffer = Haml::Buffer.new(@haml_buffer, Haml::Engine.new('').send(:options_for_buffer))
75
+ nil
76
+ end
77
+
78
+ # Runs a block of code in a non-Haml context
79
+ # (i.e. \{#is\_haml?} will return false).
80
+ #
81
+ # This is mainly useful for rendering sub-templates such as partials in a non-Haml language,
82
+ # particularly where helpers may behave differently when run from Haml.
83
+ #
84
+ # Note that this is automatically applied to Rails partials.
85
+ #
86
+ # @yield A block which won't register as Haml
87
+ def non_haml
88
+ was_active = @haml_buffer.active?
89
+ @haml_buffer.active = false
90
+ yield
91
+ ensure
92
+ @haml_buffer.active = was_active
93
+ end
94
+
95
+ # Uses \{#preserve} to convert any newlines inside whitespace-sensitive tags
96
+ # into the HTML entities for endlines.
97
+ #
98
+ # @param tags [Array<String>] Tags that should have newlines escaped
99
+ #
100
+ # @overload find_and_preserve(input, tags = haml_buffer.options[:preserve])
101
+ # Escapes newlines within a string.
102
+ #
103
+ # @param input [String] The string within which to escape newlines
104
+ # @overload find_and_preserve(tags = haml_buffer.options[:preserve])
105
+ # Escapes newlines within a block of Haml code.
106
+ #
107
+ # @yield The block within which to escape newlines
108
+ def find_and_preserve(input = nil, tags = haml_buffer.options[:preserve], &block)
109
+ return find_and_preserve(capture_haml(&block), input || tags) if block
110
+ re = /<(#{tags.map(&Regexp.method(:escape)).join('|')})([^>]*)>(.*?)(<\/\1>)/im
111
+ input.to_s.gsub(re) do |s|
112
+ s =~ re # Can't rely on $1, etc. existing since Rails' SafeBuffer#gsub is incompatible
113
+ "<#{$1}#{$2}>#{preserve($3)}</#{$1}>"
114
+ end
115
+ end
116
+
117
+ # Takes any string, finds all the newlines, and converts them to
118
+ # HTML entities so they'll render correctly in
119
+ # whitespace-sensitive tags without screwing up the indentation.
120
+ #
121
+ # @overload perserve(input)
122
+ # Escapes newlines within a string.
123
+ #
124
+ # @param input [String] The string within which to escape all newlines
125
+ # @overload perserve
126
+ # Escapes newlines within a block of Haml code.
127
+ #
128
+ # @yield The block within which to escape newlines
129
+ def preserve(input = nil, &block)
130
+ return preserve(capture_haml(&block)) if block
131
+ input.to_s.chomp("\n").gsub(/\n/, '&#x000A;').gsub(/\r/, '')
132
+ end
133
+ alias_method :flatten, :preserve
134
+
135
+ # Takes an `Enumerable` object and a block
136
+ # and iterates over the enum,
137
+ # yielding each element to a Haml block
138
+ # and putting the result into `<li>` elements.
139
+ # This creates a list of the results of the block.
140
+ # For example:
141
+ #
142
+ # = list_of([['hello'], ['yall']]) do |i|
143
+ # = i[0]
144
+ #
145
+ # Produces:
146
+ #
147
+ # <li>hello</li>
148
+ # <li>yall</li>
149
+ #
150
+ # And
151
+ #
152
+ # = list_of({:title => 'All the stuff', :description => 'A book about all the stuff.'}) do |key, val|
153
+ # %h3= key.humanize
154
+ # %p= val
155
+ #
156
+ # Produces:
157
+ #
158
+ # <li>
159
+ # <h3>Title</h3>
160
+ # <p>All the stuff</p>
161
+ # </li>
162
+ # <li>
163
+ # <h3>Description</h3>
164
+ # <p>A book about all the stuff.</p>
165
+ # </li>
166
+ #
167
+ # @param enum [Enumerable] The list of objects to iterate over
168
+ # @yield [item] A block which contains Haml code that goes within list items
169
+ # @yieldparam item An element of `enum`
170
+ def list_of(enum, &block)
171
+ to_return = enum.collect do |i|
172
+ result = capture_haml(i, &block)
173
+
174
+ if result.count("\n") > 1
175
+ result = result.gsub("\n", "\n ")
176
+ result = "\n #{result.strip}\n"
177
+ else
178
+ result = result.strip
179
+ end
180
+
181
+ "<li>#{result}</li>"
182
+ end
183
+ to_return.join("\n")
184
+ end
185
+
186
+ # Returns a hash containing default assignments for the `xmlns`, `lang`, and `xml:lang`
187
+ # attributes of the `html` HTML element.
188
+ # For example,
189
+ #
190
+ # %html{html_attrs}
191
+ #
192
+ # becomes
193
+ #
194
+ # <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en-US' lang='en-US'>
195
+ #
196
+ # @param lang [String] The value of `xml:lang` and `lang`
197
+ # @return [{#to_s => String}] The attribute hash
198
+ def html_attrs(lang = 'en-US')
199
+ {:xmlns => "http://www.w3.org/1999/xhtml", 'xml:lang' => lang, :lang => lang}
200
+ end
201
+
202
+ # Increments the number of tabs the buffer automatically adds
203
+ # to the lines of the template.
204
+ # For example:
205
+ #
206
+ # %h1 foo
207
+ # - tab_up
208
+ # %p bar
209
+ # - tab_down
210
+ # %strong baz
211
+ #
212
+ # Produces:
213
+ #
214
+ # <h1>foo</h1>
215
+ # <p>bar</p>
216
+ # <strong>baz</strong>
217
+ #
218
+ # @param i [Fixnum] The number of tabs by which to increase the indentation
219
+ # @see #tab_down
220
+ def tab_up(i = 1)
221
+ haml_buffer.tabulation += i
222
+ end
223
+
224
+ # Decrements the number of tabs the buffer automatically adds
225
+ # to the lines of the template.
226
+ #
227
+ # @param i [Fixnum] The number of tabs by which to decrease the indentation
228
+ # @see #tab_up
229
+ def tab_down(i = 1)
230
+ haml_buffer.tabulation -= i
231
+ end
232
+
233
+ # Sets the number of tabs the buffer automatically adds
234
+ # to the lines of the template,
235
+ # but only for the duration of the block.
236
+ # For example:
237
+ #
238
+ # %h1 foo
239
+ # - with_tabs(2) do
240
+ # %p bar
241
+ # %strong baz
242
+ #
243
+ # Produces:
244
+ #
245
+ # <h1>foo</h1>
246
+ # <p>bar</p>
247
+ # <strong>baz</strong>
248
+ #
249
+ #
250
+ # @param i [Fixnum] The number of tabs to use
251
+ # @yield A block in which the indentation will be `i` spaces
252
+ def with_tabs(i)
253
+ old_tabs = haml_buffer.tabulation
254
+ haml_buffer.tabulation = i
255
+ yield
256
+ ensure
257
+ haml_buffer.tabulation = old_tabs
258
+ end
259
+
260
+ # Surrounds a block of Haml code with strings,
261
+ # with no whitespace in between.
262
+ # For example:
263
+ #
264
+ # = surround '(', ')' do
265
+ # %a{:href => "food"} chicken
266
+ #
267
+ # Produces:
268
+ #
269
+ # (<a href='food'>chicken</a>)
270
+ #
271
+ # and
272
+ #
273
+ # = surround '*' do
274
+ # %strong angry
275
+ #
276
+ # Produces:
277
+ #
278
+ # *<strong>angry</strong>*
279
+ #
280
+ # @param front [String] The string to add before the Haml
281
+ # @param back [String] The string to add after the Haml
282
+ # @yield A block of Haml to surround
283
+ def surround(front, back = front, &block)
284
+ output = capture_haml(&block)
285
+
286
+ "#{front}#{output.chomp}#{back}\n"
287
+ end
288
+
289
+ # Prepends a string to the beginning of a Haml block,
290
+ # with no whitespace between.
291
+ # For example:
292
+ #
293
+ # = precede '*' do
294
+ # %span.small Not really
295
+ #
296
+ # Produces:
297
+ #
298
+ # *<span class='small'>Not really</span>
299
+ #
300
+ # @param str [String] The string to add before the Haml
301
+ # @yield A block of Haml to prepend to
302
+ def precede(str, &block)
303
+ "#{str}#{capture_haml(&block).chomp}\n"
304
+ end
305
+
306
+ # Appends a string to the end of a Haml block,
307
+ # with no whitespace between.
308
+ # For example:
309
+ #
310
+ # click
311
+ # = succeed '.' do
312
+ # %a{:href=>"thing"} here
313
+ #
314
+ # Produces:
315
+ #
316
+ # click
317
+ # <a href='thing'>here</a>.
318
+ #
319
+ # @param str [String] The string to add after the Haml
320
+ # @yield A block of Haml to append to
321
+ def succeed(str, &block)
322
+ "#{capture_haml(&block).chomp}#{str}\n"
323
+ end
324
+
325
+ # Captures the result of a block of Haml code,
326
+ # gets rid of the excess indentation,
327
+ # and returns it as a string.
328
+ # For example, after the following,
329
+ #
330
+ # .foo
331
+ # - foo = capture_haml(13) do |a|
332
+ # %p= a
333
+ #
334
+ # the local variable `foo` would be assigned to `"<p>13</p>\n"`.
335
+ #
336
+ # @param args [Array] Arguments to pass into the block
337
+ # @yield [args] A block of Haml code that will be converted to a string
338
+ # @yieldparam args [Array] `args`
339
+ def capture_haml(*args, &block)
340
+ buffer = eval('_hamlout', block.binding) rescue haml_buffer
341
+ with_haml_buffer(buffer) do
342
+ position = haml_buffer.buffer.length
343
+
344
+ haml_buffer.capture_position = position
345
+ block.call(*args)
346
+
347
+ captured = haml_buffer.buffer.slice!(position..-1)
348
+ return captured if haml_buffer.options[:ugly]
349
+ captured = captured.split(/^/)
350
+
351
+ min_tabs = nil
352
+ captured.each do |line|
353
+ tabs = line.index(/[^ ]/) || line.length
354
+ min_tabs ||= tabs
355
+ min_tabs = min_tabs > tabs ? tabs : min_tabs
356
+ end
357
+
358
+ captured.map do |line|
359
+ line[min_tabs..-1]
360
+ end.join
361
+ end
362
+ ensure
363
+ haml_buffer.capture_position = nil
364
+ end
365
+
366
+ # Outputs text directly to the Haml buffer, with the proper indentation.
367
+ #
368
+ # @param text [#to_s] The text to output
369
+ def haml_concat(text = "")
370
+ unless haml_buffer.options[:ugly] || haml_indent == 0
371
+ haml_buffer.buffer << haml_indent <<
372
+ text.to_s.gsub("\n", "\n" + haml_indent) << "\n"
373
+ else
374
+ haml_buffer.buffer << text.to_s << "\n"
375
+ end
376
+ ErrorReturn.new("haml_concat")
377
+ end
378
+
379
+ # @return [String] The indentation string for the current line
380
+ def haml_indent
381
+ ' ' * haml_buffer.tabulation
382
+ end
383
+
384
+ # Creates an HTML tag with the given name and optionally text and attributes.
385
+ # Can take a block that will run between the opening and closing tags.
386
+ # If the block is a Haml block or outputs text using \{#haml\_concat},
387
+ # the text will be properly indented.
388
+ #
389
+ # `name` can be a string using the standard Haml class/id shorthand
390
+ # (e.g. "span#foo.bar", "#foo").
391
+ # Just like standard Haml tags, these class and id values
392
+ # will be merged with manually-specified attributes.
393
+ #
394
+ # `flags` is a list of symbol flags
395
+ # like those that can be put at the end of a Haml tag
396
+ # (`:/`, `:<`, and `:>`).
397
+ # Currently, only `:/` and `:<` are supported.
398
+ #
399
+ # `haml_tag` outputs directly to the buffer;
400
+ # its return value should not be used.
401
+ # If you need to get the results as a string,
402
+ # use \{#capture\_haml\}.
403
+ #
404
+ # For example,
405
+ #
406
+ # haml_tag :table do
407
+ # haml_tag :tr do
408
+ # haml_tag 'td.cell' do
409
+ # haml_tag :strong, "strong!"
410
+ # haml_concat "data"
411
+ # end
412
+ # haml_tag :td do
413
+ # haml_concat "more_data"
414
+ # end
415
+ # end
416
+ # end
417
+ #
418
+ # outputs
419
+ #
420
+ # <table>
421
+ # <tr>
422
+ # <td class='cell'>
423
+ # <strong>
424
+ # strong!
425
+ # </strong>
426
+ # data
427
+ # </td>
428
+ # <td>
429
+ # more_data
430
+ # </td>
431
+ # </tr>
432
+ # </table>
433
+ #
434
+ # @param name [#to_s] The name of the tag
435
+ # @param flags [Array<Symbol>] Haml end-of-tag flags
436
+ #
437
+ # @overload haml_tag(name, *flags, attributes = {})
438
+ # @yield The block of Haml code within the tag
439
+ # @overload haml_tag(name, text, *flags, attributes = {})
440
+ # @param text [#to_s] The text within the tag
441
+ def haml_tag(name, *rest, &block)
442
+ ret = ErrorReturn.new("haml_tag")
443
+
444
+ text = rest.shift.to_s unless [Symbol, Hash, NilClass].any? {|t| rest.first.is_a? t}
445
+ flags = []
446
+ flags << rest.shift while rest.first.is_a? Symbol
447
+ attrs = Haml::Util.map_keys(rest.shift || {}) {|key| key.to_s}
448
+ name, attrs = merge_name_and_attributes(name.to_s, attrs)
449
+
450
+ attributes = Haml::Compiler.build_attributes(haml_buffer.html?,
451
+ haml_buffer.options[:attr_wrapper],
452
+ haml_buffer.options[:escape_attrs],
453
+ attrs)
454
+
455
+ if text.nil? && block.nil? && (haml_buffer.options[:autoclose].include?(name) || flags.include?(:/))
456
+ haml_concat "<#{name}#{attributes} />"
457
+ return ret
458
+ end
459
+
460
+ if flags.include?(:/)
461
+ raise Error.new("Self-closing tags can't have content.") if text
462
+ raise Error.new("Illegal nesting: nesting within a self-closing tag is illegal.") if block
463
+ end
464
+
465
+ tag = "<#{name}#{attributes}>"
466
+ if block.nil?
467
+ text = text.to_s
468
+ if text.include?("\n")
469
+ haml_concat tag
470
+ tab_up
471
+ haml_concat text
472
+ tab_down
473
+ haml_concat "</#{name}>"
474
+ else
475
+ tag << text << "</#{name}>"
476
+ haml_concat tag
477
+ end
478
+ return ret
479
+ end
480
+
481
+ if text
482
+ raise Error.new("Illegal nesting: content can't be both given to haml_tag :#{name} and nested within it.")
483
+ end
484
+
485
+ if flags.include?(:<)
486
+ tag << capture_haml(&block).strip << "</#{name}>"
487
+ haml_concat tag
488
+ return ret
489
+ end
490
+
491
+ haml_concat tag
492
+ tab_up
493
+ block.call
494
+ tab_down
495
+ haml_concat "</#{name}>"
496
+
497
+ ret
498
+ end
499
+
500
+ # Characters that need to be escaped to HTML entities from user input
501
+ HTML_ESCAPE = { '&'=>'&amp;', '<'=>'&lt;', '>'=>'&gt;', '"'=>'&quot;', "'"=>'&#039;', }
502
+
503
+ # Returns a copy of `text` with ampersands, angle brackets and quotes
504
+ # escaped into HTML entities.
505
+ #
506
+ # Note that if ActionView is loaded and XSS protection is enabled
507
+ # (as is the default for Rails 3.0+, and optional for version 2.3.5+),
508
+ # this won't escape text declared as "safe".
509
+ #
510
+ # @param text [String] The string to sanitize
511
+ # @return [String] The sanitized string
512
+ def html_escape(text)
513
+ Haml::Util.silence_warnings {text.to_s.gsub(/[\"><&]/n) {|s| HTML_ESCAPE[s]}}
514
+ end
515
+
516
+ # Escapes HTML entities in `text`, but without escaping an ampersand
517
+ # that is already part of an escaped entity.
518
+ #
519
+ # @param text [String] The string to sanitize
520
+ # @return [String] The sanitized string
521
+ def escape_once(text)
522
+ Haml::Util.silence_warnings do
523
+ text.to_s.gsub(/[\"><]|&(?!(?:[a-zA-Z]+|(#\d+));)/n) {|s| HTML_ESCAPE[s]}
524
+ end
525
+ end
526
+
527
+ # Returns whether or not the current template is a Haml template.
528
+ #
529
+ # This function, unlike other {Haml::Helpers} functions,
530
+ # also works in other `ActionView` templates,
531
+ # where it will always return false.
532
+ #
533
+ # @return [Boolean] Whether or not the current template is a Haml template
534
+ def is_haml?
535
+ !@haml_buffer.nil? && @haml_buffer.active?
536
+ end
537
+
538
+ # Returns whether or not `block` is defined directly in a Haml template.
539
+ #
540
+ # @param block [Proc] A Ruby block
541
+ # @return [Boolean] Whether or not `block` is defined directly in a Haml template
542
+ def block_is_haml?(block)
543
+ eval('_hamlout', block.binding)
544
+ true
545
+ rescue
546
+ false
547
+ end
548
+
549
+ private
550
+
551
+ # Parses the tag name used for \{#haml\_tag}
552
+ # and merges it with the Ruby attributes hash.
553
+ def merge_name_and_attributes(name, attributes_hash = {})
554
+ # skip merging if no ids or classes found in name
555
+ return name, attributes_hash unless name =~ /^(.+?)?([\.#].*)$/
556
+
557
+ return $1 || "div", Buffer.merge_attrs(
558
+ Haml::Parser.parse_class_and_id($2), attributes_hash)
559
+ end
560
+
561
+ # Runs a block of code with the given buffer as the currently active buffer.
562
+ #
563
+ # @param buffer [Haml::Buffer] The Haml buffer to use temporarily
564
+ # @yield A block in which the given buffer should be used
565
+ def with_haml_buffer(buffer)
566
+ @haml_buffer, old_buffer = buffer, @haml_buffer
567
+ old_buffer.active, old_was_active = false, old_buffer.active? if old_buffer
568
+ @haml_buffer.active, was_active = true, @haml_buffer.active?
569
+ yield
570
+ ensure
571
+ @haml_buffer.active = was_active
572
+ old_buffer.active = old_was_active if old_buffer
573
+ @haml_buffer = old_buffer
574
+ end
575
+
576
+ # The current {Haml::Buffer} object.
577
+ #
578
+ # @return [Haml::Buffer]
579
+ def haml_buffer
580
+ @haml_buffer
581
+ end
582
+
583
+ # Gives a proc the same local `_hamlout` and `_erbout` variables
584
+ # that the current template has.
585
+ #
586
+ # @param proc [#call] The proc to bind
587
+ # @return [Proc] A new proc with the new variables bound
588
+ def haml_bind_proc(&proc)
589
+ _hamlout = haml_buffer
590
+ _erbout = _hamlout.buffer
591
+ proc { |*args| proc.call(*args) }
592
+ end
593
+ end
594
+ end
595
+
596
+ # @private
597
+ class Object
598
+ # Haml overrides various `ActionView` helpers,
599
+ # which call an \{#is\_haml?} method
600
+ # to determine whether or not the current context object
601
+ # is a proper Haml context.
602
+ # Because `ActionView` helpers may be included in non-`ActionView::Base` classes,
603
+ # it's a good idea to define \{#is\_haml?} for all objects.
604
+ def is_haml?
605
+ false
606
+ end
607
+ end
608
+