faml 0.6.4 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: efb487cc95863a4732f1771c0e634fe19c533d84
4
- data.tar.gz: a2d406a2e67257ee76c8c847b52f9ac0c54a7bd5
3
+ metadata.gz: 12548082a8aaf67316ba96345010c92ded15aa41
4
+ data.tar.gz: bf0e80233a7227814421df27fe15b8fe05271aad
5
5
  SHA512:
6
- metadata.gz: 4fb7e5535a4c2f2e7f03a9fb79055d02191bd3b862e6e5e5b8b884c832d5a6c877776d9fb234367de6f03d751749ccb38bfb92a698cb1a0279779e88b78f40f5
7
- data.tar.gz: cc47fb356f37cf92cfc5c402b63c29d9b3318667118ff33c8b0fb964219d4bf262bed7d1de9d175f7dc4d9f4ec6fc1162434eb581628a4d02a01fda65e46d595
6
+ metadata.gz: 13d98c0fd7b3fa67895b874a99bc02606e3eb334be9d169038d975f86f09c7715f602a94d577ea63ef9ae7222795fbe7987555a6cfd8bd104216722ad6ef2765
7
+ data.tar.gz: 2ac8f294c6bfe8eab1ace2a755f6f5eceff9fd0b59770653a0d8c321c300a876d09f105e7d4f09d7dd1a130015588ea10fb05bd689bd6b3adfb90ae844fa8d3c
@@ -1,3 +1,11 @@
1
+ ## 0.6.5 (2015-11-28)
2
+ - Delete falsey values after merging all attributes
3
+ - `%span(foo=true){foo: false}` now renders `<span></span>`, because old attributes have priority even if the value is falsey.
4
+ - https://github.com/eagletmt/faml/pull/43
5
+ - Fix duplicated attribute in dynamic attribute
6
+ - `%span{foo: 1, 'foo' => 1+1}` now renders `<span foo='2'></span>` correctly
7
+ - https://github.com/eagletmt/faml/pull/45
8
+
1
9
  ## 0.6.4 (2015-11-28)
2
10
  - Flatten `id` and `class` attributes
3
11
  - https://github.com/eagletmt/faml/pull/41
@@ -83,14 +83,12 @@ substitute_underscores(VALUE str)
83
83
  static int
84
84
  normalize_data_i2(VALUE key, VALUE value, VALUE ptr)
85
85
  {
86
- if (RTEST(value)) {
87
- struct normalize_data_i2_arg *arg = (struct normalize_data_i2_arg *)ptr;
88
- VALUE k = rb_str_dup(arg->key);
86
+ struct normalize_data_i2_arg *arg = (struct normalize_data_i2_arg *)ptr;
87
+ VALUE k = rb_str_dup(arg->key);
89
88
 
90
- rb_str_cat(k, "-", 1);
91
- rb_str_append(k, key);
92
- rb_hash_aset(arg->normalized, k, value);
93
- }
89
+ rb_str_cat(k, "-", 1);
90
+ rb_str_append(k, key);
91
+ rb_hash_aset(arg->normalized, k, value);
94
92
  return ST_CONTINUE;
95
93
  }
96
94
 
@@ -107,11 +105,9 @@ normalize_data_i(VALUE key, VALUE value, VALUE normalized)
107
105
  arg.key = key;
108
106
  arg.normalized = normalized;
109
107
  rb_hash_foreach(normalize_data(value), FOREACH_FUNC(normalize_data_i2), (VALUE)(&arg));
110
- } else if (RB_TYPE_P(value, T_TRUE)) {
111
- /* Keep Qtrue value */
108
+ } else if (RB_TYPE_P(value, T_TRUE) || !RTEST(value)) {
109
+ /* Keep Qtrue and falsey value */
112
110
  rb_hash_aset(normalized, key, value);
113
- } else if (!RTEST(value)) {
114
- /* Delete falsey values */
115
111
  } else {
116
112
  rb_hash_aset(normalized, key, rb_convert_type(value, T_STRING, "String", "to_s"));
117
113
  }
