haml 3.2.0.alpha.13 → 3.2.0.alpha.14

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.

@@ -5,7 +5,7 @@ require 'haml/helpers/action_view_extensions'
5
5
  require 'haml/helpers/xss_mods'
6
6
 
7
7
  module Haml
8
- module Compiler
8
+ class Compiler
9
9
  def precompiled_method_return_value_with_haml_xss
10
10
  "::Haml::Util.html_safe(#{precompiled_method_return_value_without_haml_xss})"
11
11
  end
@@ -25,8 +25,8 @@ module Haml
25
25
  end
26
26
 
27
27
 
28
- Haml::Template.options[:ugly] ||= Rails.env.development?
28
+ Haml::Template.options[:ugly] = !Rails.env.development?
29
29
  Haml::Template.options[:escape_html] = true
30
- Haml::Template.options[:format] ||= :html5
30
+ Haml::Template.options[:format] = :html5
31
31
 
32
32
  require 'haml/template/plugin'
@@ -18,7 +18,7 @@ module Haml
18
18
  options = Haml::Template.options.dup
19
19
  options[:mime_type] = template.mime_type if template.respond_to? :mime_type
20
20
  options[:filename] = template.identifier
21
- Haml::Engine.new(template.source, options).send(:precompiled_with_ambles, [])
21
+ Haml::Engine.new(template.source, options).compiler.precompiled_with_ambles([])
22
22
  end
23
23
 
24
24
  # In Rails 3.1+, #call takes the place of #compile
@@ -8,14 +8,6 @@ module Haml
8
8
  module Util
9
9
  extend self
10
10
 
11
- # Returns the path of a file relative to the Haml root directory.
12
- #
13
- # @param file [String] The filename relative to the Haml root
14
- # @return [String] The filename relative to the the working directory
15
- def scope(file)
16
- File.expand_path("../../../#{file}", __FILE__)
17
- end
18
-
19
11
  # Computes the powerset of the given array.
20
12
  # This is the set of all subsets of the array.
21
13
  #
@@ -90,8 +82,7 @@ module Haml
90
82
  # @return [String, nil] `text`, marked as HTML-safe
91
83
  def html_safe(text)
92
84
  return unless text
93
- return text.html_safe if defined?(ActiveSupport::SafeBuffer)
94
- text.html_safe!
85
+ text.html_safe
95
86
  end
96
87
 
97
88
  # Checks that the encoding of a string is valid in Ruby 1.9
@@ -172,17 +163,22 @@ MSG
172
163
  end
173
164
  end
174
165
 
175
- # Like `Object#inspect`, but preserves non-ASCII characters rather than escaping them under Ruby 1.9.2.
176
- # This is necessary so that the precompiled Haml template can be `#encode`d into `@options[:encoding]`
177
- # before being evaluated.
178
- #
179
- # @param obj {Object}
180
- # @return {String}
181
- def inspect_obj(obj)
182
- return obj.inspect unless (::RUBY_VERSION >= "1.9.2")
183
- return ':' + inspect_obj(obj.to_s) if obj.is_a?(Symbol)
184
- return obj.inspect unless obj.is_a?(String)
185
- '"' + obj.gsub(/[\x00-\x7F]+/) {|s| s.inspect[1...-1]} + '"'
166
+ if RUBY_VERSION < "1.9.2"
167
+ def inspect_obj(obj)
168
+ return obj.inspect
169
+ end
170
+ else
171
+ # Like `Object#inspect`, but preserves non-ASCII characters rather than escaping them under Ruby 1.9.2.
172
+ # This is necessary so that the precompiled Haml template can be `#encode`d into `@options[:encoding]`
173
+ # before being evaluated.
174
+ #
175
+ # @param obj {Object}
176
+ # @return {String}
177
+ def inspect_obj(obj)
178
+ return ':' + inspect_obj(obj.to_s) if obj.is_a?(Symbol)
179
+ return obj.inspect unless obj.is_a?(String)
180
+ '"' + obj.gsub(/[\x00-\x7F]+/) {|s| s.inspect[1...-1]} + '"'
181
+ end
186
182
  end
187
183
 
188
184
  ## Static Method Stuff
