haml 3.0.25 → 3.1.0.alpha.2

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 (212) hide show
  1. data/.yardopts +1 -1
  2. data/CONTRIBUTING +0 -1
  3. data/EDGE_GEM_VERSION +1 -0
  4. data/MIT-LICENSE +1 -1
  5. data/README.md +10 -175
  6. data/Rakefile +56 -84
  7. data/VERSION +1 -1
  8. data/VERSION_NAME +1 -1
  9. data/init.rb +1 -1
  10. data/lib/haml.rb +14 -12
  11. data/lib/haml/engine.rb +1 -1
  12. data/lib/haml/exec.rb +19 -316
  13. data/lib/haml/helpers/action_view_extensions.rb +1 -1
  14. data/lib/haml/html.rb +69 -76
  15. data/lib/haml/precompiler.rb +34 -41
  16. data/lib/haml/railtie.rb +4 -6
  17. data/lib/haml/template/plugin.rb +6 -16
  18. data/lib/haml/util.rb +91 -107
  19. data/lib/haml/version.rb +7 -0
  20. data/test/benchmark.rb +2 -9
  21. data/test/haml/engine_test.rb +195 -92
  22. data/test/haml/html2haml/erb_tests.rb +0 -14
  23. data/test/haml/util_test.rb +32 -0
  24. data/test/test_helper.rb +0 -39
  25. metadata +96 -324
  26. data/bin/css2sass +0 -13
  27. data/bin/sass +0 -8
  28. data/bin/sass-convert +0 -7
  29. data/extra/haml-mode.el +0 -753
  30. data/extra/sass-mode.el +0 -207
  31. data/lib/haml/util/subset_map.rb +0 -101
  32. data/lib/sass.rb +0 -29
  33. data/lib/sass/callbacks.rb +0 -52
  34. data/lib/sass/css.rb +0 -294
  35. data/lib/sass/engine.rb +0 -720
  36. data/lib/sass/environment.rb +0 -143
  37. data/lib/sass/error.rb +0 -198
  38. data/lib/sass/files.rb +0 -160
  39. data/lib/sass/less.rb +0 -382
  40. data/lib/sass/plugin.rb +0 -279
  41. data/lib/sass/plugin/configuration.rb +0 -221
  42. data/lib/sass/plugin/generic.rb +0 -15
  43. data/lib/sass/plugin/merb.rb +0 -37
  44. data/lib/sass/plugin/rack.rb +0 -47
  45. data/lib/sass/plugin/rails.rb +0 -32
  46. data/lib/sass/plugin/staleness_checker.rb +0 -123
  47. data/lib/sass/repl.rb +0 -58
  48. data/lib/sass/script.rb +0 -63
  49. data/lib/sass/script/bool.rb +0 -18
  50. data/lib/sass/script/color.rb +0 -491
  51. data/lib/sass/script/css_lexer.rb +0 -29
  52. data/lib/sass/script/css_parser.rb +0 -31
  53. data/lib/sass/script/funcall.rb +0 -77
  54. data/lib/sass/script/functions.rb +0 -861
  55. data/lib/sass/script/interpolation.rb +0 -70
  56. data/lib/sass/script/lexer.rb +0 -337
  57. data/lib/sass/script/literal.rb +0 -236
  58. data/lib/sass/script/node.rb +0 -112
  59. data/lib/sass/script/number.rb +0 -423
  60. data/lib/sass/script/operation.rb +0 -95
  61. data/lib/sass/script/parser.rb +0 -401
  62. data/lib/sass/script/string.rb +0 -67
  63. data/lib/sass/script/string_interpolation.rb +0 -93
  64. data/lib/sass/script/unary_operation.rb +0 -57
  65. data/lib/sass/script/variable.rb +0 -48
  66. data/lib/sass/scss.rb +0 -17
  67. data/lib/sass/scss/css_parser.rb +0 -46
  68. data/lib/sass/scss/parser.rb +0 -855
  69. data/lib/sass/scss/rx.rb +0 -126
  70. data/lib/sass/scss/sass_parser.rb +0 -11
  71. data/lib/sass/scss/script_lexer.rb +0 -15
  72. data/lib/sass/scss/script_parser.rb +0 -25
  73. data/lib/sass/scss/static_parser.rb +0 -40
  74. data/lib/sass/selector.rb +0 -361
  75. data/lib/sass/selector/abstract_sequence.rb +0 -62
  76. data/lib/sass/selector/comma_sequence.rb +0 -82
  77. data/lib/sass/selector/sequence.rb +0 -237
  78. data/lib/sass/selector/simple.rb +0 -113
  79. data/lib/sass/selector/simple_sequence.rb +0 -136
  80. data/lib/sass/tree/charset_node.rb +0 -37
  81. data/lib/sass/tree/comment_node.rb +0 -128
  82. data/lib/sass/tree/debug_node.rb +0 -36
  83. data/lib/sass/tree/directive_node.rb +0 -75
  84. data/lib/sass/tree/extend_node.rb +0 -65
  85. data/lib/sass/tree/for_node.rb +0 -55
  86. data/lib/sass/tree/if_node.rb +0 -69
  87. data/lib/sass/tree/import_node.rb +0 -102
  88. data/lib/sass/tree/mixin_def_node.rb +0 -48
  89. data/lib/sass/tree/mixin_node.rb +0 -111
  90. data/lib/sass/tree/node.rb +0 -464
  91. data/lib/sass/tree/prop_node.rb +0 -220
  92. data/lib/sass/tree/root_node.rb +0 -163
  93. data/lib/sass/tree/rule_node.rb +0 -261
  94. data/lib/sass/tree/variable_node.rb +0 -39
  95. data/lib/sass/tree/warn_node.rb +0 -42
  96. data/lib/sass/tree/while_node.rb +0 -36
  97. data/test/haml/util/subset_map_test.rb +0 -91
  98. data/test/sass/callbacks_test.rb +0 -61
  99. data/test/sass/conversion_test.rb +0 -1218
  100. data/test/sass/css2sass_test.rb +0 -364
  101. data/test/sass/data/hsl-rgb.txt +0 -319
  102. data/test/sass/engine_test.rb +0 -2267
  103. data/test/sass/extend_test.rb +0 -1348
  104. data/test/sass/functions_test.rb +0 -556
  105. data/test/sass/less_conversion_test.rb +0 -653
  106. data/test/sass/more_results/more1.css +0 -9
  107. data/test/sass/more_results/more1_with_line_comments.css +0 -26
  108. data/test/sass/more_results/more_import.css +0 -29
  109. data/test/sass/more_templates/_more_partial.sass +0 -2
  110. data/test/sass/more_templates/more1.sass +0 -23
  111. data/test/sass/more_templates/more_import.sass +0 -11
  112. data/test/sass/plugin_test.rb +0 -433
  113. data/test/sass/results/alt.css +0 -4
  114. data/test/sass/results/basic.css +0 -9
  115. data/test/sass/results/compact.css +0 -5
  116. data/test/sass/results/complex.css +0 -86
  117. data/test/sass/results/compressed.css +0 -1
  118. data/test/sass/results/expanded.css +0 -19
  119. data/test/sass/results/import.css +0 -31
  120. data/test/sass/results/import_charset.css +0 -4
  121. data/test/sass/results/import_charset_1_8.css +0 -4
  122. data/test/sass/results/import_charset_ibm866.css +0 -4
  123. data/test/sass/results/line_numbers.css +0 -49
  124. data/test/sass/results/mixins.css +0 -95
  125. data/test/sass/results/multiline.css +0 -24
  126. data/test/sass/results/nested.css +0 -22
  127. data/test/sass/results/options.css +0 -1
  128. data/test/sass/results/parent_ref.css +0 -13
  129. data/test/sass/results/script.css +0 -16
  130. data/test/sass/results/scss_import.css +0 -31
  131. data/test/sass/results/scss_importee.css +0 -2
  132. data/test/sass/results/subdir/nested_subdir/nested_subdir.css +0 -1
  133. data/test/sass/results/subdir/subdir.css +0 -3
  134. data/test/sass/results/units.css +0 -11
  135. data/test/sass/results/warn.css +0 -0
  136. data/test/sass/results/warn_imported.css +0 -0
  137. data/test/sass/script_conversion_test.rb +0 -314
  138. data/test/sass/script_test.rb +0 -470
  139. data/test/sass/scss/css_test.rb +0 -916
  140. data/test/sass/scss/rx_test.rb +0 -156
  141. data/test/sass/scss/scss_test.rb +0 -1122
  142. data/test/sass/scss/test_helper.rb +0 -37
  143. data/test/sass/templates/_imported_charset_ibm866.sass +0 -4
  144. data/test/sass/templates/_imported_charset_utf8.sass +0 -4
  145. data/test/sass/templates/_partial.sass +0 -2
  146. data/test/sass/templates/alt.sass +0 -16
  147. data/test/sass/templates/basic.sass +0 -23
  148. data/test/sass/templates/bork1.sass +0 -2
  149. data/test/sass/templates/bork2.sass +0 -2
  150. data/test/sass/templates/bork3.sass +0 -2
  151. data/test/sass/templates/bork4.sass +0 -2
  152. data/test/sass/templates/compact.sass +0 -17
  153. data/test/sass/templates/complex.sass +0 -305
  154. data/test/sass/templates/compressed.sass +0 -15
  155. data/test/sass/templates/expanded.sass +0 -17
  156. data/test/sass/templates/import.sass +0 -12
  157. data/test/sass/templates/import_charset.sass +0 -7
  158. data/test/sass/templates/import_charset_1_8.sass +0 -4
  159. data/test/sass/templates/import_charset_ibm866.sass +0 -9
  160. data/test/sass/templates/importee.less +0 -2
  161. data/test/sass/templates/importee.sass +0 -19
  162. data/test/sass/templates/line_numbers.sass +0 -13
  163. data/test/sass/templates/mixin_bork.sass +0 -5
  164. data/test/sass/templates/mixins.sass +0 -76
  165. data/test/sass/templates/multiline.sass +0 -20
  166. data/test/sass/templates/nested.sass +0 -25
  167. data/test/sass/templates/nested_bork1.sass +0 -2
  168. data/test/sass/templates/nested_bork2.sass +0 -2
  169. data/test/sass/templates/nested_bork3.sass +0 -2
  170. data/test/sass/templates/nested_bork4.sass +0 -2
  171. data/test/sass/templates/nested_mixin_bork.sass +0 -6
  172. data/test/sass/templates/options.sass +0 -2
  173. data/test/sass/templates/parent_ref.sass +0 -25
  174. data/test/sass/templates/script.sass +0 -101
  175. data/test/sass/templates/scss_import.scss +0 -11
  176. data/test/sass/templates/scss_importee.scss +0 -1
  177. data/test/sass/templates/subdir/nested_subdir/_nested_partial.sass +0 -2
  178. data/test/sass/templates/subdir/nested_subdir/nested_subdir.sass +0 -3
  179. data/test/sass/templates/subdir/subdir.sass +0 -6
  180. data/test/sass/templates/units.sass +0 -11
  181. data/test/sass/templates/warn.sass +0 -3
  182. data/test/sass/templates/warn_imported.sass +0 -4
  183. data/vendor/fssm/LICENSE +0 -20
  184. data/vendor/fssm/README.markdown +0 -55
  185. data/vendor/fssm/Rakefile +0 -59
  186. data/vendor/fssm/VERSION.yml +0 -5
  187. data/vendor/fssm/example.rb +0 -9
  188. data/vendor/fssm/fssm.gemspec +0 -77
  189. data/vendor/fssm/lib/fssm.rb +0 -33
  190. data/vendor/fssm/lib/fssm/backends/fsevents.rb +0 -36
  191. data/vendor/fssm/lib/fssm/backends/inotify.rb +0 -26
  192. data/vendor/fssm/lib/fssm/backends/polling.rb +0 -25
  193. data/vendor/fssm/lib/fssm/backends/rubycocoa/fsevents.rb +0 -131
  194. data/vendor/fssm/lib/fssm/monitor.rb +0 -26
  195. data/vendor/fssm/lib/fssm/path.rb +0 -91
  196. data/vendor/fssm/lib/fssm/pathname.rb +0 -502
  197. data/vendor/fssm/lib/fssm/state/directory.rb +0 -57
  198. data/vendor/fssm/lib/fssm/state/file.rb +0 -24
  199. data/vendor/fssm/lib/fssm/support.rb +0 -63
  200. data/vendor/fssm/lib/fssm/tree.rb +0 -176
  201. data/vendor/fssm/profile/prof-cache.rb +0 -40
  202. data/vendor/fssm/profile/prof-fssm-pathname.html +0 -1231
  203. data/vendor/fssm/profile/prof-pathname.rb +0 -68
  204. data/vendor/fssm/profile/prof-plain-pathname.html +0 -988
  205. data/vendor/fssm/profile/prof.html +0 -2379
  206. data/vendor/fssm/spec/path_spec.rb +0 -75
  207. data/vendor/fssm/spec/root/duck/quack.txt +0 -0
  208. data/vendor/fssm/spec/root/file.css +0 -0
  209. data/vendor/fssm/spec/root/file.rb +0 -0
  210. data/vendor/fssm/spec/root/file.yml +0 -0
  211. data/vendor/fssm/spec/root/moo/cow.txt +0 -0
  212. data/vendor/fssm/spec/spec_helper.rb +0 -14