@@ -157,10 +153,8 @@ normalize(VALUE hash)
157
153
  rb_hash_delete(hash, key);
158
154
  data = normalize_data(value);
159
155
  rb_hash_foreach(data, FOREACH_FUNC(put_data_attribute), hash);
160
- } else if (RB_TYPE_P(value, T_TRUE)) {
161
- /* Keep Qtrue value */
162
- } else if (!RTEST(value)) {
163
- rb_hash_delete(hash, key);
156
+ } else if (RB_TYPE_P(value, T_TRUE) || !RTEST(value)) {
157
+ /* Keep Qtrue and falsey value */
164
158
  } else {
165
159
  rb_hash_aset(hash, key, rb_convert_type(value, T_STRING, "String", "to_s"));
166
160
  }
@@ -226,6 +220,22 @@ join_id_attribute(VALUE attributes, VALUE key)
226
220
  }
227
221
  }
228
222
 
223
+ static int
224
+ delete_falsey_values_i(RB_UNUSED_VAR(VALUE key), VALUE value, RB_UNUSED_VAR(VALUE arg))
225
+ {
226
+ if (RTEST(value)) {
227
+ return ST_CONTINUE;
228
+ } else {
229
+ return ST_DELETE;
230
+ }
231
+ }
232
+
233
+ static void
234
+ delete_falsey_values(VALUE attributes)
235
+ {
236
+ rb_hash_foreach(attributes, FOREACH_FUNC(delete_falsey_values_i), Qnil);
237
+ }
238
+
229
239
  static VALUE
230
240
  merge(VALUE object_ref, int argc, VALUE *argv)
231
241
  {
@@ -247,6 +257,7 @@ merge(VALUE object_ref, int argc, VALUE *argv)
247
257
 
248
258
  join_class_attribute(attributes, class_str);
249
259
  join_id_attribute(attributes, id_str);
260
+ delete_falsey_values(attributes);
250
261
 
251
262
  return attributes;
252
263
  }
@@ -1,7 +1,7 @@
1
1
  # Incompatibilities
2
2
  ## Versions
3
3
  - Haml 4.1.0.beta.1
4
- - Faml 0.6.4
4
+ - Faml 0.6.5
5
5
  - Hamlit 1.7.2
6
6
 
7
7
  ## Table of contents
@@ -1,6 +1,46 @@
1
1
  # [./spec/render/attribute_spec.rb:44](../../../spec/render/attribute_spec.rb#L44)
2
2
  ## Input
3
3
  ```haml
4
+ - h1 = { foo: 'should be overwritten' }
5
+ - h2 = { foo: nil }
6
+ %a{h1, h2}
7
+
8
+ ```
9
+
10
+ ## Faml, Haml
11
+ ```html
12
+ <a></a>
13
+
14
+ ```
15
+
16
+ ## Hamlit
17
+ ```html
18
+ <a foo='should be overwritten'></a>
19
+
20
+ ```
21
+
22
+ # [./spec/render/attribute_spec.rb:52](../../../spec/render/attribute_spec.rb#L52)
23
+ ## Input
24
+ ```haml
25
+ - h = {foo: 1, 'foo' => 2}
26
+ %span{h}
27
+ ```
28
+
29
+ ## Faml, Haml
30
+ ```html
31
+ <span foo='2'></span>
32
+
33
+ ```
34
+
35
+ ## Hamlit
36
+ ```html
37
+ <span foo='1' foo='2'></span>
38
+
39
+ ```
40
+
41
+ # [./spec/render/attribute_spec.rb:58](../../../spec/render/attribute_spec.rb#L58)
42
+ ## Input
43
+ ```haml
4
44
  %span{foo: "x\"y'z"}hello
5
45
  ```
6
46
 
@@ -16,7 +56,7 @@
16
56
 