@@ -327,6 +323,26 @@ METHOD
327
323
  "#{indentation.length} #{noun}#{'s' unless singular}#{was}"
328
324
  end
329
325
 
326
+ def contains_interpolation?(str)
327
+ str.include?('#{')
328
+ end
329
+
330
+ def unescape_interpolation(str, escape_html = nil)
331
+ res = ''
332
+ rest = Haml::Util.handle_interpolation str.dump do |scan|
333
+ escapes = (scan[2].size - 1) / 2
334
+ res << scan.matched[0...-3 - escapes]
335
+ if escapes % 2 == 1
336
+ res << '#{'
337
+ else
338
+ content = eval('"' + balance(scan, ?{, ?}, 1)[0][0...-1] + '"')
339
+ content = "Haml::Helpers.html_escape((#{content}))" if escape_html
340
+ res << '#{' + content + "}"# Use eval to get rid of string escapes
341
+ end
342
+ end
343
+ res + rest
344
+ end
345
+
330
346
  private
331
347
 
332
348
  # Parses a magic comment at the beginning of a Haml file.
@@ -1,3 +1,3 @@
1
1
  module Haml
2
- VERSION = "3.2.0.alpha.13"
2
+ VERSION = "3.2.0.alpha.14"
3
3
  end
@@ -731,7 +731,8 @@ HAML
731
731
  end
732
732
 
733
733
  def test_silent_script_with_hyphen_end_and_block
734
- assert_equal(<<HTML, render(<<HAML))
734
+ silence_warnings do
735
+ assert_equal(<<HTML, render(<<HAML))
735
736
  <p>foo-end</p>
736
737
  <p>bar-end</p>
737
738
  HTML
@@ -739,6 +740,7 @@ HTML
739
740
  %p= s
740
741
  - end; nil)
741
742
  HAML
743
+ end
742
744
  end
743
745
 
744
746
  def test_if_without_content_and_else
@@ -1152,7 +1154,9 @@ HAML
1152
1154
  EXCEPTION_MAP.each do |key, value|
1153
1155
  define_method("test_exception (#{key.inspect})") do
1154
1156
  begin
1155
- render(key, :filename => "(test_exception (#{key.inspect}))")
1157
+ silence_warnings do
1158
+ render(key, :filename => "(test_exception (#{key.inspect}))")
1159
+ end
1156
1160
  rescue Exception => err
1157
1161
  value = [value] unless value.is_a?(Array)
1158
1162
  expected_message, line_no = value
@@ -1327,6 +1331,20 @@ HAML
1327
1331
  render("%p= 's' * 75", :ugly => true))
1328
1332
  end
1329
1333
 
1334
+ def test_remove_whitespace_true
1335
+ assert_equal("<div id='outer'><div id='inner'><p>hello world</p></div></div>",
1336
+ render("#outer\n #inner\n %p hello world", :remove_whitespace => true))
1337
+ assert_equal("<p>hello world<pre>foo bar\nbaz</pre></p>", render(<<HAML, :remove_whitespace => true))
1338
+ %p
1339
+ hello world
1340
+ %pre
1341
+ foo bar
1342
+ baz
1343
+ HAML
1344
+ assert_equal("<div><span>foo</span> <span>bar</span></div>",
1345
+ render('%div <span>foo</span> <span>bar</span>', :remove_whitespace => true))
1346
+ end
1347
+
1330
1348
  def test_auto_preserve_unless_ugly
1331
1349
  assert_equal("<pre>foo&#x000A;bar</pre>\n", render('%pre="foo\nbar"'))
1332
1350
  assert_equal("<pre>foo\nbar</pre>\n", render("%pre\n foo\n bar"))
@@ -41,9 +41,9 @@ class FiltersTest < MiniTest::Unit::TestCase
41
41
 
42
42
  test "should pass options to Tilt filters that precompile" do
43
43
  haml = ":erb\n <%= 'foo' %>"
44
- refute_match('TEST_VAR', Haml::Engine.new(haml).precompiled)
44
+ refute_match('TEST_VAR', Haml::Engine.new(haml).compiler.precompiled)
45
45
  Haml::Filters::Erb.options = {:outvar => 'TEST_VAR'}
