haml 4.0.7 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -1
  3. data/CHANGELOG.md +42 -4
  4. data/FAQ.md +4 -14
  5. data/MIT-LICENSE +1 -1
  6. data/README.md +85 -42
  7. data/REFERENCE.md +108 -57
  8. data/Rakefile +46 -54
  9. data/lib/haml/attribute_builder.rb +163 -0
  10. data/lib/haml/attribute_compiler.rb +215 -0
  11. data/lib/haml/attribute_parser.rb +144 -0
  12. data/lib/haml/buffer.rb +22 -132
  13. data/lib/haml/compiler.rb +87 -295
  14. data/lib/haml/engine.rb +25 -41
  15. data/lib/haml/error.rb +3 -0
  16. data/lib/haml/escapable.rb +49 -0
  17. data/lib/haml/exec.rb +33 -19
  18. data/lib/haml/filters.rb +18 -24
  19. data/lib/haml/generator.rb +41 -0
  20. data/lib/haml/helpers/action_view_extensions.rb +3 -2
  21. data/lib/haml/helpers/action_view_mods.rb +36 -58
  22. data/lib/haml/helpers/action_view_xss_mods.rb +1 -0
  23. data/lib/haml/helpers/safe_erubi_template.rb +27 -0
  24. data/lib/haml/helpers/safe_erubis_template.rb +4 -1
  25. data/lib/haml/helpers/xss_mods.rb +18 -12
  26. data/lib/haml/helpers.rb +133 -90
  27. data/lib/haml/options.rb +38 -47
  28. data/lib/haml/parser.rb +278 -216
  29. data/lib/haml/{template/plugin.rb → plugin.rb} +8 -15
  30. data/lib/haml/railtie.rb +21 -12
  31. data/lib/haml/sass_rails_filter.rb +17 -4
  32. data/lib/haml/template/options.rb +12 -2
  33. data/lib/haml/template.rb +12 -6
  34. data/lib/haml/temple_engine.rb +120 -0
  35. data/lib/haml/temple_line_counter.rb +29 -0
  36. data/lib/haml/util.rb +80 -199
  37. data/lib/haml/version.rb +2 -1
  38. data/lib/haml.rb +1 -0
  39. data/test/attribute_parser_test.rb +101 -0
  40. data/test/engine_test.rb +287 -176
  41. data/test/filters_test.rb +32 -19
  42. data/test/gemfiles/Gemfile.rails-4.0.x +9 -3
  43. data/test/gemfiles/Gemfile.rails-4.0.x.lock +87 -0
  44. data/test/gemfiles/Gemfile.rails-4.1.x +5 -0
  45. data/test/gemfiles/Gemfile.rails-4.2.x +5 -0
  46. data/test/gemfiles/Gemfile.rails-5.0.x +4 -0
  47. data/test/helper_test.rb +224 -112
  48. data/test/options_test.rb +22 -0
  49. data/test/parser_test.rb +71 -4
  50. data/test/results/bemit.xhtml +4 -0
  51. data/test/results/eval_suppressed.xhtml +4 -4
  52. data/test/results/helpers.xhtml +43 -41
  53. data/test/results/helpful.xhtml +6 -3
  54. data/test/results/just_stuff.xhtml +21 -20
  55. data/test/results/list.xhtml +9 -9
  56. data/test/results/nuke_inner_whitespace.xhtml +22 -22
  57. data/test/results/nuke_outer_whitespace.xhtml +84 -92
  58. data/test/results/original_engine.xhtml +17 -17
  59. data/test/results/partial_layout.xhtml +4 -3
  60. data/test/results/partial_layout_erb.xhtml +4 -3
  61. data/test/results/partials.xhtml +11 -10
  62. data/test/results/silent_script.xhtml +63 -63
  63. data/test/results/standard.xhtml +156 -159
  64. data/test/results/tag_parsing.xhtml +19 -19
  65. data/test/results/very_basic.xhtml +2 -2
  66. data/test/results/whitespace_handling.xhtml +77 -76
  67. data/test/template_test.rb +24 -56
  68. data/test/template_test_helper.rb +38 -0
  69. data/test/templates/bemit.haml +3 -0
  70. data/test/templates/just_stuff.haml +1 -0
  71. data/test/templates/standard_ugly.haml +1 -0
  72. data/test/templates/with_bom.haml +1 -0
  73. data/test/temple_line_counter_test.rb +40 -0
  74. data/test/test_helper.rb +26 -8
  75. data/test/util_test.rb +6 -47
  76. metadata +53 -43
  77. data/test/gemfiles/Gemfile.rails-3.0.x +0 -5
  78. data/test/gemfiles/Gemfile.rails-3.1.x +0 -6
  79. data/test/gemfiles/Gemfile.rails-3.2.x +0 -5
  80. data/test/haml-spec/LICENSE +0 -14
  81. data/test/haml-spec/README.md +0 -106
  82. data/test/haml-spec/lua_haml_spec.lua +0 -38
  83. data/test/haml-spec/perl_haml_test.pl +0 -81
  84. data/test/haml-spec/ruby_haml_test.rb +0 -23
  85. data/test/haml-spec/tests.json +0 -660
  86. data/test/templates/_av_partial_1_ugly.haml +0 -9
  87. data/test/templates/_av_partial_2_ugly.haml +0 -5
  88. data/test/templates/action_view_ugly.haml +0 -47
  89. data/test/templates/standard_ugly.haml +0 -43
