haml 2.2.24 → 3.0.0.beta.1
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.
- data/.yardopts +0 -1
- data/README.md +91 -151
- data/REMEMBER +11 -1
- data/Rakefile +73 -55
- data/VERSION +1 -1
- data/VERSION_NAME +1 -1
- data/bin/css2sass +7 -1
- data/bin/sass-convert +7 -0
- data/extra/haml-mode.el +2 -1
- data/lib/haml/buffer.rb +22 -4
- data/lib/haml/engine.rb +5 -1
- data/lib/haml/exec.rb +231 -46
- data/lib/haml/filters.rb +19 -8
- data/lib/haml/helpers.rb +47 -20
- data/lib/haml/helpers/action_view_extensions.rb +2 -4
- data/lib/haml/helpers/action_view_mods.rb +11 -8
- data/lib/haml/helpers/xss_mods.rb +13 -2
- data/lib/haml/html.rb +179 -48
- data/lib/haml/html/erb.rb +141 -0
- data/lib/haml/precompiler.rb +40 -15
- data/lib/haml/railtie.rb +1 -5
- data/lib/haml/root.rb +3 -0
- data/lib/haml/template.rb +4 -14
- data/lib/haml/util.rb +120 -30
- data/lib/haml/version.rb +25 -2
- data/lib/sass.rb +5 -1
- data/lib/sass/callbacks.rb +50 -0
- data/lib/sass/css.rb +40 -191
- data/lib/sass/engine.rb +170 -74
- data/lib/sass/environment.rb +8 -2
- data/lib/sass/error.rb +163 -25
- data/lib/sass/files.rb +31 -28
- data/lib/sass/plugin.rb +268 -87
- data/lib/sass/plugin/rails.rb +9 -4
- data/lib/sass/repl.rb +1 -1
- data/lib/sass/script.rb +31 -29
- data/lib/sass/script/bool.rb +1 -0
- data/lib/sass/script/color.rb +290 -23
- data/lib/sass/script/css_lexer.rb +22 -0
- data/lib/sass/script/css_parser.rb +28 -0
- data/lib/sass/script/funcall.rb +22 -3
- data/lib/sass/script/functions.rb +523 -33
- data/lib/sass/script/interpolation.rb +42 -0
- data/lib/sass/script/lexer.rb +169 -52
- data/lib/sass/script/literal.rb +58 -9
- data/lib/sass/script/node.rb +79 -1
- data/lib/sass/script/number.rb +20 -5
- data/lib/sass/script/operation.rb +49 -3
- data/lib/sass/script/parser.rb +162 -28
- data/lib/sass/script/string.rb +50 -2
- data/lib/sass/script/unary_operation.rb +25 -2
- data/lib/sass/script/variable.rb +21 -4
- data/lib/sass/scss.rb +14 -0
- data/lib/sass/scss/css_parser.rb +39 -0
- data/lib/sass/scss/parser.rb +683 -0
- data/lib/sass/scss/rx.rb +112 -0
- data/lib/sass/scss/script_lexer.rb +13 -0
- data/lib/sass/scss/script_parser.rb +25 -0
- data/lib/sass/tree/comment_node.rb +69 -27
- data/lib/sass/tree/debug_node.rb +7 -2
- data/lib/sass/tree/directive_node.rb +41 -35
- data/lib/sass/tree/for_node.rb +6 -0
- data/lib/sass/tree/if_node.rb +13 -1
- data/lib/sass/tree/import_node.rb +52 -27
- data/lib/sass/tree/mixin_def_node.rb +18 -0
- data/lib/sass/tree/mixin_node.rb +41 -6
- data/lib/sass/tree/node.rb +197 -70
- data/lib/sass/tree/prop_node.rb +152 -57
- data/lib/sass/tree/root_node.rb +118 -0
- data/lib/sass/tree/rule_node.rb +193 -96
- data/lib/sass/tree/variable_node.rb +9 -5
- data/lib/sass/tree/while_node.rb +4 -0
- data/test/benchmark.rb +5 -5
- data/test/haml/engine_test.rb +147 -10
- data/test/haml/{rhtml/_av_partial_1.rhtml → erb/_av_partial_1.erb} +1 -1
- data/test/haml/{rhtml/_av_partial_2.rhtml → erb/_av_partial_2.erb} +1 -1
- data/test/haml/{rhtml/action_view.rhtml → erb/action_view.erb} +1 -1
- data/test/haml/{rhtml/standard.rhtml → erb/standard.erb} +0 -0
- data/test/haml/helper_test.rb +91 -24
- data/test/haml/html2haml/erb_tests.rb +410 -0
- data/test/haml/html2haml_test.rb +210 -66
- data/test/haml/results/filters.xhtml +1 -1
- data/test/haml/results/just_stuff.xhtml +2 -0
- data/test/haml/spec_test.rb +44 -0
- data/test/haml/template_test.rb +22 -2
- data/test/haml/templates/helpers.haml +0 -13
- data/test/haml/templates/just_stuff.haml +2 -0
- data/test/haml/util_test.rb +48 -0
- data/test/sass/callbacks_test.rb +61 -0
- data/test/sass/conversion_test.rb +884 -0
- data/test/sass/css2sass_test.rb +99 -18
- data/test/sass/data/hsl-rgb.txt +319 -0
- data/test/sass/engine_test.rb +1049 -131
- data/test/sass/functions_test.rb +398 -47
- data/test/sass/more_results/more_import.css +1 -1
- data/test/sass/more_templates/more_import.sass +3 -3
- data/test/sass/plugin_test.rb +184 -10
- data/test/sass/results/compact.css +1 -1
- data/test/sass/results/complex.css +5 -5
- data/test/sass/results/compressed.css +1 -1
- data/test/sass/results/expanded.css +1 -1
- data/test/sass/results/import.css +3 -1
- data/test/sass/results/mixins.css +12 -12
- data/test/sass/results/nested.css +1 -1
- data/test/sass/results/options.css +1 -0
- data/test/sass/results/parent_ref.css +4 -4
- data/test/sass/results/script.css +3 -3
- data/test/sass/results/scss_import.css +15 -0
- data/test/sass/results/scss_importee.css +2 -0
- data/test/sass/script_conversion_test.rb +153 -0
- data/test/sass/script_test.rb +137 -70
- data/test/sass/scss/css_test.rb +811 -0
- data/test/sass/scss/rx_test.rb +156 -0
- data/test/sass/scss/scss_test.rb +871 -0
- data/test/sass/scss/test_helper.rb +37 -0
- data/test/sass/templates/alt.sass +2 -2
- data/test/sass/templates/bork1.sass +2 -0
- data/test/sass/templates/bork3.sass +2 -0
- data/test/sass/templates/bork4.sass +2 -0
- data/test/sass/templates/import.sass +4 -4
- data/test/sass/templates/importee.sass +3 -3
- data/test/sass/templates/line_numbers.sass +1 -1
- data/test/sass/templates/mixin_bork.sass +5 -0
- data/test/sass/templates/mixins.sass +2 -2
- data/test/sass/templates/nested_bork1.sass +2 -0
- data/test/sass/templates/nested_bork2.sass +2 -0
- data/test/sass/templates/nested_bork3.sass +2 -0
- data/test/sass/templates/nested_bork4.sass +2 -0
- data/test/sass/templates/nested_mixin_bork.sass +6 -0
- data/test/sass/templates/options.sass +2 -0
- data/test/sass/templates/parent_ref.sass +2 -2
- data/test/sass/templates/script.sass +69 -69
- data/test/sass/templates/scss_import.scss +10 -0
- data/test/sass/templates/scss_importee.scss +1 -0
- data/test/sass/templates/units.sass +10 -10
- data/test/test_helper.rb +20 -8
- data/vendor/fssm/LICENSE +20 -0
- data/vendor/fssm/README.markdown +55 -0
- data/vendor/fssm/Rakefile +59 -0
- data/vendor/fssm/VERSION.yml +5 -0
- data/vendor/fssm/example.rb +9 -0
- data/vendor/fssm/fssm.gemspec +77 -0
- data/vendor/fssm/lib/fssm.rb +33 -0
- data/vendor/fssm/lib/fssm/backends/fsevents.rb +36 -0
- data/vendor/fssm/lib/fssm/backends/inotify.rb +26 -0
- data/vendor/fssm/lib/fssm/backends/polling.rb +25 -0
- data/vendor/fssm/lib/fssm/backends/rubycocoa/fsevents.rb +131 -0
- data/vendor/fssm/lib/fssm/monitor.rb +26 -0
- data/vendor/fssm/lib/fssm/path.rb +91 -0
- data/vendor/fssm/lib/fssm/pathname.rb +502 -0
- data/vendor/fssm/lib/fssm/state/directory.rb +57 -0
- data/vendor/fssm/lib/fssm/state/file.rb +24 -0
- data/vendor/fssm/lib/fssm/support.rb +63 -0
- data/vendor/fssm/lib/fssm/tree.rb +176 -0
- data/vendor/fssm/profile/prof-cache.rb +40 -0
- data/vendor/fssm/profile/prof-fssm-pathname.html +1231 -0
- data/vendor/fssm/profile/prof-pathname.rb +68 -0
- data/vendor/fssm/profile/prof-plain-pathname.html +988 -0
- data/vendor/fssm/profile/prof.html +2379 -0
- data/vendor/fssm/spec/path_spec.rb +75 -0
- data/vendor/fssm/spec/root/duck/quack.txt +0 -0
- data/vendor/fssm/spec/root/file.css +0 -0
- data/vendor/fssm/spec/root/file.rb +0 -0
- data/vendor/fssm/spec/root/file.yml +0 -0
- data/vendor/fssm/spec/root/moo/cow.txt +0 -0
- data/vendor/fssm/spec/spec_helper.rb +14 -0
- metadata +94 -14
- data/test/sass/templates/bork.sass +0 -2
@@ -16,17 +16,21 @@ module Sass
|
|
16
16
|
|
17
17
|
protected
|
18
18
|
|
19
|
+
def to_src(tabs, opts, fmt)
|
20
|
+
"#{' ' * tabs}$#{@name}: #{@expr.to_sass}#{' !default' if @guarded}#{semi fmt}\n"
|
21
|
+
end
|
22
|
+
|
19
23
|
# Loads the new variable value into the environment.
|
20
24
|
#
|
21
25
|
# @param environment [Sass::Environment] The lexical environment containing
|
22
26
|
# variable and mixin values
|
23
27
|
def _perform(environment)
|
24
|
-
if @guarded && environment.var(@name).nil?
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
+
return [] if @guarded && !environment.var(@name).nil?
|
29
|
+
val = @expr.perform(environment)
|
30
|
+
if @expr.context == :equals && val.is_a?(Sass::Script::String)
|
31
|
+
val = Sass::Script::String.new(val.value)
|
28
32
|
end
|
29
|
-
|
33
|
+
environment.set_var(@name, val)
|
30
34
|
[]
|
31
35
|
end
|
32
36
|
end
|
data/lib/sass/tree/while_node.rb
CHANGED
@@ -13,6 +13,10 @@ module Sass::Tree
|
|
13
13
|
|
14
14
|
protected
|
15
15
|
|
16
|
+
def to_src(tabs, opts, fmt)
|
17
|
+
"#{' ' * tabs}@while #{@expr.to_sass}" + children_to_src(tabs, opts, fmt)
|
18
|
+
end
|
19
|
+
|
16
20
|
# Runs the child nodes until the continue expression becomes false.
|
17
21
|
#
|
18
22
|
# @param environment [Sass::Environment] The lexical environment containing
|
data/test/benchmark.rb
CHANGED
@@ -40,7 +40,7 @@ RBench.run(times) do
|
|
40
40
|
template_name = 'standard'
|
41
41
|
directory = File.dirname(__FILE__) + '/haml'
|
42
42
|
haml_template = File.read("#{directory}/templates/#{template_name}.haml")
|
43
|
-
erb_template = File.read("#{directory}/
|
43
|
+
erb_template = File.read("#{directory}/erb/#{template_name}.erb")
|
44
44
|
markaby_template = File.read("#{directory}/markaby/#{template_name}.mab")
|
45
45
|
|
46
46
|
report "Cached" do
|
@@ -64,10 +64,10 @@ RBench.run(times) do
|
|
64
64
|
Haml::Template.options[:ugly] = false
|
65
65
|
# To cache the template
|
66
66
|
render @base, 'haml/templates/standard'
|
67
|
-
render @base, 'haml/
|
67
|
+
render @base, 'haml/erb/standard'
|
68
68
|
|
69
69
|
haml { render @base, 'haml/templates/standard' }
|
70
|
-
erb { render @base, 'haml/
|
70
|
+
erb { render @base, 'haml/erb/standard' }
|
71
71
|
|
72
72
|
Haml::Template.options[:ugly] = true
|
73
73
|
render @base, 'haml/templates/standard_ugly'
|
@@ -81,10 +81,10 @@ RBench.run(times) do
|
|
81
81
|
Haml::Template.options[:ugly] = false
|
82
82
|
# To cache the template
|
83
83
|
render @base, 'haml/templates/action_view'
|
84
|
-
render @base, 'haml/
|
84
|
+
render @base, 'haml/erb/action_view'
|
85
85
|
|
86
86
|
haml { render @base, 'haml/templates/action_view' }
|
87
|
-
erb { render @base, 'haml/
|
87
|
+
erb { render @base, 'haml/erb/action_view' }
|
88
88
|
|
89
89
|
Haml::Template.options[:ugly] = true
|
90
90
|
render @base, 'haml/templates/action_view_ugly'
|
data/test/haml/engine_test.rb
CHANGED
@@ -89,6 +89,11 @@ MESSAGE
|
|
89
89
|
}
|
90
90
|
|
91
91
|
User = Struct.new('User', :id)
|
92
|
+
class CustomHamlClass < Struct.new(:id)
|
93
|
+
def haml_object_ref
|
94
|
+
"my_thing"
|
95
|
+
end
|
96
|
+
end
|
92
97
|
|
93
98
|
def render(text, options = {}, &block)
|
94
99
|
scope = options.delete(:scope) || Object.new
|
@@ -137,6 +142,29 @@ MESSAGE
|
|
137
142
|
assert_equal("<p class='3'>foo</p>", render("%p{:class => 1+2} foo").chomp)
|
138
143
|
end
|
139
144
|
|
145
|
+
def test_class_attr_with_array
|
146
|
+
assert_equal("<p class='a b'>foo</p>\n", render("%p{:class => %w[a b]} foo")) # basic
|
147
|
+
assert_equal("<p class='a b css'>foo</p>\n", render("%p.css{:class => %w[a b]} foo")) # merge with css
|
148
|
+
assert_equal("<p class='b css'>foo</p>\n", render("%p.css{:class => %w[css b]} foo")) # merge uniquely
|
149
|
+
assert_equal("<p class='a b c d'>foo</p>\n", render("%p{:class => [%w[a b], %w[c d]]} foo")) # flatten
|
150
|
+
assert_equal("<p class='a b'>foo</p>\n", render("%p{:class => [:a, :b] } foo")) # stringify
|
151
|
+
assert_equal("<p class=''>foo</p>\n", render("%p{:class => [nil, false] } foo")) # strip falsey
|
152
|
+
assert_equal("<p class='a'>foo</p>\n", render("%p{:class => :a} foo")) # single stringify
|
153
|
+
assert_equal("<p>foo</p>\n", render("%p{:class => false} foo")) # single falsey
|
154
|
+
assert_equal("<p class='a b html'>foo</p>\n", render("%p(class='html'){:class => %w[a b]} foo")) # html attrs
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_id_attr_with_array
|
158
|
+
assert_equal("<p id='a_b'>foo</p>\n", render("%p{:id => %w[a b]} foo")) # basic
|
159
|
+
assert_equal("<p id='css_a_b'>foo</p>\n", render("%p#css{:id => %w[a b]} foo")) # merge with css
|
160
|
+
assert_equal("<p id='a_b_c_d'>foo</p>\n", render("%p{:id => [%w[a b], %w[c d]]} foo")) # flatten
|
161
|
+
assert_equal("<p id='a_b'>foo</p>\n", render("%p{:id => [:a, :b] } foo")) # stringify
|
162
|
+
assert_equal("<p id=''>foo</p>\n", render("%p{:id => [nil, false] } foo")) # strip falsey
|
163
|
+
assert_equal("<p id='a'>foo</p>\n", render("%p{:id => :a} foo")) # single stringify
|
164
|
+
assert_equal("<p>foo</p>\n", render("%p{:id => false} foo")) # single falsey
|
165
|
+
assert_equal("<p id='html_a_b'>foo</p>\n", render("%p(id='html'){:id => %w[a b]} foo")) # html attrs
|
166
|
+
end
|
167
|
+
|
140
168
|
def test_dynamic_attributes_with_no_content
|
141
169
|
assert_equal(<<HTML, render(<<HAML))
|
142
170
|
<p>
|
@@ -148,6 +176,20 @@ HTML
|
|
148
176
|
HAML
|
149
177
|
end
|
150
178
|
|
179
|
+
def test_attributes_with_to_s
|
180
|
+
assert_equal(<<HTML, render(<<HAML))
|
181
|
+
<p id='foo_2'></p>
|
182
|
+
<p class='2 foo'></p>
|
183
|
+
<p blaz='2'></p>
|
184
|
+
<p 2='2'></p>
|
185
|
+
HTML
|
186
|
+
%p#foo{:id => 1+1}
|
187
|
+
%p.foo{:class => 1+1}
|
188
|
+
%p{:blaz => 1+1}
|
189
|
+
%p{(1+1) => 1+1}
|
190
|
+
HAML
|
191
|
+
end
|
192
|
+
|
151
193
|
def test_nil_should_render_empty_tag
|
152
194
|
assert_equal("<div class='no_attributes'></div>",
|
153
195
|
render(".no_attributes{:nil => nil}").chomp)
|
@@ -629,15 +671,6 @@ HAML
|
|
629
671
|
assert_equal("<a href='#\"'></a>\n", render('%a(href="#\\"")'))
|
630
672
|
end
|
631
673
|
|
632
|
-
def test_filter_with_newline_and_interp
|
633
|
-
assert_equal(<<HTML, render(<<HAML))
|
634
|
-
\\n
|
635
|
-
HTML
|
636
|
-
:plain
|
637
|
-
\\n\#{""}
|
638
|
-
HAML
|
639
|
-
end
|
640
|
-
|
641
674
|
# HTML escaping tests
|
642
675
|
|
643
676
|
def test_ampersand_equals_should_escape
|
@@ -817,13 +850,26 @@ HAML
|
|
817
850
|
assert_equal("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n", render("!!! XML", :attr_wrapper => '"'))
|
818
851
|
end
|
819
852
|
|
853
|
+
def test_autoclose_option
|
854
|
+
assert_equal("<flaz foo='bar' />\n", render("%flaz{:foo => 'bar'}", :autoclose => ["flaz"]))
|
855
|
+
assert_equal(<<HTML, render(<<HAML, :autoclose => [/^flaz/]))
|
856
|
+
<flaz />
|
857
|
+
<flaznicate />
|
858
|
+
<flan></flan>
|
859
|
+
HTML
|
860
|
+
%flaz
|
861
|
+
%flaznicate
|
862
|
+
%flan
|
863
|
+
HAML
|
864
|
+
end
|
865
|
+
|
820
866
|
def test_attrs_parsed_correctly
|
821
867
|
assert_equal("<p boom=>biddly='bar => baz'></p>\n", render("%p{'boom=>biddly' => 'bar => baz'}"))
|
822
868
|
assert_equal("<p foo,bar='baz, qux'></p>\n", render("%p{'foo,bar' => 'baz, qux'}"))
|
823
869
|
assert_equal("<p escaped='quo
te'></p>\n", render("%p{ :escaped => \"quo\\nte\"}"))
|
824
870
|
assert_equal("<p escaped='quo4te'></p>\n", render("%p{ :escaped => \"quo\#{2 + 2}te\"}"))
|
825
871
|
end
|
826
|
-
|
872
|
+
|
827
873
|
def test_correct_parsing_with_brackets
|
828
874
|
assert_equal("<p class='foo'>{tada} foo</p>\n", render("%p{:class => 'foo'} {tada} foo"))
|
829
875
|
assert_equal("<p class='foo'>deep {nested { things }}</p>\n", render("%p{:class => 'foo'} deep {nested { things }}"))
|
@@ -962,6 +1008,21 @@ END
|
|
962
1008
|
END
|
963
1009
|
end
|
964
1010
|
|
1011
|
+
def test_css_filter
|
1012
|
+
assert_equal(<<CSS, render(<<SASS))
|
1013
|
+
<style type='text/css'>
|
1014
|
+
/*<![CDATA[*/
|
1015
|
+
#foo {
|
1016
|
+
bar: baz; }
|
1017
|
+
/*]]>*/
|
1018
|
+
</style>
|
1019
|
+
CSS
|
1020
|
+
:css
|
1021
|
+
#foo {
|
1022
|
+
bar: baz; }
|
1023
|
+
SASS
|
1024
|
+
end
|
1025
|
+
|
965
1026
|
def test_local_assigns_dont_modify_class
|
966
1027
|
assert_equal("bar\n", render("= foo", :locals => {:foo => 'bar'}))
|
967
1028
|
assert_equal(nil, defined?(foo))
|
@@ -979,6 +1040,12 @@ END
|
|
979
1040
|
render("%p[user]{:style => 'width: 100px;'} New User", :locals => {:user => user}))
|
980
1041
|
end
|
981
1042
|
|
1043
|
+
def test_object_ref_with_custom_haml_class
|
1044
|
+
custom = CustomHamlClass.new 42
|
1045
|
+
assert_equal("<p class='my_thing' id='my_thing_42' style='width: 100px;'>My Thing</p>\n",
|
1046
|
+
render("%p[custom]{:style => 'width: 100px;'} My Thing", :locals => {:custom => custom}))
|
1047
|
+
end
|
1048
|
+
|
982
1049
|
def test_non_literal_attributes
|
983
1050
|
assert_equal("<p a1='foo' a2='bar' a3='baz' />\n",
|
984
1051
|
render("%p{a2, a1, :a3 => 'baz'}/",
|
@@ -1133,6 +1200,47 @@ END
|
|
1133
1200
|
assert_equal %{<!DOCTYPE html>\n}, render('!!!', :format => :html5)
|
1134
1201
|
end
|
1135
1202
|
|
1203
|
+
# HTML5 custom data attributes
|
1204
|
+
def test_html5_data_attributes
|
1205
|
+
assert_equal("<div data-author_id='123' data-biz='baz' data-foo='bar'></div>\n",
|
1206
|
+
render("%div{:data => {:author_id => 123, :foo => 'bar', :biz => 'baz'}}"))
|
1207
|
+
|
1208
|
+
assert_equal("<div data-one_plus_one='2'></div>\n",
|
1209
|
+
render("%div{:data => {:one_plus_one => 1+1}}"))
|
1210
|
+
|
1211
|
+
assert_equal("<div data-foo='Here's a \"quoteful\" string.'></div>\n",
|
1212
|
+
render(%{%div{:data => {:foo => %{Here's a "quoteful" string.}}}})) #'
|
1213
|
+
end
|
1214
|
+
|
1215
|
+
def test_html5_data_attributes_with_multiple_defs
|
1216
|
+
# Should always use the more-explicit attribute
|
1217
|
+
assert_equal("<div data-foo='second'></div>\n",
|
1218
|
+
render("%div{:data => {:foo => 'first'}, 'data-foo' => 'second'}"))
|
1219
|
+
assert_equal("<div data-foo='first'></div>\n",
|
1220
|
+
render("%div{'data-foo' => 'first', :data => {:foo => 'second'}}"))
|
1221
|
+
end
|
1222
|
+
|
1223
|
+
def test_html5_data_attributes_with_attr_method
|
1224
|
+
Haml::Helpers.module_eval do
|
1225
|
+
def data_hash
|
1226
|
+
{:data => {:foo => "bar", :baz => "bang"}}
|
1227
|
+
end
|
1228
|
+
|
1229
|
+
def data_val
|
1230
|
+
{:data => "dat"}
|
1231
|
+
end
|
1232
|
+
end
|
1233
|
+
|
1234
|
+
assert_equal("<div data-baz='bang' data-brat='wurst' data-foo='blip'></div>\n",
|
1235
|
+
render("%div{data_hash, :data => {:foo => 'blip', :brat => 'wurst'}}"))
|
1236
|
+
assert_equal("<div data-baz='bang' data-foo='blip'></div>\n",
|
1237
|
+
render("%div{data_hash, 'data-foo' => 'blip'}"))
|
1238
|
+
assert_equal("<div data-baz='bang' data-foo='bar' data='dat'></div>\n",
|
1239
|
+
render("%div{data_hash, :data => 'dat'}"))
|
1240
|
+
assert_equal("<div data-brat='wurst' data-foo='blip' data='dat'></div>\n",
|
1241
|
+
render("%div{data_val, :data => {:foo => 'blip', :brat => 'wurst'}}"))
|
1242
|
+
end
|
1243
|
+
|
1136
1244
|
# New attributes
|
1137
1245
|
|
1138
1246
|
def test_basic_new_attributes
|
@@ -1233,6 +1341,17 @@ END
|
|
1233
1341
|
|
1234
1342
|
# Encodings
|
1235
1343
|
|
1344
|
+
def test_utf_8_bom
|
1345
|
+
assert_equal <<CSS, render(<<SCSS)
|
1346
|
+
<div class='foo'>
|
1347
|
+
<p>baz</p>
|
1348
|
+
</div>
|
1349
|
+
CSS
|
1350
|
+
\xEF\xBB\xBF.foo
|
1351
|
+
%p baz
|
1352
|
+
SCSS
|
1353
|
+
end
|
1354
|
+
|
1236
1355
|
unless Haml::Util.ruby1_8?
|
1237
1356
|
def test_default_encoding
|
1238
1357
|
assert_equal(Encoding.find("utf-8"), render(<<HAML.encode("us-ascii")).encoding)
|
@@ -1277,6 +1396,24 @@ HAML
|
|
1277
1396
|
o.render
|
1278
1397
|
end
|
1279
1398
|
end
|
1399
|
+
|
1400
|
+
def test_encoding_error
|
1401
|
+
render("foo\nbar\nb\xFEaz".force_encoding("utf-8"))
|
1402
|
+
assert(false, "Expected exception")
|
1403
|
+
rescue Haml::Error => e
|
1404
|
+
assert_equal(3, e.line)
|
1405
|
+
assert_equal('Invalid UTF-8 character "\xFE"', e.message)
|
1406
|
+
end
|
1407
|
+
|
1408
|
+
def test_ascii_incompatible_encoding_error
|
1409
|
+
template = "foo\nbar\nb_z".encode("utf-16le")
|
1410
|
+
template[9] = "\xFE".force_encoding("utf-16le")
|
1411
|
+
render(template)
|
1412
|
+
assert(false, "Expected exception")
|
1413
|
+
rescue Haml::Error => e
|
1414
|
+
assert_equal(3, e.line)
|
1415
|
+
assert_equal('Invalid UTF-16LE character "\xFE"', e.message)
|
1416
|
+
end
|
1280
1417
|
end
|
1281
1418
|
|
1282
1419
|
private
|
File without changes
|
data/test/haml/helper_test.rb
CHANGED
@@ -15,18 +15,7 @@ module Haml::Helpers
|
|
15
15
|
end
|
16
16
|
|
17
17
|
class HelperTest < Test::Unit::TestCase
|
18
|
-
Post = Struct.new('Post', :body
|
19
|
-
class PostErrors
|
20
|
-
def on(name)
|
21
|
-
return unless name == 'error_field'
|
22
|
-
["Really bad error"]
|
23
|
-
end
|
24
|
-
alias_method :full_messages, :on
|
25
|
-
|
26
|
-
def [](name)
|
27
|
-
on(name) || []
|
28
|
-
end
|
29
|
-
end
|
18
|
+
Post = Struct.new('Post', :body)
|
30
19
|
|
31
20
|
def setup
|
32
21
|
@base = ActionView::Base.new
|
@@ -37,7 +26,7 @@ class HelperTest < Test::Unit::TestCase
|
|
37
26
|
@base.controller.response = ActionController::Response.new
|
38
27
|
end
|
39
28
|
|
40
|
-
@base.instance_variable_set('@post', Post.new("Foo bar\nbaz"
|
29
|
+
@base.instance_variable_set('@post', Post.new("Foo bar\nbaz"))
|
41
30
|
end
|
42
31
|
|
43
32
|
def render(text, options = {})
|
@@ -164,16 +153,48 @@ HTML
|
|
164
153
|
HAML
|
165
154
|
end
|
166
155
|
|
167
|
-
def
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
156
|
+
def test_haml_tag_name_attribute_with_id
|
157
|
+
assert_equal("<p id='some_id'></p>\n", render("- haml_tag 'p#some_id'"))
|
158
|
+
end
|
159
|
+
|
160
|
+
def test_haml_tag_without_name_but_with_id
|
161
|
+
assert_equal("<div id='some_id'></div>\n", render("- haml_tag '#some_id'"))
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_haml_tag_without_name_but_with_class
|
165
|
+
assert_equal("<div class='foo'></div>\n", render("- haml_tag '.foo'"))
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_haml_tag_name_with_id_and_class
|
169
|
+
assert_equal("<p class='foo' id='some_id'></p>\n", render("- haml_tag 'p#some_id.foo'"))
|
170
|
+
end
|
171
|
+
|
172
|
+
def test_haml_tag_name_with_class
|
173
|
+
assert_equal("<p class='foo'></p>\n", render("- haml_tag 'p.foo'"))
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_haml_tag_name_with_class_and_id
|
177
|
+
assert_equal("<p class='foo' id='some_id'></p>\n", render("- haml_tag 'p.foo#some_id'"))
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_haml_tag_name_with_id_and_multiple_classes
|
181
|
+
assert_equal("<p class='foo bar' id='some_id'></p>\n", render("- haml_tag 'p#some_id.foo.bar'"))
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_haml_tag_name_with_multiple_classes_and_id
|
185
|
+
assert_equal("<p class='foo bar' id='some_id'></p>\n", render("- haml_tag 'p.foo.bar#some_id'"))
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_haml_tag_name_and_attribute_classes_merging
|
189
|
+
assert_equal("<p class='foo bar' id='some_id'></p>\n", render("- haml_tag 'p#some_id.foo', :class => 'bar'"))
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_haml_tag_name_and_attribute_classes_merging
|
193
|
+
assert_equal("<p class='bar foo'></p>\n", render("- haml_tag 'p.foo', :class => 'bar'"))
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_haml_tag_name_merges_id_and_attribute_id
|
197
|
+
assert_equal("<p id='foo_bar'></p>\n", render("- haml_tag 'p#foo', :id => 'bar'"))
|
177
198
|
end
|
178
199
|
|
179
200
|
def test_haml_tag_attribute_html_escaping
|
@@ -184,6 +205,16 @@ HAML
|
|
184
205
|
assert_equal("<br class='foo' />\n", render("- haml_tag :br, :class => 'foo'"))
|
185
206
|
end
|
186
207
|
|
208
|
+
def test_haml_tag_with_class_array
|
209
|
+
assert_equal("<p class='a b'>foo</p>\n", render("- haml_tag :p, 'foo', :class => %w[a b]"))
|
210
|
+
assert_equal("<p class='a b c d'>foo</p>\n", render("- haml_tag 'p.c.d', 'foo', :class => %w[a b]"))
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_haml_tag_with_id_array
|
214
|
+
assert_equal("<p id='a_b'>foo</p>\n", render("- haml_tag :p, 'foo', :id => %w[a b]"))
|
215
|
+
assert_equal("<p id='c_a_b'>foo</p>\n", render("- haml_tag 'p#c', 'foo', :id => %w[a b]"))
|
216
|
+
end
|
217
|
+
|
187
218
|
def test_haml_tag_non_autoclosed_tags_arent_closed
|
188
219
|
assert_equal("<p></p>\n", render("- haml_tag :p"))
|
189
220
|
end
|
@@ -208,6 +239,42 @@ HAML
|
|
208
239
|
assert_raise(Haml::Error) { render("= haml_tag :p") }
|
209
240
|
end
|
210
241
|
|
242
|
+
def test_haml_tag_with_multiline_string
|
243
|
+
assert_equal(<<HTML, render(<<HAML))
|
244
|
+
<p>
|
245
|
+
foo
|
246
|
+
bar
|
247
|
+
baz
|
248
|
+
</p>
|
249
|
+
HTML
|
250
|
+
- haml_tag :p, "foo\\nbar\\nbaz"
|
251
|
+
HAML
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_haml_concat_with_multiline_string
|
255
|
+
assert_equal(<<HTML, render(<<HAML))
|
256
|
+
<p>
|
257
|
+
foo
|
258
|
+
bar
|
259
|
+
baz
|
260
|
+
</p>
|
261
|
+
HTML
|
262
|
+
%p
|
263
|
+
- haml_concat "foo\\nbar\\nbaz"
|
264
|
+
HAML
|
265
|
+
end
|
266
|
+
|
267
|
+
def test_haml_tag_with_ugly
|
268
|
+
assert_equal(<<HTML, render(<<HAML, :ugly => true))
|
269
|
+
<p>
|
270
|
+
<strong>Hi!</strong>
|
271
|
+
</p>
|
272
|
+
HTML
|
273
|
+
- haml_tag :p do
|
274
|
+
- haml_tag :strong, "Hi!"
|
275
|
+
HAML
|
276
|
+
end
|
277
|
+
|
211
278
|
def test_is_haml
|
212
279
|
assert(!ActionView::Base.new.is_haml?)
|
213
280
|
assert_equal("true\n", render("= is_haml?"))
|
@@ -291,7 +358,7 @@ MESSAGE
|
|
291
358
|
render("%p foo\n= haml_concat 'foo'\n%p bar")
|
292
359
|
assert false, "Expected Haml::Error"
|
293
360
|
rescue Haml::Error => e
|
294
|
-
assert_equal 2, e.backtrace[
|
361
|
+
assert_equal 2, e.backtrace[1].scan(/:(\d+)/).first.first.to_i
|
295
362
|
end
|
296
363
|
|
297
364
|
def test_error_return_line_in_helper
|