@@ -99,4 +99,11 @@ module Haml
99
99
  return nil
100
100
  end
101
101
  end
102
+
103
+ extend Haml::Version
104
+
105
+ # A string representing the version of Haml.
106
+ # A more fine-grained representation is available from Haml.version.
107
+ # @api public
108
+ VERSION = version[:string] unless defined?(Haml::VERSION)
102
109
  end
@@ -5,15 +5,14 @@ times = (ARGV.first || 1000).to_i
5
5
  if times == 0 # Invalid parameter
6
6
  puts <<END
7
7
  ruby #$0 [times=1000]
8
- Benchmark Haml against various other templating languages and Sass
9
- on its own.
8
+ Benchmark Haml against various other templating languages.
10
9
  END
11
10
  exit 1
12
11
  end
13
12
 
14
13
  require File.dirname(__FILE__) + '/../lib/haml'
15
14
  require File.dirname(__FILE__) + '/linked_rails'
16
- %w[sass rubygems erb erubis markaby active_support action_controller
15
+ %w[rubygems erb erubis markaby active_support action_controller
17
16
  action_view action_pack haml/template rbench].each {|dep| require(dep)}
18
17
 
19
18
  def view
@@ -91,9 +90,3 @@ RBench.run(times) do
91
90
  haml_ugly { render @base, 'haml/templates/action_view_ugly' }
92
91
  end
93
92
  end
94
-
95
- RBench.run(times) do
96
- sass_template = File.read("#{File.dirname(__FILE__)}/sass/templates/complex.sass")
97
-
98
- report("Sass") { Sass::Engine.new(sass_template).render }
99
- end
@@ -86,7 +86,6 @@ MESSAGE
86
86
  "foo\n:plain\n 1\n 2\n 3\#{''}\n4\n- raise 'foo'" => ["foo", 7],
87
87
  "foo\n:plain\n 1\n 2\n \#{raise 'foo'}" => ["foo", 5],
88
88
  "= raise 'foo'\nfoo\nbar\nbaz\nbang" => ["foo", 1],
89
- "- case 1\n\n- when 1\n - raise 'foo'" => ["foo", 4],
90
89
  }