data/test/filters_test.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class FiltersTest < MiniTest::Unit::TestCase
3
+ class FiltersTest < Haml::TestCase
4
4
  test "should be registered as filters when including Haml::Filters::Base" do
5
5
  begin
6
6
  refute Haml::Filters.defined.has_key? "bar"
@@ -26,8 +26,11 @@ class FiltersTest < MiniTest::Unit::TestCase
26
26
  test "should raise error when a Tilt filters dependencies are unavailable for extension" do
27
27
  begin
28
28
  assert_raises Haml::Error do
29
- Haml::Filters.register_tilt_filter "Textile"
30
- Haml::Filters.defined["textile"].template_class
29
+ # ignore warnings from Tilt
30
+ silence_warnings do
31
+ Haml::Filters.register_tilt_filter "Textile"
32
+ Haml::Filters.defined["textile"].template_class
33
+ end
31
34
  end
32
35
  ensure
33
36
  Haml::Filters.remove_filter "Textile"
@@ -64,7 +67,7 @@ class FiltersTest < MiniTest::Unit::TestCase
64
67
  end
65
68
 
66
69
  test "should respect escaped newlines and interpolation" do
67
- html = "\\n\n"
70
+ html = "\\n\n\n"
68
71
  haml = ":plain\n \\n\#{""}"
69
72
  assert_equal(html, render(haml))
70
73
  end
@@ -73,16 +76,21 @@ class FiltersTest < MiniTest::Unit::TestCase
73
76
  assert_equal("\n", render(':plain'))
74
77
  end
75
78
 
76
- test "should be compatible with ugly mode" do
79
+ test ":plain with content" do
77
80
  expectation = "foo\n"
78
- assert_equal(expectation, render(":plain\n foo", :ugly => true))
81
+ assert_equal(expectation, render(":plain\n foo"))
79
82
  end
80
83
 
81
84
  test "should pass options to Tilt filters that precompile" do
82
- haml = ":erb\n <%= 'foo' %>"
83
- refute_match('TEST_VAR', Haml::Engine.new(haml).compiler.precompiled)
84
- Haml::Filters::Erb.options = {:outvar => 'TEST_VAR'}
85
- assert_match('TEST_VAR', Haml::Engine.new(haml).compiler.precompiled)
85
+ begin
86
+ orig_erb_opts = Haml::Filters::Erb.options
87
+ haml = ":erb\n <%= 'foo' %>"
88
+ refute_match('test_var', Haml::Engine.new(haml).compiler.precompiled)
89
+ Haml::Filters::Erb.options = {:outvar => 'test_var'}
90
+ assert_match('test_var', Haml::Engine.new(haml).compiler.precompiled)
91
+ ensure
92
+ Haml::Filters::Erb.options = orig_erb_opts
93
+ end
86
94
  end
87
95
 
88
96
  test "should pass options to Tilt filters that don't precompile" do