17
57
  ```
18
58
 
19
- # [./spec/render/attribute_spec.rb:44](../../../spec/render/attribute_spec.rb#L44)
59
+ # [./spec/render/attribute_spec.rb:58](../../../spec/render/attribute_spec.rb#L58)
20
60
  ## Input
21
61
  ```haml
22
62
  - v = "x\"y'z"
@@ -35,7 +75,7 @@
35
75
 
36
76
  ```
37
77
 
38
- # [./spec/render/attribute_spec.rb:44](../../../spec/render/attribute_spec.rb#L44)
78
+ # [./spec/render/attribute_spec.rb:58](../../../spec/render/attribute_spec.rb#L58)
39
79
  ## Input
40
80
  ```haml
41
81
  - h = {foo: "x\"y'z"}
@@ -54,7 +94,7 @@
54
94
 
55
95
  ```
56
96
 
57
- # [./spec/render/attribute_spec.rb:61](../../../spec/render/attribute_spec.rb#L61)
97
+ # [./spec/render/attribute_spec.rb:75](../../../spec/render/attribute_spec.rb#L75)
58
98
  ## Input (with options={:format=>:xhtml})
59
99
  ```haml
60
100
  - v = true
@@ -73,7 +113,7 @@
73
113
 
74
114
  ```
75
115
 
76
- # [./spec/render/attribute_spec.rb:61](../../../spec/render/attribute_spec.rb#L61)
116
+ # [./spec/render/attribute_spec.rb:75](../../../spec/render/attribute_spec.rb#L75)
77
117
  ## Input (with options={:format=>:xhtml})
78
118
  ```haml
79
119
  - h = {foo: true}
@@ -92,7 +132,7 @@
92
132
 
93
133
  ```
94
134
 
95
- # [./spec/render/attribute_spec.rb:75](../../../spec/render/attribute_spec.rb#L75)
135
+ # [./spec/render/attribute_spec.rb:89](../../../spec/render/attribute_spec.rb#L89)
96
136
  ## Input
97
137
  ```haml