91
90
 
92
91
  User = Struct.new('User', :id)
@@ -112,17 +111,6 @@ MESSAGE
112
111
  Haml::Engine.new(text, options)
113
112
  end
114
113
 
115
- def setup
116
- return if Haml::Util.ruby1_8?
117
- @old_default_internal = Encoding.default_internal
118
- Encoding.default_internal = nil
119
- end
120
-
121
- def teardown
122
- return if Haml::Util.ruby1_8?
123
- Encoding.default_internal = @old_default_internal
124
- end
125
-
126
114
  def test_empty_render
127
115
  assert_equal "", render("")
128
116
  end
@@ -775,38 +763,6 @@ HTML
775
763
  HAML
776
764
  end
777
765
 
778
- def test_case_with_newline_after_case
779
- assert_equal(<<HTML, render(<<HAML))
780
- foo
781
- HTML
782
- - case 1
783
-
784
- - when 1
785
- foo
786
- - when 2
787
- bar
788
- HAML
789
-
790
- assert_equal(<<HTML, render(<<HAML))
791
- bar
792
- HTML
793
- - case 2
794
-
795
- - when 1
796
- foo
797
- - when 2
798
- bar
799
- HAML
800
- end
801
-
802
- def test_escape_html_with_interpolated_if_statement
803
- assert_equal(<<HTML, render(<<HAML, :escape_html => true))
804
- foo,
805
- HTML
806
- foo\#{"," if true}
807
- HAML
808
- end
809
-
810
766
  # HTML escaping tests