@@ -109,9 +117,14 @@ class FiltersTest < MiniTest::Unit::TestCase
109
117
  end
110
118
  end
111
119
 
120
+ test "interpolated code should be escaped if escape_html is set" do
121
+ assert_equal "&lt;script&gt;evil&lt;/script&gt;\n\n",
122
+ render(":plain\n \#{'<script>evil</script>'}", :escape_html => true)
123
+ end
124
+
112
125
  end
113
126
 
114
- class ErbFilterTest < MiniTest::Unit::TestCase
127
+ class ErbFilterTest < Haml::TestCase
115
128
  test "multiline expressions should work" do
116
129
  html = "foobarbaz\n"
117
130
  haml = %Q{:erb\n <%= "foo" +\n "bar" +\n "baz" %>}
@@ -132,7 +145,7 @@ class ErbFilterTest < MiniTest::Unit::TestCase
132
145
 
133
146
  end
134
147
 
135
- class JavascriptFilterTest < MiniTest::Unit::TestCase
148
+ class JavascriptFilterTest < Haml::TestCase
136
149
  test "should interpolate" do
137
150
  scope = Object.new.instance_eval {foo = "bar"; nil if foo; binding}
138
151
  haml = ":javascript\n \#{foo}"
@@ -140,8 +153,8 @@ class JavascriptFilterTest < MiniTest::Unit::TestCase
140
153
  assert_match(/bar/, html)
141
154
  end
142
155
 