98
138
  %span{b: __LINE__,
@@ -112,7 +152,7 @@
112
152
 
113
153
  ```
114
154
 
115
- # [./spec/render/attribute_spec.rb:82](../../../spec/render/attribute_spec.rb#L82)
155
+ # [./spec/render/attribute_spec.rb:96](../../../spec/render/attribute_spec.rb#L96)
116
156
  ## Input
117
157
  ```haml
118
158
  %span{"foo\0bar" => "hello"}
@@ -130,7 +170,7 @@
130
170
 
131
171
  ```
132
172
 
133
- # [./spec/render/attribute_spec.rb:82](../../../spec/render/attribute_spec.rb#L82)
173
+ # [./spec/render/attribute_spec.rb:96](../../../spec/render/attribute_spec.rb#L96)
134
174
  ## Input
135
175
  ```haml
136
176
  - val = "hello"
@@ -150,7 +190,7 @@
150
190
 
151
191
  ```
152
192
 
153
- # [./spec/render/attribute_spec.rb:82](../../../spec/render/attribute_spec.rb#L82)
193
+ # [./spec/render/attribute_spec.rb:96](../../../spec/render/attribute_spec.rb#L96)
154
194
  ## Input
155
195
  ```haml
156
196
  - key = "foo\0bar"
@@ -172,7 +212,7 @@
172
212
  ... ^
173
213
  ```
174
214
 
175
- # [./spec/render/attribute_spec.rb:96](../../../spec/render/attribute_spec.rb#L96)
215
+ # [./spec/render/attribute_spec.rb:110](../../../spec/render/attribute_spec.rb#L110)
176
216
  ## Input
177
217
  ```haml
178
218
  %span[Faml::TestStruct.new(123)] hello
@@ -190,7 +230,7 @@
190
230
 
191
231
  ```
192
232
 
193
- # [./spec/render/attribute_spec.rb:100](../../../spec/render/attribute_spec.rb#L100)
233
+ # [./spec/render/attribute_spec.rb:114](../../../spec/render/attribute_spec.rb#L114)
194
234
  ## Input
195
235
  ```haml
196
236
  %span[Faml::TestStruct.new(123), :hello] hello
@@ -208,7 +248,7 @@
208
248
 
209
249
  ```
210
250
 
211
- # [./spec/render/attribute_spec.rb:104](../../../spec/render/attribute_spec.rb#L104)
251
+ # [./spec/render/attribute_spec.rb:118](../../../spec/render/attribute_spec.rb#L118)
212
252
  ## Input
213
253
  ```haml
214
254
  %span[Faml::TestRefStruct.new(123)] hello
@@ -226,7 +266,7 @@
226
266
 
227
267
  ```
228
268
 
229
- # [./spec/render/attribute_spec.rb:108](../../../spec/render/attribute_spec.rb#L108)
269
+ # [./spec/render/attribute_spec.rb:122](../../../spec/render/attribute_spec.rb#L122)
230
270
  ## Input
231
271
  ```haml
232
272
  %span#baz[Faml::TestStruct.new(123)]{id: "foo"} hello
@@ -244,7 +284,7 @@
244
284
 
245
285
  ```
246
286
 
247
- # [./spec/render/attribute_spec.rb:114](../../../spec/render/attribute_spec.rb#L114)
287
+ # [./spec/render/attribute_spec.rb:128](../../../spec/render/attribute_spec.rb#L128)
248
288
  ## Input
249
289
  ```haml
250
290
  %span{foo: 1}(foo=2)
@@ -262,7 +302,7 @@
262
302
 
263
303
  ```
264
304
 
265
- # [./spec/render/attribute_spec.rb:114](../../../spec/render/attribute_spec.rb#L114)
305
+ # [./spec/render/attribute_spec.rb:128](../../../spec/render/attribute_spec.rb#L128)
266
306
  ## Input
267
307
  ```haml
268
308
  %span(foo=2){foo: 1}
@@ -280,7 +320,7 @@
280
320
 
281
321
  ```
282
322
 
283
- # [./spec/render/attribute_spec.rb:114](../../../spec/render/attribute_spec.rb#L114)
323
+ # [./spec/render/attribute_spec.rb:128](../../../spec/render/attribute_spec.rb#L128)
284
324
  ## Input
285
325
  ```haml
286
326
  - v = 2
@@ -299,7 +339,7 @@
299
339
 
300
340
  ```
301
341
 
302
- # [./spec/render/attribute_spec.rb:114](../../../spec/render/attribute_spec.rb#L114)
342
+ # [./spec/render/attribute_spec.rb:128](../../../spec/render/attribute_spec.rb#L128)
303
343
  ## Input
304
344
  ```haml
305
345
  - v = 2
@@ -318,7 +358,7 @@
318
358
 
319
359
  ```
320
360
 
321
- # [./spec/render/attribute_spec.rb:114](../../../spec/render/attribute_spec.rb#L114)
361
+ # [./spec/render/attribute_spec.rb:128](../../../spec/render/attribute_spec.rb#L128)
322
362
  ## Input
323
363
  ```haml
324
364
  - h = {foo: 1}
@@ -337,7 +377,7 @@
337
377
 
338
378
  ```
339
379
 
340
- # [./spec/render/attribute_spec.rb:114](../../../spec/render/attribute_spec.rb#L114)
380
+ # [./spec/render/attribute_spec.rb:128](../../../spec/render/attribute_spec.rb#L128)
341
381
  ## Input
342
382
  ```haml
343
383
  - h = {foo: 1}
@@ -356,7 +396,7 @@
356
396
 
357
397
  ```
358
398
 
359
- # [./spec/render/attribute_spec.rb:133](../../../spec/render/attribute_spec.rb#L133)
399
+ # [./spec/render/attribute_spec.rb:147](../../../spec/render/attribute_spec.rb#L147)
360
400
  ## Input
361
401
  ```haml
362
402
  %span{id: 1}(id=2)
@@ -118,3 +118,24 @@
118
118
 
119
119
  ```
120
120
 
121
+ # [./spec/render/hash_attribute_spec.rb:61](../../../spec/render/hash_attribute_spec.rb#L61)
122
+ ## Input
123
+ ```haml
124
+ - h1 = { new: true }
125
+ - h2 = { data: { old: true } }
126
+ %a(data=h1){ h2 , data: { new: nil, old: false } }
127
+
128
+ ```
129
+
130
+ ## Faml, Haml
131
+ ```html
132
+ <a></a>
133
+
134
+ ```
135
+
136
+ ## Hamlit
137
+ ```html
138
+ <a data-old data='{:new=&gt;true}'></a>
139
+
140
+ ```
141
+
@@ -56,8 +56,6 @@ module Faml
56
56
  case
57
57
  when value == true
58
58
  [:haml, :attr, key, [:multi]]
59
- when value == false || value.nil?
60
- [:multi]
61
59
  else
62
60
  [:haml, :attr, key, [:static, Temple::Utils.escape_html(value)]]
63
61
  end
@@ -59,10 +59,9 @@ module Faml
59
59
  parser.dynamic_attributes.each do |k, v|
60
60
  k = k.to_s
61
61
  if static_attributes.key?(k)
62
- if StaticHashParser::SPECIAL_ATTRIBUTES.include?(k)
63
- # XXX: Quit optimization
64
- return nil
65
- end
62
+ # XXX: Quit optimization.
63
+ # See also https://github.com/eagletmt/faml/issues/44
64
+ return nil
66
65
  end
67
66
  dynamic_attributes[k] = v
68
67
  end
@@ -1,4 +1,4 @@
1
1
  # frozen-string-literal: true
2
2
  module Faml
3
- VERSION = '0.6.4'
3
+ VERSION = '0.6.5'
4
4
  end
@@ -41,6 +41,20 @@ RSpec.describe 'Attributes rendering', type: :render do
41
41
  end
42
42
  end
43
43
 
44
+ it 'skips falsey values after merging attributes' do
45
+ expect(render_string(<<HAML)).to eq("<a></a>\n")
46
+ - h1 = { foo: 'should be overwritten' }
47
+ - h2 = { foo: nil }
48
+ %a{h1, h2}
49
+ HAML
50
+ end
51
+
52
+ it 'renders duplicated keys correctly' do
53
+ expect(render_string("%span{foo: 1, 'foo' => 2}")).to eq("<span foo='2'></span>\n")
54
+ expect(render_string("- v = 2\n%span{foo: 1, 'foo' => v}")).to eq("<span foo='2'></span>\n")
55
+ expect(render_string("- h = {foo: 1, 'foo' => 2}\n%span{h}")).to eq("<span foo='2'></span>\n")
56
+ end
57
+
44
58
  it 'escapes' do
45
59
  with_each_attribute_type(:foo, %q|"x\"y'z"|, text: 'hello') do |str|
46
60
  expect(render_string(str)).to eq(%Q{<span foo='x&quot;y&#39;z'>hello</span>\n})
@@ -58,6 +58,14 @@ HAML
58
58
  expect(render_string("- v = nil\n%span{data: { foo: v }}")).to eq("<span></span>\n")
59
59
  end
60
60
 
61
+ it 'skips falsey data attributes after merging attributes' do
62
+ expect(render_string(<<HAML)).to eq("<a></a>\n")
63
+ - h1 = { new: true }
64
+ - h2 = { data: { old: true } }
65
+ %a(data=h1){ h2 , data: { new: nil, old: false } }
66
+ HAML
67
+ end
68
+
61
69
  it 'renders true data attributes' do
62
70
  expect(render_string('%span{data: { foo: true }}')).to eq("<span data-foo></span>\n")
63
71
  expect(render_string("- v = true\n%span{data: { foo: v }}")).to eq("<span data-foo></span>\n")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kohei Suzuki