faml 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/ext/attribute_builder/attribute_builder.c +9 -5
- data/incompatibilities/README.md +1 -1
- data/incompatibilities/spec/render/attribute_spec.md +161 -13
- data/lib/faml/compiler.rb +2 -2
- data/lib/faml/version.rb +1 -1
- data/spec/render/attribute_spec.rb +20 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fde0bb641367cd51b35eeeb6d1d5b02211d57054
|
4
|
+
data.tar.gz: 82f60f95e10a5d7b40fd6c2a16f5504a569a9fc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a6f81803cfcc97363081929acf0720d511602fe1057d5057b46de50498559004a162b894b5a809c2a6c9d4258f089689d1544feff72c5968436ada5623f9d61
|
7
|
+
data.tar.gz: e49cfef05e71d400b49c6367e21f1878237fdac8c2798ff34b2a034aa155f416a7f50e51780963181bf11b96f00efe1d0433ea5ffe7b9fd7ea58ae8585b190ad
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## 0.3.5 (2015-10-19)
|
2
|
+
- Fix empty class or id rendering
|
3
|
+
- It's a regression in v0.3.4.
|
4
|
+
- Ignore falsey elements in class or id array
|
5
|
+
- For compatibility with haml
|
6
|
+
- `%span{class: [1, nil, false, true]}` now renders `<span class='1 true'></span>` .
|
7
|
+
|
1
8
|
## 0.3.4 (2015-10-19)
|
2
9
|
- Support array, rational and complex literal optimization
|
3
10
|
- Now `%div{class: %w[foo bar], data: { foo: 1i, bar: 2r }}` is compiled into string literal.
|
@@ -79,7 +79,7 @@ substitute_underscores(VALUE str)
|
|
79
79
|
static int
|
80
80
|
normalize_data_i2(VALUE key, VALUE value, VALUE ptr)
|
81
81
|
{
|
82
|
-
if (
|
82
|
+
if (RTEST(value)) {
|
83
83
|
struct normalize_data_i2_arg *arg = (struct normalize_data_i2_arg *)ptr;
|
84
84
|
VALUE k = rb_str_dup(arg->key);
|
85
85
|
|
@@ -107,7 +107,7 @@ normalize_data_i(VALUE key, VALUE value, VALUE normalized)
|
|
107
107
|
} else if (RB_TYPE_P(value, T_TRUE)) {
|
108
108
|
/* Keep Qtrue value */
|
109
109
|
rb_hash_aset(normalized, key, value);
|
110
|
-
} else if (
|
110
|
+
} else if (!RTEST(value)) {
|
111
111
|
/* Delete falsey values */
|
112
112
|
} else {
|
113
113
|
rb_hash_aset(normalized, key, rb_convert_type(value, T_STRING, "String", "to_s"));
|
@@ -156,7 +156,7 @@ normalize(VALUE hash)
|
|
156
156
|
rb_hash_foreach(data, FOREACH_FUNC(put_data_attribute), hash);
|
157
157
|
} else if (RB_TYPE_P(value, T_TRUE)) {
|
158
158
|
/* Keep Qtrue value */
|
159
|
-
} else if (
|
159
|
+
} else if (!RTEST(value)) {
|
160
160
|
rb_hash_delete(hash, key);
|
161
161
|
} else {
|
162
162
|
rb_hash_aset(hash, key, rb_convert_type(value, T_STRING, "String", "to_s"));
|
@@ -214,7 +214,9 @@ build_attribute(VALUE buf, VALUE attr_quote, int is_html, VALUE key, VALUE value
|
|
214
214
|
VALUE ary = rb_ary_new_capa(len);
|
215
215
|
for (i = 0; i < len; i++) {
|
216
216
|
VALUE v = RARRAY_AREF(value, i);
|
217
|
-
|
217
|
+
if (RTEST(v)) {
|
218
|
+
rb_ary_push(ary, rb_convert_type(v, T_STRING, "String", "to_s"));
|
219
|
+
}
|
218
220
|
}
|
219
221
|
rb_funcall(ary, id_sort_bang, 0);
|
220
222
|
rb_funcall(ary, id_uniq_bang, 0);
|
@@ -230,7 +232,9 @@ build_attribute(VALUE buf, VALUE attr_quote, int is_html, VALUE key, VALUE value
|
|
230
232
|
VALUE ary = rb_ary_new_capa(len);
|
231
233
|
for (i = 0; i < len; i++) {
|
232
234
|
VALUE v = RARRAY_AREF(value, i);
|
233
|
-
|
235
|
+
if (RTEST(v)) {
|
236
|
+
rb_ary_push(ary, rb_convert_type(v, T_STRING, "String", "to_s"));
|
237
|
+
}
|
234
238
|
}
|
235
239
|
put_attribute(buf, attr_quote, key, rb_ary_join(ary, rb_const_get(rb_mAttributeBuilder, id_underscore)));
|
236
240
|
}
|
data/incompatibilities/README.md
CHANGED
@@ -37,9 +37,157 @@
|
|
37
37
|
|
38
38
|
```
|
39
39
|
|
40
|
+
# [./spec/render/attribute_spec.rb:67](../../../spec/render/attribute_spec.rb#L67)
|
41
|
+
## Input
|
42
|
+
```haml
|
43
|
+
%span{class: []}
|
44
|
+
```
|
45
|
+
|
46
|
+
## Faml, Haml
|
47
|
+
```html
|
48
|
+
<span></span>
|
49
|
+
|
50
|
+
```
|
51
|
+
|
52
|
+
## Hamlit
|
53
|
+
```html
|
54
|
+
<span class=''></span>
|
55
|
+
|
56
|
+
```
|
57
|
+
|
58
|
+
# [./spec/render/attribute_spec.rb:71](../../../spec/render/attribute_spec.rb#L71)
|
59
|
+
## Input
|
60
|
+
```haml
|
61
|
+
- v = [1, nil, false, true]
|
62
|
+
%span{class: v}
|
63
|
+
```
|
64
|
+
|
65
|
+
## Faml, Haml
|
66
|
+
```html
|
67
|
+
<span class='1 true'></span>
|
68
|
+
|
69
|
+
```
|
70
|
+
|
71
|
+
## Hamlit
|
72
|
+
```html
|
73
|
+
<span class='1 false true'></span>
|
74
|
+
|
75
|
+
```
|
76
|
+
|
40
77
|
# [./spec/render/attribute_spec.rb:71](../../../spec/render/attribute_spec.rb#L71)
|
41
78
|
## Input
|
42
79
|
```haml
|
80
|
+
- h = { class: [1, nil, false, true] }
|
81
|
+
%span{h}
|
82
|
+
```
|
83
|
+
|
84
|
+
## Faml, Haml
|
85
|
+
```html
|
86
|
+
<span class='1 true'></span>
|
87
|
+
|
88
|
+
```
|
89
|
+
|
90
|
+
## Hamlit
|
91
|
+
```html
|
92
|
+
<span class='1 false true'></span>
|
93
|
+
|
94
|
+
```
|
95
|
+
|
96
|
+
# [./spec/render/attribute_spec.rb:71](../../../spec/render/attribute_spec.rb#L71)
|
97
|
+
## Input
|
98
|
+
```haml
|
99
|
+
%span{class: [1, nil, false, true]}
|
100
|
+
```
|
101
|
+
|
102
|
+
## Faml, Haml
|
103
|
+
```html
|
104
|
+
<span class='1 true'></span>
|
105
|
+
|
106
|
+
```
|
107
|
+
|
108
|
+
## Hamlit
|
109
|
+
```html
|
110
|
+
<span class='1 false true'></span>
|
111
|
+
|
112
|
+
```
|
113
|
+
|
114
|
+
# [./spec/render/attribute_spec.rb:81](../../../spec/render/attribute_spec.rb#L81)
|
115
|
+
## Input
|
116
|
+
```haml
|
117
|
+
%span{id: []}
|
118
|
+
```
|
119
|
+
|
120
|
+
## Faml, Haml
|
121
|
+
```html
|
122
|
+
<span></span>
|
123
|
+
|
124
|
+
```
|
125
|
+
|
126
|
+
## Hamlit
|
127
|
+
```html
|
128
|
+
<span id=''></span>
|
129
|
+
|
130
|
+
```
|
131
|
+
|
132
|
+
# [./spec/render/attribute_spec.rb:85](../../../spec/render/attribute_spec.rb#L85)
|
133
|
+
## Input
|
134
|
+
```haml
|
135
|
+
- v = [1, nil, false, true]
|
136
|
+
%span{id: v}
|
137
|
+
```
|
138
|
+
|
139
|
+
## Faml, Haml
|
140
|
+
```html
|
141
|
+
<span id='1_true'></span>
|
142
|
+
|
143
|
+
```
|
144
|
+
|
145
|
+
## Hamlit
|
146
|
+
```html
|
147
|
+
<span id='1__false_true'></span>
|
148
|
+
|
149
|
+
```
|
150
|
+
|
151
|
+
# [./spec/render/attribute_spec.rb:85](../../../spec/render/attribute_spec.rb#L85)
|
152
|
+
## Input
|
153
|
+
```haml
|
154
|
+
- h = { id: [1, nil, false, true] }
|
155
|
+
%span{h}
|
156
|
+
```
|
157
|
+
|
158
|
+
## Faml, Haml
|
159
|
+
```html
|
160
|
+
<span id='1_true'></span>
|
161
|
+
|
162
|
+
```
|
163
|
+
|
164
|
+
## Hamlit
|
165
|
+
```html
|
166
|
+
<span id='1__false_true'></span>
|
167
|
+
|
168
|
+
```
|
169
|
+
|
170
|
+
# [./spec/render/attribute_spec.rb:85](../../../spec/render/attribute_spec.rb#L85)
|
171
|
+
## Input
|
172
|
+
```haml
|
173
|
+
%span{id: [1, nil, false, true]}
|
174
|
+
```
|
175
|
+
|
176
|
+
## Faml, Haml
|
177
|
+
```html
|
178
|
+
<span id='1_true'></span>
|
179
|
+
|
180
|
+
```
|
181
|
+
|
182
|
+
## Hamlit
|
183
|
+
```html
|
184
|
+
<span id='1__false_true'></span>
|
185
|
+
|
186
|
+
```
|
187
|
+
|
188
|
+
# [./spec/render/attribute_spec.rb:91](../../../spec/render/attribute_spec.rb#L91)
|
189
|
+
## Input
|
190
|
+
```haml
|
43
191
|
%span{class: "x\"y'z"} hello
|
44
192
|
```
|
45
193
|
|
@@ -55,7 +203,7 @@
|
|
55
203
|
|
56
204
|
```
|
57
205
|
|
58
|
-
# [./spec/render/attribute_spec.rb:
|
206
|
+
# [./spec/render/attribute_spec.rb:104](../../../spec/render/attribute_spec.rb#L104)
|
59
207
|
## Input (with options={:format=>:xhtml})
|
60
208
|
```haml
|
61
209
|
- foo = true
|
@@ -74,7 +222,7 @@
|
|
74
222
|
|
75
223
|
```
|
76
224
|
|
77
|
-
# [./spec/render/attribute_spec.rb:
|
225
|
+
# [./spec/render/attribute_spec.rb:104](../../../spec/render/attribute_spec.rb#L104)
|
78
226
|
## Input (with options={:format=>:xhtml})
|
79
227
|
```haml
|
80
228
|
- h = {foo: true, bar: 1}
|
@@ -93,7 +241,7 @@
|
|
93
241
|
|
94
242
|
```
|
95
243
|
|
96
|
-
# [./spec/render/attribute_spec.rb:
|
244
|
+
# [./spec/render/attribute_spec.rb:111](../../../spec/render/attribute_spec.rb#L111)
|
97
245
|
## Input
|
98
246
|
```haml
|
99
247
|
%span{foo: {bar: 1+2}} hello
|
@@ -111,7 +259,7 @@
|
|
111
259
|
|
112
260
|
```
|
113
261
|
|
114
|
-
# [./spec/render/attribute_spec.rb:
|
262
|
+
# [./spec/render/attribute_spec.rb:115](../../../spec/render/attribute_spec.rb#L115)
|
115
263
|
## Input
|
116
264
|
```haml
|
117
265
|
- attrs = { foo: 1, bar: { hoge: :fuga }, baz: true }
|
@@ -137,7 +285,7 @@
|
|
137
285
|
|
138
286
|
```
|
139
287
|
|
140
|
-
# [./spec/render/attribute_spec.rb:
|
288
|
+
# [./spec/render/attribute_spec.rb:129](../../../spec/render/attribute_spec.rb#L129)
|
141
289
|
## Input
|
142
290
|
```haml
|
143
291
|
- data = { foo: 1 }
|
@@ -157,7 +305,7 @@
|
|
157
305
|
|
158
306
|
```
|
159
307
|
|
160
|
-
# [./spec/render/attribute_spec.rb:
|
308
|
+
# [./spec/render/attribute_spec.rb:136](../../../spec/render/attribute_spec.rb#L136)
|
161
309
|
## Input
|
162
310
|
```haml
|
163
311
|
%span{foo: {bar: 1+2}} hello
|
@@ -175,7 +323,7 @@
|
|
175
323
|
|
176
324
|
```
|
177
325
|
|
178
|
-
# [./spec/render/attribute_spec.rb:
|
326
|
+
# [./spec/render/attribute_spec.rb:159](../../../spec/render/attribute_spec.rb#L159)
|
179
327
|
## Input
|
180
328
|
```haml
|
181
329
|
%span{data: {foo: 1, bar: 'baz', :hoge => :fuga, k1: { k2: 'v3' }}} hello
|
@@ -193,7 +341,7 @@
|
|
193
341
|
|
194
342
|
```
|
195
343
|
|
196
|
-
# [./spec/render/attribute_spec.rb:
|
344
|
+
# [./spec/render/attribute_spec.rb:167](../../../spec/render/attribute_spec.rb#L167)
|
197
345
|
## Input
|
198
346
|
```haml
|
199
347
|
%span{data: {foo: 1, bar: 2+3}} hello
|
@@ -211,7 +359,7 @@
|
|
211
359
|
|
212
360
|
```
|
213
361
|
|
214
|
-
# [./spec/render/attribute_spec.rb:
|
362
|
+
# [./spec/render/attribute_spec.rb:171](../../../spec/render/attribute_spec.rb#L171)
|
215
363
|
## Input
|
216
364
|
```haml
|
217
365
|
- data = { foo: 1, bar: 2 }
|
@@ -231,7 +379,7 @@
|
|
231
379
|
|
232
380
|
```
|
233
381
|
|
234
|
-
# [./spec/render/attribute_spec.rb:
|
382
|
+
# [./spec/render/attribute_spec.rb:189](../../../spec/render/attribute_spec.rb#L189)
|
235
383
|
## Input
|
236
384
|
```haml
|
237
385
|
%span{b: __LINE__,
|
@@ -251,7 +399,7 @@
|
|
251
399
|
|
252
400
|
```
|
253
401
|
|
254
|
-
# [./spec/render/attribute_spec.rb:
|
402
|
+
# [./spec/render/attribute_spec.rb:196](../../../spec/render/attribute_spec.rb#L196)
|
255
403
|
## Input
|
256
404
|
```haml
|
257
405
|
%span{"foo\0bar" => "hello"}
|
@@ -269,7 +417,7 @@
|
|
269
417
|
|
270
418
|
```
|
271
419
|
|
272
|
-
# [./spec/render/attribute_spec.rb:
|
420
|
+
# [./spec/render/attribute_spec.rb:196](../../../spec/render/attribute_spec.rb#L196)
|
273
421
|
## Input
|
274
422
|
```haml
|
275
423
|
- val = "hello"
|
@@ -289,7 +437,7 @@
|
|
289
437
|
|
290
438
|
```
|
291
439
|
|
292
|
-
# [./spec/render/attribute_spec.rb:
|
440
|
+
# [./spec/render/attribute_spec.rb:196](../../../spec/render/attribute_spec.rb#L196)
|
293
441
|
## Input
|
294
442
|
```haml
|
295
443
|
- key = "foo\0bar"
|
data/lib/faml/compiler.rb
CHANGED
@@ -319,7 +319,7 @@ module Faml
|
|
319
319
|
static_attributes[k.to_s] = v
|
320
320
|
end
|
321
321
|
|
322
|
-
class_list = Array(static_attributes
|
322
|
+
class_list = Array(static_attributes.delete('class')).select { |v| v }.flat_map { |c| c.to_s.split(/ +/) }
|
323
323
|
unless static_class.empty?
|
324
324
|
class_list.concat(static_class.split(/ +/))
|
325
325
|
end
|
@@ -327,7 +327,7 @@ module Faml
|
|
327
327
|
static_attributes['class'] = class_list.uniq.sort.join(' ')
|
328
328
|
end
|
329
329
|
|
330
|
-
id_list = Array(static_attributes
|
330
|
+
id_list = Array(static_attributes.delete('id')).select { |v| v }
|
331
331
|
unless static_id.empty?
|
332
332
|
id_list = [static_id].concat(id_list)
|
333
333
|
end
|
data/lib/faml/version.rb
CHANGED
@@ -64,10 +64,30 @@ HAML
|
|
64
64
|
expect(render_string('%span.foo{class: %w[foo bar]}')).to eq("<span class='bar foo'></span>\n")
|
65
65
|
end
|
66
66
|
|
67
|
+
it 'skips empty array class' do
|
68
|
+
expect(render_string('%span{class: []}')).to eq("<span></span>\n")
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'skips falsey array elements in class' do
|
72
|
+
expect(render_string('%span{class: [1, nil, false, true]}')).to eq("<span class='1 true'></span>\n")
|
73
|
+
expect(render_string("- v = [1, nil, false, true]\n%span{class: v}")).to eq("<span class='1 true'></span>\n")
|
74
|
+
expect(render_string("- h = { class: [1, nil, false, true] }\n%span{h}")).to eq("<span class='1 true'></span>\n")
|
75
|
+
end
|
76
|
+
|
67
77
|
it 'strigify non-string ids' do
|
68
78
|
expect(render_string('%span#foo{id: :bar} hello')).to eq("<span id='foo_bar'>hello</span>\n")
|
69
79
|
end
|
70
80
|
|
81
|
+
it 'skips empty array class' do
|
82
|
+
expect(render_string('%span{id: []}')).to eq("<span></span>\n")
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'skips falsey array elements in id' do
|
86
|
+
expect(render_string('%span{id: [1, nil, false, true]}')).to eq("<span id='1_true'></span>\n")
|
87
|
+
expect(render_string("- v = [1, nil, false, true]\n%span{id: v}")).to eq("<span id='1_true'></span>\n")
|
88
|
+
expect(render_string("- h = { id: [1, nil, false, true] }\n%span{h}")).to eq("<span id='1_true'></span>\n")
|
89
|
+
end
|
90
|
+
|
71
91
|
it 'escapes' do
|
72
92
|
expect(render_string(%q|%span{class: "x\"y'z"} hello|)).to eq(%Q{<span class='x"y'z'>hello</span>\n})
|
73
93
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kohei Suzuki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: escape_utils
|
@@ -511,7 +511,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
511
511
|
version: '0'
|
512
512
|
requirements: []
|
513
513
|
rubyforge_project:
|
514
|
-
rubygems_version: 2.5.
|
514
|
+
rubygems_version: 2.4.5.1
|
515
515
|
signing_key:
|
516
516
|
specification_version: 4
|
517
517
|
summary: Faster implementation of Haml template language.
|