faml 0.6.3 → 0.6.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +3 -0
- data/CHANGELOG.md +4 -0
- data/Rakefile +8 -4
- data/ext/attribute_builder/attribute_builder.c +7 -2
- data/incompatibilities/README.md +3 -1
- data/incompatibilities/spec/render/array_attribute_spec.md +301 -0
- data/incompatibilities/spec/render/attribute_spec.md +43 -368
- data/incompatibilities/spec/render/hash_attribute_spec.md +120 -0
- data/lib/faml/version.rb +1 -1
- data/spec/render/array_attribute_spec.rb +85 -0
- data/spec/render/attribute_spec.rb +15 -154
- data/spec/render/hash_attribute_spec.rb +66 -0
- data/spec/spec_helper.rb +14 -0
- metadata +10 -2
@@ -0,0 +1,120 @@
|
|
1
|
+
# [./spec/render/hash_attribute_spec.rb:5](../../../spec/render/hash_attribute_spec.rb#L5)
|
2
|
+
## Input
|
3
|
+
```haml
|
4
|
+
%span{foo: {bar: 1+2}} hello
|
5
|
+
```
|
6
|
+
|
7
|
+
## Faml
|
8
|
+
```html
|
9
|
+
<span foo='{:bar=>3}'>hello</span>
|
10
|
+
|
11
|
+
```
|
12
|
+
|
13
|
+
## Haml, Hamlit
|
14
|
+
```html
|
15
|
+
<span foo-bar='3'>hello</span>
|
16
|
+
|
17
|
+
```
|
18
|
+
|
19
|
+
# [./spec/render/hash_attribute_spec.rb:9](../../../spec/render/hash_attribute_spec.rb#L9)
|
20
|
+
## Input
|
21
|
+
```haml
|
22
|
+
- attrs = { foo: 1, bar: { hoge: :fuga }, baz: true }
|
23
|
+
%span{attrs} hello
|
24
|
+
|
25
|
+
```
|
26
|
+
|
27
|
+
## Faml
|
28
|
+
```html
|
29
|
+
<span bar='{:hoge=>:fuga}' baz foo='1'>hello</span>
|
30
|
+
|
31
|
+
```
|
32
|
+
|
33
|
+
## Haml
|
34
|
+
```html
|
35
|
+
<span bar-hoge='fuga' baz foo='1'>hello</span>
|
36
|
+
|
37
|
+
```
|
38
|
+
|
39
|
+
## Hamlit
|
40
|
+
```html
|
41
|
+
<span foo='1' bar-hoge='fuga' baz>hello</span>
|
42
|
+
|
43
|
+
```
|
44
|
+
|
45
|
+
# [./spec/render/hash_attribute_spec.rb:16](../../../spec/render/hash_attribute_spec.rb#L16)
|
46
|
+
## Input
|
47
|
+
```haml
|
48
|
+
- data = { foo: 1 }
|
49
|
+
%span{foo: {bar: "x#{1}y"}} hello
|
50
|
+
|
51
|
+
```
|
52
|
+
|
53
|
+
## Faml
|
54
|
+
```html
|
55
|
+
<span foo='{:bar=>"x1y"}'>hello</span>
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
## Haml, Hamlit
|
60
|
+
```html
|
61
|
+
<span foo-bar='x1y'>hello</span>
|
62
|
+
|
63
|
+
```
|
64
|
+
|
65
|
+
# [./spec/render/hash_attribute_spec.rb:37](../../../spec/render/hash_attribute_spec.rb#L37)
|
66
|
+
## Input
|
67
|
+
```haml
|
68
|
+
%span{data: {foo: 1, bar: 'baz', :hoge => :fuga, k1: { k2: 'v3' }}} hello
|
69
|
+
```
|
70
|
+
|
71
|
+
## Faml, Haml
|
72
|
+
```html
|
73
|
+
<span data-bar='baz' data-foo='1' data-hoge='fuga' data-k1-k2='v3'>hello</span>
|
74
|
+
|
75
|
+
```
|
76
|
+
|
77
|
+
## Hamlit
|
78
|
+
```html
|
79
|
+
<span data-foo='1' data-bar='baz' data-hoge='fuga' data-k1-k2='v3'>hello</span>
|
80
|
+
|
81
|
+
```
|
82
|
+
|
83
|
+
# [./spec/render/hash_attribute_spec.rb:45](../../../spec/render/hash_attribute_spec.rb#L45)
|
84
|
+
## Input
|
85
|
+
```haml
|
86
|
+
%span{data: {foo: 1, bar: 2+3}} hello
|
87
|
+
```
|
88
|
+
|
89
|
+
## Faml, Haml
|
90
|
+
```html
|
91
|
+
<span data-bar='5' data-foo='1'>hello</span>
|
92
|
+
|
93
|
+
```
|
94
|
+
|
95
|
+
## Hamlit
|
96
|
+
```html
|
97
|
+
<span data-foo='1' data-bar='5'>hello</span>
|
98
|
+
|
99
|
+
```
|
100
|
+
|
101
|
+
# [./spec/render/hash_attribute_spec.rb:49](../../../spec/render/hash_attribute_spec.rb#L49)
|
102
|
+
## Input
|
103
|
+
```haml
|
104
|
+
- data = { foo: 1, bar: 2 }
|
105
|
+
%span{data: data} hello
|
106
|
+
|
107
|
+
```
|
108
|
+
|
109
|
+
## Faml, Haml
|
110
|
+
```html
|
111
|
+
<span data-bar='2' data-foo='1'>hello</span>
|
112
|
+
|
113
|
+
```
|
114
|
+
|
115
|
+
## Hamlit
|
116
|
+
```html
|
117
|
+
<span data-foo='1' data-bar='2'>hello</span>
|
118
|
+
|
119
|
+
```
|
120
|
+
|
data/lib/faml/version.rb
CHANGED
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
RSpec.describe 'Array attributes rendering', type: :render do
|
5
|
+
describe 'class' do
|
6
|
+
it 'renders array class' do
|
7
|
+
with_each_attribute_type(:class, '"c1"', klass: 'c2') do |str|
|
8
|
+
expect(render_string(str)).to eq("<span class='c1 c2'></span>\n")
|
9
|
+
end
|
10
|
+
with_each_attribute_type(:class, '["c1", "c3", :c2]', klass: 'c2') do |str|
|
11
|
+
expect(render_string(str)).to eq("<span class='c1 c2 c3'></span>\n")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'merges classes' do
|
16
|
+
expect(render_string(<<HAML)).to eq("<span class='c1 c2 content {}' id='main_id1_id3_id2'>hello</span>\n")
|
17
|
+
- h1 = {class: 'c1', id: ['id1', 'id3']}
|
18
|
+
- h2 = {class: [{}, 'c2'], id: 'id2'}
|
19
|
+
%span#main.content{h1, h2} hello
|
20
|
+
HAML
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'remove duplicated classes' do
|
24
|
+
with_each_attribute_type(:class, ':foo', klass: 'foo') do |str|
|
25
|
+
expect(render_string(str)).to eq("<span class='foo'></span>\n")
|
26
|
+
end
|
27
|
+
with_each_attribute_type(:class, '"foo bar"', klass: 'foo') do |str|
|
28
|
+
expect(render_string(str)).to eq("<span class='bar foo'></span>\n")
|
29
|
+
end
|
30
|
+
with_each_attribute_type(:class, '%w[foo bar]', klass: 'foo') do |str|
|
31
|
+
expect(render_string(str)).to eq("<span class='bar foo'></span>\n")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'skips empty array class' do
|
36
|
+
with_each_attribute_type(:class, '[]') do |str|
|
37
|
+
expect(render_string(str)).to eq("<span></span>\n")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'skips falsey array elements in class' do
|
42
|
+
with_each_attribute_type(:class, '[1, nil, false, true]') do |str|
|
43
|
+
expect(render_string(str)).to eq("<span class='1 true'></span>\n")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'flattens array class' do
|
48
|
+
with_each_attribute_type(:class, '[[1, [2]]]') do |str|
|
49
|
+
expect(render_string(str)).to eq("<span class='1 2'></span>\n")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'merges static class' do
|
54
|
+
with_each_attribute_type(:class, '"bar"', tag: 'div', klass: 'foo', text: 'baz') do |str|
|
55
|
+
expect(render_string(str)).to eq("<div class='bar foo'>baz</div>\n")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe 'id' do
|
61
|
+
it 'skips empty array id' do
|
62
|
+
with_each_attribute_type(:id, '[]') do |str|
|
63
|
+
expect(render_string(str)).to eq("<span></span>\n")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'skips falsey array elements in id' do
|
68
|
+
with_each_attribute_type(:id, '[1, nil, false, true]') do |str|
|
69
|
+
expect(render_string(str)).to eq("<span id='1_true'></span>\n")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'flattens array id' do
|
74
|
+
with_each_attribute_type(:id, '[1, [2]]') do |str|
|
75
|
+
expect(render_string(str)).to eq("<span id='1_2'></span>\n")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'merges static id' do
|
80
|
+
with_each_attribute_type(:id, '"bar"', tag: 'div', id: 'foo', text: 'baz') do |str|
|
81
|
+
expect(render_string(str)).to eq("<div id='foo_bar'>baz</div>\n")
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -29,89 +29,28 @@ RSpec.describe 'Attributes rendering', type: :render do
|
|
29
29
|
expect(render_string(%q|%span#main{class: "na#{'ni'}ka"} hello|)).to eq(%Q{<span class='nanika' id='main'>hello</span>\n})
|
30
30
|
end
|
31
31
|
|
32
|
-
it 'renders array class' do
|
33
|
-
expect(render_string('%span.c2{class: "c1"}')).to eq("<span class='c1 c2'></span>\n")
|
34
|
-
expect(render_string('%span.c2{class: ["c1", "c3", :c2]}')).to eq("<span class='c1 c2 c3'></span>\n")
|
35
|
-
end
|
36
|
-
|
37
32
|
it 'renders boolean attributes' do
|
38
|
-
|
39
|
-
|
40
|
-
expect(render_string('%input{checked: nil}')).to eq("<input>\n")
|
41
|
-
expect(render_string('%input{checked: "a" == "a"}')).to eq("<input checked>\n")
|
42
|
-
expect(render_string('%input{checked: "a" != "a"}')).to eq("<input>\n")
|
43
|
-
expect(render_string("- x = nil\n%input{checked: x}")).to eq("<input>\n")
|
44
|
-
expect(render_string("- h = {checked: true}\n%input{h}")).to eq("<input checked>\n")
|
45
|
-
expect(render_string("- h = {checked: false}\n%input{h}")).to eq("<input>\n")
|
46
|
-
expect(render_string("- h = {checked: nil}\n%input{h}")).to eq("<input>\n")
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'merges classes' do
|
50
|
-
expect(render_string(<<HAML)).to eq("<span class='c1 c2 content {}' id='main_id1_id3_id2'>hello</span>\n")
|
51
|
-
- h1 = {class: 'c1', id: ['id1', 'id3']}
|
52
|
-
- h2 = {class: [{}, 'c2'], id: 'id2'}
|
53
|
-
%span#main.content{h1, h2} hello
|
54
|
-
HAML
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'strigify non-string classes' do
|
58
|
-
expect(render_string('%span.foo{class: :bar} hello')).to eq("<span class='bar foo'>hello</span>\n")
|
59
|
-
expect(render_string('%span.foo{class: 1} hello')).to eq("<span class='1 foo'>hello</span>\n")
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'remove duplicated classes' do
|
63
|
-
aggregate_failures do
|
64
|
-
expect(render_string('%span.foo{class: :foo}')).to eq("<span class='foo'></span>\n")
|
65
|
-
expect(render_string('%span.foo{class: "foo bar"}')).to eq("<span class='bar foo'></span>\n")
|
66
|
-
expect(render_string('%span.foo{class: %w[foo bar]}')).to eq("<span class='bar foo'></span>\n")
|
33
|
+
with_each_attribute_type(:checked, 'true', tag: 'input') do |str|
|
34
|
+
expect(render_string(str)).to eq("<input checked>\n")
|
67
35
|
end
|
68
|
-
|
69
|
-
expect(render_string(
|
70
|
-
expect(render_string("- v = 'foo bar'\n%span.foo{class: v}")).to eq("<span class='bar foo'></span>\n")
|
71
|
-
expect(render_string("- v = %w[foo bar]\n%span.foo{class: v}")).to eq("<span class='bar foo'></span>\n")
|
36
|
+
with_each_attribute_type(:checked, 'false', tag: 'input') do |str|
|
37
|
+
expect(render_string(str)).to eq("<input>\n")
|
72
38
|
end
|
73
|
-
|
74
|
-
expect(render_string(
|
75
|
-
expect(render_string("- h = {class: 'foo bar'}\n%span.foo{h}")).to eq("<span class='bar foo'></span>\n")
|
76
|
-
expect(render_string("- h = {class: %w[foo bar]}\n%span.foo{h}")).to eq("<span class='bar foo'></span>\n")
|
39
|
+
with_each_attribute_type(:checked, 'nil', tag: 'input') do |str|
|
40
|
+
expect(render_string(str)).to eq("<input>\n")
|
77
41
|
end
|
78
42
|
end
|
79
43
|
|
80
|
-
it 'skips empty array class' do
|
81
|
-
expect(render_string('%span{class: []}')).to eq("<span></span>\n")
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'skips falsey array elements in class' do
|
85
|
-
expect(render_string('%span{class: [1, nil, false, true]}')).to eq("<span class='1 true'></span>\n")
|
86
|
-
expect(render_string("- v = [1, nil, false, true]\n%span{class: v}")).to eq("<span class='1 true'></span>\n")
|
87
|
-
expect(render_string("- h = { class: [1, nil, false, true] }\n%span{h}")).to eq("<span class='1 true'></span>\n")
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'strigify non-string ids' do
|
91
|
-
expect(render_string('%span#foo{id: :bar} hello')).to eq("<span id='foo_bar'>hello</span>\n")
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'skips empty array class' do
|
95
|
-
expect(render_string('%span{id: []}')).to eq("<span></span>\n")
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'skips falsey array elements in id' do
|
99
|
-
expect(render_string('%span{id: [1, nil, false, true]}')).to eq("<span id='1_true'></span>\n")
|
100
|
-
expect(render_string("- v = [1, nil, false, true]\n%span{id: v}")).to eq("<span id='1_true'></span>\n")
|
101
|
-
expect(render_string("- h = { id: [1, nil, false, true] }\n%span{h}")).to eq("<span id='1_true'></span>\n")
|
102
|
-
end
|
103
|
-
|
104
44
|
it 'escapes' do
|
105
|
-
|
45
|
+
with_each_attribute_type(:foo, %q|"x\"y'z"|, text: 'hello') do |str|
|
46
|
+
expect(render_string(str)).to eq(%Q{<span foo='x"y'z'>hello</span>\n})
|
47
|
+
end
|
106
48
|
end
|
107
49
|
|
108
50
|
it 'does not escape slash' do
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
it 'renders only name if value is true' do
|
114
|
-
expect(render_string(%q|%span{foo: true, bar: 1} hello|)).to eq(%Q{<span bar='1' foo>hello</span>\n})
|
51
|
+
with_each_attribute_type(:href, "'http://example.com/'", tag: 'a') do |str|
|
52
|
+
expect(render_string(str)).to eq(%Q{<a href='http://example.com/'></a>\n})
|
53
|
+
end
|
115
54
|
end
|
116
55
|
|
117
56
|
it 'raises error when unparsable Ruby code is given' do
|
@@ -120,23 +59,12 @@ HAML
|
|
120
59
|
|
121
60
|
context 'with xhtml format' do
|
122
61
|
it 'renders name="name" if value is true' do
|
123
|
-
|
124
|
-
|
125
|
-
|
62
|
+
with_each_attribute_type(:foo, 'true', text: 'hello') do |str|
|
63
|
+
expect(render_string(str, format: :xhtml)).to eq(%Q{<span foo='foo'>hello</span>\n})
|
64
|
+
end
|
126
65
|
end
|
127
66
|
end
|
128
67
|
|
129
|
-
it 'renders nested attributes' do
|
130
|
-
expect(render_string(%q|%span{foo: {bar: 1+2}} hello|)).to eq(%Q|<span foo='{:bar=>3}'>hello</span>\n|)
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'renders code attributes' do
|
134
|
-
expect(render_string(<<HAML)).to eq(%Q|<span bar='{:hoge=>:fuga}' baz foo='1'>hello</span>\n|)
|
135
|
-
- attrs = { foo: 1, bar: { hoge: :fuga }, baz: true }
|
136
|
-
%span{attrs} hello
|
137
|
-
HAML
|
138
|
-
end
|
139
|
-
|
140
68
|
it 'renders dstr attributes' do
|
141
69
|
expect(render_string(<<HAML)).to eq(%Q|<span data='x{:foo=>1}y'>hello</span>\n|)
|
142
70
|
- data = { foo: 1 }
|
@@ -144,73 +72,6 @@ HAML
|
|
144
72
|
HAML
|
145
73
|
end
|
146
74
|
|
147
|
-
it 'renders nested dstr attributes' do
|
148
|
-
expect(render_string(<<'HAML')).to eq(%Q|<span foo='{:bar=>"x1y"}'>hello</span>\n|)
|
149
|
-
- data = { foo: 1 }
|
150
|
-
%span{foo: {bar: "x#{1}y"}} hello
|
151
|
-
HAML
|
152
|
-
end
|
153
|
-
|
154
|
-
it 'renders data-id and data-class (#38)' do
|
155
|
-
aggregate_failures do
|
156
|
-
expect(render_string('%span{data: {id: 1}}')).to eq("<span data-id='1'></span>\n")
|
157
|
-
expect(render_string('%span{data: {class: 1}}')).to eq("<span data-class='1'></span>\n")
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
it 'optimize send case' do
|
162
|
-
expect(render_string('%span{foo: {bar: 1+2}} hello')).to eq("<span foo='{:bar=>3}'>hello</span>\n")
|
163
|
-
end
|
164
|
-
|
165
|
-
it 'merges static id' do
|
166
|
-
expect(render_string('#foo{id: "bar"} baz')).to eq("<div id='foo_bar'>baz</div>\n")
|
167
|
-
expect(render_string('#foo{id: %w[bar baz]} hoge')).to eq("<div id='foo_bar_baz'>hoge</div>\n")
|
168
|
-
end
|
169
|
-
|
170
|
-
it 'merges static class' do
|
171
|
-
expect(render_string('.foo{class: "bar"} baz')).to eq("<div class='bar foo'>baz</div>\n")
|
172
|
-
expect(render_string(<<'HAML')).to eq("<div class='bar foo'>baz</div>\n")
|
173
|
-
- bar = 'bar'
|
174
|
-
.foo{class: "#{bar}"} baz
|
175
|
-
HAML
|
176
|
-
end
|
177
|
-
|
178
|
-
it 'converts underscore to hyphen in data attributes' do
|
179
|
-
expect(render_string("%span{data: {foo_bar: 'baz'}}")).to eq("<span data-foo-bar='baz'></span>\n")
|
180
|
-
expect(render_string("- h = {foo_bar: 'baz'}\n%span{data: h}")).to eq("<span data-foo-bar='baz'></span>\n")
|
181
|
-
end
|
182
|
-
|
183
|
-
context 'with data attributes' do
|
184
|
-
it 'renders nested attributes' do
|
185
|
-
expect(render_string(%q|%span{data: {foo: 1, bar: 'baz', :hoge => :fuga, k1: { k2: 'v3' }}} hello|)).to eq(%Q{<span data-bar='baz' data-foo='1' data-hoge='fuga' data-k1-k2='v3'>hello</span>\n})
|
186
|
-
end
|
187
|
-
|
188
|
-
it 'renders nested dynamic attributes' do
|
189
|
-
expect(render_string(%q|%span{data: {foo: "b#{'a'}r"}} hello|)).to eq(%Q{<span data-foo='bar'>hello</span>\n})
|
190
|
-
end
|
191
|
-
|
192
|
-
it 'renders nested attributes' do
|
193
|
-
expect(render_string(%q|%span{data: {foo: 1, bar: 2+3}} hello|)).to eq(%Q{<span data-bar='5' data-foo='1'>hello</span>\n})
|
194
|
-
end
|
195
|
-
|
196
|
-
it 'renders nested code attributes' do
|
197
|
-
expect(render_string(<<HAML)).to eq(%Q{<span data-bar='2' data-foo='1'>hello</span>\n})
|
198
|
-
- data = { foo: 1, bar: 2 }
|
199
|
-
%span{data: data} hello
|
200
|
-
HAML
|
201
|
-
end
|
202
|
-
|
203
|
-
it 'skips falsey data attributes' do
|
204
|
-
expect(render_string('%span{data: { foo: nil }}')).to eq("<span></span>\n")
|
205
|
-
expect(render_string("- v = nil\n%span{data: { foo: v }}")).to eq("<span></span>\n")
|
206
|
-
end
|
207
|
-
|
208
|
-
it 'renders true data attributes' do
|
209
|
-
expect(render_string('%span{data: { foo: true }}')).to eq("<span data-foo></span>\n")
|
210
|
-
expect(render_string("- v = true\n%span{data: { foo: v }}")).to eq("<span data-foo></span>\n")
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
75
|
it 'renders __LINE__ correctly' do
|
215
76
|
expect(render_string(<<HAML)).to eq("<span a='2' b='1'></span>\n")
|
216
77
|
%span{b: __LINE__,
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen-string-literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
RSpec.describe 'Hash attributes rendering', type: :render do
|
5
|
+
it 'renders nested attributes' do
|
6
|
+
expect(render_string(%q|%span{foo: {bar: 1+2}} hello|)).to eq(%Q|<span foo='{:bar=>3}'>hello</span>\n|)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'renders code attributes' do
|
10
|
+
expect(render_string(<<HAML)).to eq(%Q|<span bar='{:hoge=>:fuga}' baz foo='1'>hello</span>\n|)
|
11
|
+
- attrs = { foo: 1, bar: { hoge: :fuga }, baz: true }
|
12
|
+
%span{attrs} hello
|
13
|
+
HAML
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'renders nested dstr attributes' do
|
17
|
+
expect(render_string(<<'HAML')).to eq(%Q|<span foo='{:bar=>"x1y"}'>hello</span>\n|)
|
18
|
+
- data = { foo: 1 }
|
19
|
+
%span{foo: {bar: "x#{1}y"}} hello
|
20
|
+
HAML
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'renders data-id and data-class (#38)' do
|
24
|
+
aggregate_failures do
|
25
|
+
expect(render_string('%span{data: {id: 1}}')).to eq("<span data-id='1'></span>\n")
|
26
|
+
expect(render_string('%span{data: {class: 1}}')).to eq("<span data-class='1'></span>\n")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'converts underscore to hyphen in data attributes' do
|
31
|
+
with_each_attribute_type(:data, '{foo_bar: "baz"}') do |str|
|
32
|
+
expect(render_string(str)).to eq("<span data-foo-bar='baz'></span>\n")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'data attributes' do
|
37
|
+
it 'renders nested attributes' do
|
38
|
+
expect(render_string(%q|%span{data: {foo: 1, bar: 'baz', :hoge => :fuga, k1: { k2: 'v3' }}} hello|)).to eq(%Q{<span data-bar='baz' data-foo='1' data-hoge='fuga' data-k1-k2='v3'>hello</span>\n})
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'renders nested dynamic attributes' do
|
42
|
+
expect(render_string(%q|%span{data: {foo: "b#{'a'}r"}} hello|)).to eq(%Q{<span data-foo='bar'>hello</span>\n})
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'renders nested attributes' do
|
46
|
+
expect(render_string(%q|%span{data: {foo: 1, bar: 2+3}} hello|)).to eq(%Q{<span data-bar='5' data-foo='1'>hello</span>\n})
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'renders nested code attributes' do
|
50
|
+
expect(render_string(<<HAML)).to eq(%Q{<span data-bar='2' data-foo='1'>hello</span>\n})
|
51
|
+
- data = { foo: 1, bar: 2 }
|
52
|
+
%span{data: data} hello
|
53
|
+
HAML
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'skips falsey data attributes' do
|
57
|
+
expect(render_string('%span{data: { foo: nil }}')).to eq("<span></span>\n")
|
58
|
+
expect(render_string("- v = nil\n%span{data: { foo: v }}")).to eq("<span></span>\n")
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'renders true data attributes' do
|
62
|
+
expect(render_string('%span{data: { foo: true }}')).to eq("<span data-foo></span>\n")
|
63
|
+
expect(render_string("- v = true\n%span{data: { foo: v }}")).to eq("<span data-foo></span>\n")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|