143
- test "should never HTML-escape ampersands" do
144
- html = "<script>\n & < > &\n</script>\n"
156
+ test "should never HTML-escape non-interpolated ampersands" do
157
+ html = "<script>\n & < > &amp;\n</script>\n"
145
158
  haml = %Q{:javascript\n & < > \#{"&"}}
146
159
  assert_equal(html, render(haml, :escape_html => true))
147
160
  end
@@ -178,7 +191,7 @@ class JavascriptFilterTest < MiniTest::Unit::TestCase
178
191
  end
179
192
  end
180
193
 
181
- class CSSFilterTest < MiniTest::Unit::TestCase
194
+ class CSSFilterTest < Haml::TestCase
182
195
  test "should wrap output in CDATA and a CSS tag when output is XHTML" do
183
196
  html = "<style type='text/css'>\n /*<![CDATA[*/\n foo\n /*]]>*/\n</style>\n"
184
197
  haml = ":css\n foo"
@@ -217,7 +230,7 @@ class CSSFilterTest < MiniTest::Unit::TestCase
217
230
  end
218
231
  end
219
232
 
220
- class CDATAFilterTest < MiniTest::Unit::TestCase
233
+ class CDATAFilterTest < Haml::TestCase
221
234
  test "should wrap output in CDATA tag" do
222
235
  html = "<![CDATA[\n foo\n]]>\n"
223
236
  haml = ":cdata\n foo"
@@ -225,7 +238,7 @@ class CDATAFilterTest < MiniTest::Unit::TestCase
225
238
  end
226
239
  end
227
240
 
228
- class EscapedFilterTest < MiniTest::Unit::TestCase
241
+ class EscapedFilterTest < Haml::TestCase
229
242
  test "should escape ampersands" do
230
243
  html = "&amp;\n"
231
244
  haml = ":escaped\n &"
@@ -233,7 +246,7 @@ class EscapedFilterTest < MiniTest::Unit::TestCase
233
246
  end
234
247
  end
235
248
 
236
- class RubyFilterTest < MiniTest::Unit::TestCase
249
+ class RubyFilterTest < Haml::TestCase
237
250
  test "can write to haml_io" do
238
251
  haml = ":ruby\n haml_io.puts 'hello'\n"
239
252
  html = "hello\n"
@@ -251,4 +264,4 @@ class RubyFilterTest < MiniTest::Unit::TestCase
251
264
  html = "7\n"
252
265
  assert_equal(html, render(haml))
253
266
  end
254
- end
267
+ end
@@ -1,5 +1,11 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
2
 
3
- gem 'bundler', '~> 1.3.0'
4
- gem 'rails', '~> 4.0.0.rc1'
3
+ if ENV['TRAVIS']
4
+ platform :mri_21 do
5
+ gem 'coveralls', require: false
6
+ end
7
+ end
8
+
9
+ gem 'rails', '~> 4.0.0'
10
+ gem 'nokogiri', RUBY_VERSION < '2.1' ? '~> 1.6.0' : '>= 1.7'
5
11
  gemspec :path => '../..'
@@ -0,0 +1,87 @@
1
+ PATH
2
+ remote: ../..
3
+ specs:
4
+ haml (4.0.7)
5
+ tilt
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ actionmailer (4.0.13)
11
+ actionpack (= 4.0.13)
12
+ mail (~> 2.5, >= 2.5.4)
13
+ actionpack (4.0.13)
14
+ activesupport (= 4.0.13)
15
+ builder (~> 3.1.0)
16
+ erubis (~> 2.7.0)
17
+ rack (~> 1.5.2)
18
+ rack-test (~> 0.6.2)
19
+ activemodel (4.0.13)
20
+ activesupport (= 4.0.13)
21
+ builder (~> 3.1.0)
22
+ activerecord (4.0.13)
23
+ activemodel (= 4.0.13)
24
+ activerecord-deprecated_finders (~> 1.0.2)
25
+ activesupport (= 4.0.13)
26
+ arel (~> 4.0.0)
27
+ activerecord-deprecated_finders (1.0.4)
28
+ activesupport (4.0.13)
29
+ i18n (~> 0.6, >= 0.6.9)
30
+ minitest (~> 4.2)
31
+ multi_json (~> 1.3)
32
+ thread_safe (~> 0.1)
33
+ tzinfo (~> 0.3.37)
34
+ arel (4.0.2)
35
+ builder (3.1.4)
36
+ concurrent-ruby (1.0.2)
37
+ erubis (2.7.0)
38
+ i18n (0.7.0)
39
+ mail (2.6.4)
40
+ mime-types (>= 1.16, < 4)
41
+ mime-types (2.99.2)
42
+ minitest (4.7.5)
43
+ multi_json (1.12.1)
44
+ nokogiri (1.5.11)
45
+ rack (1.5.5)
46
+ rack-test (0.6.3)
47
+ rack (>= 1.0)
48
+ rails (4.0.13)
49
+ actionmailer (= 4.0.13)
50
+ actionpack (= 4.0.13)
51
+ activerecord (= 4.0.13)
52
+ activesupport (= 4.0.13)
53
+ bundler (>= 1.3.0, < 2.0)
54
+ railties (= 4.0.13)
55
+ sprockets-rails (~> 2.0)
56
+ railties (4.0.13)
57
+ actionpack (= 4.0.13)
58
+ activesupport (= 4.0.13)
59
+ rake (>= 0.8.7)
60
+ thor (>= 0.18.1, < 2.0)
61
+ rake (11.2.2)
62
+ rbench (0.2.3)
63
+ sprockets (3.7.0)
64
+ concurrent-ruby (~> 1.0)
65
+ rack (> 1, < 3)
66
+ sprockets-rails (2.3.3)
67
+ actionpack (>= 3.0)
68
+ activesupport (>= 3.0)
69
+ sprockets (>= 2.8, < 4.0)
70
+ thor (0.19.1)
71
+ thread_safe (0.3.5)
72
+ tilt (2.0.5)
73
+ tzinfo (0.3.51)
74
+
75
+ PLATFORMS
76
+ ruby
77
+
78
+ DEPENDENCIES
79
+ haml!
80
+ mime-types (< 3)
81
+ minitest
82
+ nokogiri (~> 1.5.10)
83
+ rails (~> 4.0.0)
84
+ rbench
85
+
86
+ BUNDLED WITH
87
+ 1.12.5
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'rails', '~> 4.1.0'
4
+ gem 'nokogiri', RUBY_VERSION < '2.1' ? '~> 1.6.0' : '>= 1.7'
5
+ gemspec :path => '../..'
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'rails', '~> 4.2.0'
4
+ gem 'nokogiri', RUBY_VERSION < '2.1' ? '~> 1.6.0' : '>= 1.7'
5
+ gemspec :path => '../..'
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'rails', '~> 5.0.0'
4
+ gemspec :path => '../..'