811
767
 
812
768
  def test_ampersand_equals_should_escape
@@ -1145,18 +1101,18 @@ END
1145
1101
  end
1146
1102
 
1147
1103
  def test_css_filter
1148
- assert_equal(<<CSS, render(<<SASS))
1104
+ assert_equal(<<HTML, render(<<HAML))
1149
1105
  <style type='text/css'>
1150
1106
  /*<![CDATA[*/
1151
1107
  #foo {
1152
1108
  bar: baz; }
1153
1109
  /*]]>*/
1154
1110
  </style>
1155
- CSS
1111
+ HTML
1156
1112
  :css
1157
1113
  #foo {
1158
1114
  bar: baz; }
1159
- SASS
1115
+ HAML
1160
1116
  end
1161
1117
 
1162
1118
  def test_local_assigns_dont_modify_class
@@ -1389,7 +1345,7 @@ SASS
1389
1345
 
1390
1346
  def test_new_attribute_ids
1391
1347
  assert_equal("<div id='foo_bar'></div>\n", render("#foo(id='bar')"))
1392
- assert_equal("<div id='foo_baz_bar'></div>\n", render("#foo{:id => 'bar'}(id='baz')"))
1348
+ assert_equal("<div id='foo_bar_baz'></div>\n", render("#foo{:id => 'bar'}(id='baz')"))
1393
1349
  assert_equal("<div id='foo_baz_bar'></div>\n", render("#foo(id='baz'){:id => 'bar'}"))