46
- assert_match('TEST_VAR', Haml::Engine.new(haml).precompiled)
46
+ assert_match('TEST_VAR', Haml::Engine.new(haml).compiler.precompiled)
47
47
  end
48
48
 
49
49
  test "should pass options to Tilt filters that don't precompile" do
@@ -0,0 +1,101 @@
1
+ PATH
2
+ remote: ../../vendor/haml-contrib
3
+ specs:
4
+ haml-contrib (0.0.0)
5
+
6
+ PATH
7
+ remote: /Users/norman/work/haml/haml
8
+ specs:
9
+ haml (3.2.0.alpha.13)
10
+ tilt
11
+
12
+ GEM
13
+ remote: http://rubygems.org/
14
+ specs:
15
+ abstract (1.0.0)
16
+ actionmailer (3.0.12)
17
+ actionpack (= 3.0.12)
18
+ mail (~> 2.2.19)
19
+ actionpack (3.0.12)
20
+ activemodel (= 3.0.12)
21
+ activesupport (= 3.0.12)
22
+ builder (~> 2.1.2)
23
+ erubis (~> 2.6.6)
24
+ i18n (~> 0.5.0)
25
+ rack (~> 1.2.5)
26
+ rack-mount (~> 0.6.14)
27
+ rack-test (~> 0.5.7)
28
+ tzinfo (~> 0.3.23)
29
+ activemodel (3.0.12)
30
+ activesupport (= 3.0.12)
31
+ builder (~> 2.1.2)
32
+ i18n (~> 0.5.0)
33
+ activerecord (3.0.12)
34
+ activemodel (= 3.0.12)
35
+ activesupport (= 3.0.12)
36
+ arel (~> 2.0.10)
37
+ tzinfo (~> 0.3.23)
38
+ activeresource (3.0.12)
39
+ activemodel (= 3.0.12)
40
+ activesupport (= 3.0.12)
41
+ activesupport (3.0.12)
42
+ arel (2.0.10)
43
+ builder (2.1.2)
44
+ erubis (2.6.6)
45
+ abstract (>= 1.0.0)
46
+ i18n (0.5.0)
47
+ json (1.7.3)
48
+ mail (2.2.19)
49
+ activesupport (>= 2.3.6)
50
+ i18n (>= 0.4.0)
51
+ mime-types (~> 1.16)
52
+ treetop (~> 1.4.8)
53
+ maruku (0.6.0)
54
+ syntax (>= 1.0.0)
55
+ mime-types (1.18)
56
+ minitest (3.0.1)
57
+ polyglot (0.3.3)
58
+ rack (1.2.5)
59
+ rack-mount (0.6.14)
60
+ rack (>= 1.0.0)
61
+ rack-test (0.5.7)
62
+ rack (>= 1.0)
63
+ rails (3.0.12)
64
+ actionmailer (= 3.0.12)
65
+ actionpack (= 3.0.12)
66
+ activerecord (= 3.0.12)
67
+ activeresource (= 3.0.12)
68
+ activesupport (= 3.0.12)
69
+ bundler (~> 1.0)
70
+ railties (= 3.0.12)
71
+ railties (3.0.12)
72
+ actionpack (= 3.0.12)
73
+ activesupport (= 3.0.12)
74
+ rake (>= 0.8.7)
75
+ rdoc (~> 3.4)
76
+ thor (~> 0.14.4)
77
+ rake (0.9.2.2)
78
+ rbench (0.2.3)
79
+ rdoc (3.12)
80
+ json (~> 1.4)
81
+ syntax (1.0.0)
82
+ thor (0.14.6)
83
+ tilt (1.3.3)
84
+ treetop (1.4.10)
85
+ polyglot
86
+ polyglot (>= 0.3.1)
87
+ tzinfo (0.3.33)
88
+ yard (0.8.1)
89
+
90
+ PLATFORMS
91
+ ruby
92
+
93
+ DEPENDENCIES
94
+ haml!
95
+ haml-contrib!
96
+ json
97
+ maruku (>= 0.5.9)
98
+ minitest
99
+ rails (>= 3.0.0, < 3.1.0)
100
+ rbench
101
+ yard (>= 0.5.3)
@@ -0,0 +1,111 @@
1
+ PATH
2
+ remote: ../../vendor/haml-contrib
3
+ specs:
4
+ haml-contrib (0.0.0)
5
+
6
+ PATH
7
+ remote: /Users/norman/work/haml/haml
8
+ specs:
9
+ haml (3.2.0.alpha.13)
10
+ tilt
11
+
12
+ GEM
13
+ remote: http://rubygems.org/
14
+ specs:
15
+ actionmailer (3.1.5)
16
+ actionpack (= 3.1.5)
17
+ mail (~> 2.3.3)
18
+ actionpack (3.1.5)
19
+ activemodel (= 3.1.5)
20
+ activesupport (= 3.1.5)
21
+ builder (~> 3.0.0)
22
+ erubis (~> 2.7.0)
23
+ i18n (~> 0.6)
24
+ rack (~> 1.3.6)
25
+ rack-cache (~> 1.2)
26
+ rack-mount (~> 0.8.2)
27
+ rack-test (~> 0.6.1)
28
+ sprockets (~> 2.0.4)
29
+ activemodel (3.1.5)
30
+ activesupport (= 3.1.5)
31
+ builder (~> 3.0.0)
32
+ i18n (~> 0.6)
33
+ activerecord (3.1.5)
34
+ activemodel (= 3.1.5)
35
+ activesupport (= 3.1.5)
36
+ arel (~> 2.2.3)
37
+ tzinfo (~> 0.3.29)
38
+ activeresource (3.1.5)
39
+ activemodel (= 3.1.5)
40
+ activesupport (= 3.1.5)
41
+ activesupport (3.1.5)
42
+ multi_json (>= 1.0, < 1.3)
43
+ arel (2.2.3)
44
+ builder (3.0.0)
45
+ erubis (2.7.0)
46
+ hike (1.2.1)
47
+ i18n (0.6.0)
48
+ json (1.7.3)
49
+ mail (2.3.3)
50
+ i18n (>= 0.4.0)
51
+ mime-types (~> 1.16)
52
+ treetop (~> 1.4.8)
53
+ maruku (0.6.0)
54
+ syntax (>= 1.0.0)
55
+ mime-types (1.18)
56
+ minitest (3.0.1)
57
+ multi_json (1.2.0)
58
+ polyglot (0.3.3)
59
+ rack (1.3.6)
60
+ rack-cache (1.2)
61
+ rack (>= 0.4)
62
+ rack-mount (0.8.3)
63
+ rack (>= 1.0.0)
64
+ rack-ssl (1.3.2)
65
+ rack
66
+ rack-test (0.6.1)
67
+ rack (>= 1.0)
68
+ rails (3.1.5)
69
+ actionmailer (= 3.1.5)
70
+ actionpack (= 3.1.5)
71
+ activerecord (= 3.1.5)
72
+ activeresource (= 3.1.5)
73
+ activesupport (= 3.1.5)
74
+ bundler (~> 1.0)
75
+ railties (= 3.1.5)
76
+ railties (3.1.5)
77
+ actionpack (= 3.1.5)
78
+ activesupport (= 3.1.5)
79
+ rack-ssl (~> 1.3.2)
80
+ rake (>= 0.8.7)
81
+ rdoc (~> 3.4)
82
+ thor (~> 0.14.6)
83
+ rake (0.9.2.2)
84
+ rbench (0.2.3)
85
+ rdoc (3.12)
86
+ json (~> 1.4)
87
+ sprockets (2.0.4)
88
+ hike (~> 1.2)
89
+ rack (~> 1.0)
90
+ tilt (~> 1.1, != 1.3.0)
91
+ syntax (1.0.0)
92
+ thor (0.14.6)
93
+ tilt (1.3.3)
94
+ treetop (1.4.10)
95
+ polyglot
96
+ polyglot (>= 0.3.1)
97
+ tzinfo (0.3.33)
98
+ yard (0.8.1)
99
+
100
+ PLATFORMS
101
+ ruby
102
+
103
+ DEPENDENCIES
104
+ haml!
105
+ haml-contrib!
106
+ json
107
+ maruku (>= 0.5.9)
108
+ minitest
109
+ rails (>= 3.1.0, < 3.2.0)
110
+ rbench
111
+ yard (>= 0.5.3)
@@ -0,0 +1,109 @@
1
+ PATH
2
+ remote: ../../vendor/haml-contrib
3
+ specs:
4
+ haml-contrib (0.0.0)
5
+
6
+ PATH
7
+ remote: /Users/norman/work/haml/haml
8
+ specs:
9
+ haml (3.2.0.alpha.13)
10
+ tilt
11
+
12
+ GEM
13
+ remote: http://rubygems.org/
14
+ specs:
15
+ actionmailer (3.2.5)
16
+ actionpack (= 3.2.5)
17
+ mail (~> 2.4.4)
18
+ actionpack (3.2.5)
19
+ activemodel (= 3.2.5)
20
+ activesupport (= 3.2.5)
21
+ builder (~> 3.0.0)
22
+ erubis (~> 2.7.0)
23
+ journey (~> 1.0.1)
24
+ rack (~> 1.4.0)
25
+ rack-cache (~> 1.2)
26
+ rack-test (~> 0.6.1)
27
+ sprockets (~> 2.1.3)
28
+ activemodel (3.2.5)
29
+ activesupport (= 3.2.5)
30
+ builder (~> 3.0.0)
31
+ activerecord (3.2.5)
32
+ activemodel (= 3.2.5)
33
+ activesupport (= 3.2.5)
34
+ arel (~> 3.0.2)
35
+ tzinfo (~> 0.3.29)
36
+ activeresource (3.2.5)
37
+ activemodel (= 3.2.5)
38
+ activesupport (= 3.2.5)
39
+ activesupport (3.2.5)
40
+ i18n (~> 0.6)
41
+ multi_json (~> 1.0)
42
+ arel (3.0.2)
43
+ builder (3.0.0)
44
+ erubis (2.7.0)
45
+ hike (1.2.1)
46
+ i18n (0.6.0)
47
+ journey (1.0.3)
48
+ json (1.7.3)
49
+ mail (2.4.4)
50
+ i18n (>= 0.4.0)
51
+ mime-types (~> 1.16)
52
+ treetop (~> 1.4.8)
53
+ maruku (0.6.0)
54
+ syntax (>= 1.0.0)
55
+ mime-types (1.18)
56
+ minitest (3.0.1)
57
+ multi_json (1.3.6)
58
+ polyglot (0.3.3)
59
+ rack (1.4.1)
60
+ rack-cache (1.2)
61
+ rack (>= 0.4)
62
+ rack-ssl (1.3.2)
63
+ rack
64
+ rack-test (0.6.1)
65
+ rack (>= 1.0)
66
+ rails (3.2.5)
67
+ actionmailer (= 3.2.5)
68
+ actionpack (= 3.2.5)
69
+ activerecord (= 3.2.5)
70
+ activeresource (= 3.2.5)
71
+ activesupport (= 3.2.5)
72
+ bundler (~> 1.0)
73
+ railties (= 3.2.5)
74
+ railties (3.2.5)
75
+ actionpack (= 3.2.5)
76
+ activesupport (= 3.2.5)
77
+ rack-ssl (~> 1.3.2)
78
+ rake (>= 0.8.7)
79
+ rdoc (~> 3.4)
80
+ thor (>= 0.14.6, < 2.0)
81
+ rake (0.9.2.2)
82
+ rbench (0.2.3)
83
+ rdoc (3.12)
84
+ json (~> 1.4)
85
+ sprockets (2.1.3)
86
+ hike (~> 1.2)
87
+ rack (~> 1.0)
88
+ tilt (~> 1.1, != 1.3.0)
89
+ syntax (1.0.0)
90
+ thor (0.15.2)
91
+ tilt (1.3.3)
92
+ treetop (1.4.10)
93
+ polyglot
94
+ polyglot (>= 0.3.1)
95
+ tzinfo (0.3.33)
96
+ yard (0.8.1)
97
+
98
+ PLATFORMS
99
+ ruby
100
+
101
+ DEPENDENCIES
102
+ haml!
103
+ haml-contrib!
104
+ json
105
+ maruku (>= 0.5.9)
106
+ minitest
107
+ rails (>= 3.2.0, < 3.3.0)
108
+ rbench
109
+ yard (>= 0.5.3)