1394
1350
  foo = User.new(42)
1395
1351
  assert_equal("<div class='struct_user' id='foo_baz_bar_struct_user_42'></div>\n",
@@ -1398,7 +1354,7 @@ SASS
1398
1354
  render("#foo(id='baz')[foo]{:id => 'bar'}", :locals => {:foo => foo}))
1399
1355
  assert_equal("<div class='struct_user' id='foo_baz_bar_struct_user_42'></div>\n",
1400
1356
  render("#foo[foo](id='baz'){:id => 'bar'}", :locals => {:foo => foo}))
1401
- assert_equal("<div class='struct_user' id='foo_baz_bar_struct_user_42'></div>\n",
1357
+ assert_equal("<div class='struct_user' id='foo_bar_baz_struct_user_42'></div>\n",
1402
1358
  render("#foo[foo]{:id => 'bar'}(id='baz')", :locals => {:foo => foo}))
1403
1359
  end
1404
1360
 
@@ -1470,17 +1426,11 @@ SASS
1470
1426
  assert_equal("<a a='b' c='d'>bar</a>\n", render("%a(c='d'){:a => 'b'} bar"))
1471
1427
  assert_equal("<a a='b' c='d'>bar</a>\n", render("%a{:a => 'b'}(c='d') bar"))
1472
1428
 
1473
- # Old-style always takes precedence over new-style,
1474
- # because theoretically old-style could have arbitrary end-of-method-call syntax.
1475
- assert_equal("<a a='b'>bar</a>\n", render("%a{:a => 'b'}(a='d') bar"))
1429
+ assert_equal("<a a='d'>bar</a>\n", render("%a{:a => 'b'}(a='d') bar"))
1476
1430
  assert_equal("<a a='b'>bar</a>\n", render("%a(a='d'){:a => 'b'} bar"))
1477
1431
 
1478
1432
  assert_equal("<a a='b' b='c' c='d' d='e'>bar</a>\n",
1479
1433
  render("%a{:a => 'b',\n:b => 'c'}(c='d'\nd='e') bar"))
1480
-
1481
- locals = {:b => 'b', :d => 'd'}
1482
- assert_equal("<p a='b' c='d'></p>\n", render("%p{:a => b}(c=d)", :locals => locals))
1483
- assert_equal("<p a='b' c='d'></p>\n", render("%p(a=b){:c => d}", :locals => locals))
1484
1434
  end
1485
1435
 
1486
1436
  # Ruby Multiline
@@ -1556,7 +1506,7 @@ HAML
1556
1506
 
1557
1507
  def test_loud_ruby_multiline_with_block
1558
1508
  assert_equal(<<HTML, render(<<HAML))
1559
- #{%w[far faz fang]}
1509
+ farfazfang
1560
1510
  <p>foo</p>
1561
1511
  <p>bar</p>
1562
1512
  HTML
@@ -1686,8 +1636,18 @@ HAML
1686
1636
  HAML
1687
1637
  end
1688
1638
 
1639
+ def test_convert_template_render
1640
+ assert_equal(<<HTML, render(<<HAML.encode("iso-8859-1"), :encoding => "utf-8"))
1641
+ <p>bâr</p>
1642
+ <p>föö</p>
1643
+ HTML
1644
+ %p bâr
1645
+ %p föö
1646
+ HAML
1647
+ end
1648
+
1689
1649
  def test_fake_ascii_encoding
1690
- assert_encoded_equal(<<HTML.force_encoding("ascii-8bit"), render(<<HAML, :encoding => "ascii-8bit"))
1650
+ assert_equal(<<HTML.force_encoding("ascii-8bit"), render(<<HAML, :encoding => "ascii-8bit"))
1691
1651
  <p>bâr</p>
1692
1652
  <p>föö</p>
1693
1653
  HTML
@@ -1741,23 +1701,15 @@ HTML
1741
1701
  HAML
1742
1702
  end
1743
1703
 
1744
- def test_coding_comments
1745
- assert_valid_encoding_comment("-# coding: ibm866")
1746
- assert_valid_encoding_comment("-# CodINg: IbM866")
1747
- assert_valid_encoding_comment("-#coding:ibm866")
1748
- assert_valid_encoding_comment("-# CodINg= ibm866")
1749
- assert_valid_encoding_comment("-# foo BAR FAOJcoding: ibm866")
1750
- assert_valid_encoding_comment("-# coding: ibm866 ASFJ (&(&#!$")
1751
- assert_valid_encoding_comment("-# -*- coding: ibm866")
1752
- assert_valid_encoding_comment("-# coding: ibm866 -*- coding: blah")
1753
- assert_valid_encoding_comment("-# -*- coding: ibm866 -*-")
1754
- assert_valid_encoding_comment("-# -*- encoding: ibm866 -*-")
1755
- assert_valid_encoding_comment('-# -*- coding: "ibm866" -*-')
1756
- assert_valid_encoding_comment("-#-*-coding:ibm866-*-")
1757
- assert_valid_encoding_comment("-#-*-coding:ibm866-*-")
1758
- assert_valid_encoding_comment("-# -*- foo: bar; coding: ibm866; baz: bang -*-")
1759
- assert_valid_encoding_comment("-# foo bar coding: baz -*- coding: ibm866 -*-")
1760
- assert_valid_encoding_comment("-# -*- coding: ibm866 -*- foo bar coding: baz")
1704
+ def test_different_coding_comment_than_encoding
1705
+ assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1706
+ <p>bâr</p>
1707
+ <p>föö</p>
1708
+ HTML
1709
+ -# coding: ibm866
1710
+ %p bâr
1711
+ %p föö
1712
+ HAML
1761
1713
  end
1762
1714
 
1763
1715
  def test_different_coding_than_system
@@ -1767,27 +1719,182 @@ HTML
1767
1719
  %p тАЬ
1768
1720
  HAML
1769
1721
  end
1770
- end
1771
1722
 
1772
- private
1723
+ def test_case_insensitive_coding_comment
1724
+ assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1725
+ <p>bâr</p>
1726
+ <p>föö</p>
1727
+ HTML
1728
+ -# CodINg: IbM866
1729
+ %p bâr
1730
+ %p föö
1731
+ HAML
1732
+ end
1773
1733
 
1774
- def assert_valid_encoding_comment(comment)
1775
- assert_renders_encoded(<<HTML.encode("IBM866"), <<HAML.encode("IBM866").force_encoding("UTF-8"))
1776
- <p>ЖЛЫ</p>
1777
- <p>тАЬ</p>
1734
+ def test_whitespace_insensitive_coding_comment
1735
+ assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1736
+ <p>bâr</p>
1737
+ <p>föö</p>
1778
1738
  HTML
1779
- #{comment}
1780
- %p ЖЛЫ
1781
- %p тАЬ
1739
+ -#coding:ibm866
1740
+ %p bâr
1741
+ %p föö
1742
+ HAML
1743
+ end
1744
+
1745
+ def test_equals_coding_comment
1746
+ assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1747
+ <p>bâr</p>
1748
+ <p>föö</p>
1749
+ HTML
1750
+ -# CodINg= ibm866
1751
+ %p bâr
1752
+ %p föö
1753
+ HAML
1754
+ end
1755
+
1756
+ def test_prefixed_coding_comment
1757
+ assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1758
+ <p>bâr</p>
1759
+ <p>föö</p>
1760
+ HTML
1761
+ -# foo BAR FAOJcoding: ibm866
1762
+ %p bâr
1763
+ %p föö
1764
+ HAML
1765
+ end
1766
+
1767
+ def test_suffixed_coding_comment
1768
+ assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1769
+ <p>bâr</p>
1770
+ <p>föö</p>
1771
+ HTML
1772
+ -# coding: ibm866 ASFJ (&(&#!$
1773
+ %p bâr
1774
+ %p föö
1782
1775
  HAML
1776
+ end
1777
+
1778
+ def test_emacs_prefixed_coding_comment
1779
+ assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1780
+ <p>bâr</p>
1781
+ <p>föö</p>
1782
+ HTML
1783
+ -# -*- coding: ibm866
1784
+ %p bâr
1785
+ %p föö
1786
+ HAML
1787
+ end
1788
+
1789
+ def test_emacs_suffixed_coding_comment
1790
+ assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1791
+ <p>bâr</p>
1792
+ <p>föö</p>
1793
+ HTML
1794
+ -# coding: ibm866 -*- coding: blah
1795
+ %p bâr
1796
+ %p föö
1797
+ HAML
1798
+ end
1799
+
1800
+ def test_emacs_coding_comment
1801
+ assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1802
+ <p>bâr</p>
1803
+ <p>föö</p>
1804
+ HTML
1805
+ -# -*- coding: ibm866 -*-
1806
+ %p bâr
1807
+ %p föö
1808
+ HAML
1809
+ end
1810
+
1811
+ def test_emacs_encoding_comment
1812
+ assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1813
+ <p>bâr</p>
1814
+ <p>föö</p>
1815
+ HTML
1816
+ -# -*- encoding: ibm866 -*-
1817
+ %p bâr
1818
+ %p föö
1819
+ HAML
1820
+ end
1821
+
1822
+ def test_quoted_emacs_coding_comment
1823
+ assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1824
+ <p>bâr</p>
1825
+ <p>föö</p>
1826
+ HTML
1827
+ -# -*- coding: "ibm866" -*-
1828
+ %p bâr
1829
+ %p föö
1830
+ HAML
1831
+ end
1832
+
1833
+ def test_whitespace_insensitive_emacs_coding_comment
1834
+ assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1835
+ <p>bâr</p>
1836
+ <p>föö</p>
1837
+ HTML
1838
+ -#-*-coding:ibm866-*-
1839
+ %p bâr
1840
+ %p föö
1841
+ HAML
1842
+ end
1843
+
1844
+ def test_whitespace_insensitive_emacs_coding_comment
1845
+ assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1846
+ <p>bâr</p>
1847
+ <p>föö</p>
1848
+ HTML
1849
+ -#-*-coding:ibm866-*-
1850
+ %p bâr
1851
+ %p föö
1852
+ HAML
1853
+ end
1854
+
1855
+ def test_one_of_several_emacs_comments
1856
+ assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1857
+ <p>bâr</p>
1858
+ <p>föö</p>
1859
+ HTML
1860
+ -# -*- foo: bar; coding: ibm866; baz: bang -*-
1861
+ %p bâr
1862
+ %p föö
1863
+ HAML
1864
+ end
1865
+
1866
+ def test_prefixed_emacs_coding_comment
1867
+ assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1868
+ <p>bâr</p>
1869
+ <p>föö</p>
1870
+ HTML
1871
+ -# foo bar coding: baz -*- coding: ibm866 -*-
1872
+ %p bâr
1873
+ %p föö
1874
+ HAML
1875
+ end
1876
+
1877
+ def test_suffixed_emacs_coding_comment
1878
+ assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1879
+ <p>bâr</p>
1880
+ <p>föö</p>
1881
+ HTML
1882
+ -# -*- coding: ibm866 -*- foo bar coding: baz
1883
+ %p bâr
1884
+ %p föö
1885
+ HAML
1886
+ end
1887
+
1783
1888
  end
1784
1889
 
1890
+ private
1891
+
1785
1892
  def assert_converts_template_properly
1786
- engine = Haml::Engine.new(<<HAML.encode("iso-8859-1"), :encoding => "macRoman")
1893
+ engine = Haml::Engine.new(<<HAML.encode("iso-8859-1"), :encoding => "utf-8")
1787
1894
  %p bâr
1788
1895
  %p föö
1789
1896
  HAML
1790
- assert_encoded_equal(<<HTML.encode("macRoman"), yield(engine))
1897
+ assert_equal(<<HTML, yield(engine))
1791
1898
  <p>bâr</p>
1792
1899
  <p>föö</p>
1793
1900
  HTML
@@ -1795,11 +1902,7 @@ HTML
1795
1902
 
1796
1903
  def assert_renders_encoded(html, haml)
1797
1904
  result = render(haml)
1798
- assert_encoded_equal html, result
1799
- end
1800
-
1801
- def assert_encoded_equal(expected, actual)
1802
- assert_equal expected.encoding, actual.encoding
1803
- assert_equal expected, actual
1905
+ assert_equal html.encoding, result.encoding
1906
+ assert_equal html, result
1804
1907
  end
1805
1908
  end
@@ -421,20 +421,6 @@ HAML
421
421
  <tr></tr>
422
422
  <% end %>
423
423
  </table>
424
- ERB
425
- end
426
-
427
- def test_silent_inside_block_inside_tag
428
- assert_equal(<<HAML.rstrip, render_erb(<<ERB))
429
- %table
430
- - foo.each do
431
- - haml_puts "foo"
432
- HAML
433
- <table>
434
- <% foo.each do %>
435
- <% haml_puts "foo" %>
436
- <% end %>
437
- </table>
438
424
  ERB
439
425
  end
440
426
  end
@@ -5,6 +5,19 @@ require 'pathname'
5
5
  class UtilTest < Test::Unit::TestCase
6
6
  include Haml::Util
7
7
 
8
+ class Dumpable
9
+ attr_reader :arr
10
+ def initialize; @arr = []; end
11
+ def _before_dump; @arr << :before; end
12
+ def _after_dump; @arr << :after; end
13
+ def _around_dump
14
+ @arr << :around_before
15
+ yield
16
+ @arr << :around_after
17
+ end
18
+ def _after_load; @arr << :loaded; end
19
+ end
20
+
8
21
  def test_scope
9
22
  assert(File.exist?(scope("Rakefile")))
10
23
  end
@@ -240,6 +253,25 @@ class UtilTest < Test::Unit::TestCase
240
253
  assert(!version_gt(v2, v1), "Expected #{v2} = #{v1}")
241
254
  end
242
255
 
256
+ def test_dump_and_load
257
+ obj = Dumpable.new
258
+ data = dump(obj)
259
+ assert_equal([:before, :around_before, :around_after, :after], obj.arr)
260
+ obj2 = load(data)
261
+ assert_equal([:before, :around_before, :loaded], obj2.arr)
262
+ end
263
+
264
+ class FooBar
265
+ def foo
266
+ Haml::Util.abstract(self)
267
+ end
268
+ end
269
+
270
+ def test_abstract
271
+ assert_raise_message(NotImplementedError,
272
+ "UtilTest::FooBar must implement #foo") {FooBar.new.foo}
273
+ end
274
+
243
275
  def test_def_static_method
244
276
  klass = Class.new
245
277
  def_static_method(klass, :static_method, [:arg1, :arg2],