faml 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70be9578e244e136f47caf610ffde1a3e7edf582
4
- data.tar.gz: c3673597a734dcf1822656f55e4868396bf242c8
3
+ metadata.gz: beef30a714bedb8c79f1ff6382d91ce5d79cd7ea
4
+ data.tar.gz: 0dfd73a88e67ebc32d5ec3aa7eecd190110c92c8
5
5
  SHA512:
6
- metadata.gz: f370900646f37e6f58d4d2ef43ff98c1f72c6a74f10ea7e9733b506a85dca85e75a53b82267ec2dd5d151ea86b10c647e0de372b82e6e13b2841933ed5480df8
7
- data.tar.gz: c268cc69b1de1723be7f79e8377026e34b712fbdecd4cea73f01f450bcad11cac600fee873f34db7394a168e9109e4f8882018f1ec7e3e52d55ed8643e23749f
6
+ metadata.gz: c8be5c3da3eb798f52e9c23e2db8e7f4b2826fdeb6cacd929f17c36dc4fdfcc14f472d10345f0f4dc6618a8e036ca3f6fdeba08458af8ad9428134e811a15356
7
+ data.tar.gz: 608fd49b52622683bf2eda3e401ecea2798ded3582f0367b28f981d54cfc50c2ac60e3f1340266e7543e4fd53891b3d8321adf255e17b98c3069ff57db6f7d59
@@ -1,3 +1,8 @@
1
+ ## 0.6.3 (2015-11-22)
2
+ - Remove duplicated class in Ruby attribute case
3
+ - `%span.foo{h}` where `h = { class: 'foo bar' }` now renders `<span class='bar foo'></span>` .
4
+ - `%span.foo{class: 'foo bar'}` renders `<span class='bar foo'></span>` since v0.2.12 .
5
+
1
6
  ## 0.6.2 (2015-11-22)
2
7
  - Fix data-id and data-class attribute
3
8
  - https://github.com/eagletmt/faml/pull/39
@@ -177,16 +177,74 @@ merge_one(VALUE attributes, VALUE arg)
177
177
  }
178
178
 
179
179
  static void
180
- merge(VALUE attributes, VALUE object_ref, int argc, VALUE *argv)
180
+ join_class_attribute(VALUE attributes, VALUE key)
181
181
  {
182
+ long len;
183
+ VALUE val;
184
+
185
+ val = rb_hash_delete(attributes, key);
186
+ Check_Type(val, T_ARRAY);
187
+ len = RARRAY_LEN(val);
188
+ if (len != 0) {
189
+ long i;
190
+ VALUE ary = rb_ary_new_capa(len);
191
+ for (i = 0; i < len; i++) {
192
+ VALUE v = RARRAY_AREF(val, i);
193
+ if (RTEST(v)) {
194
+ rb_ary_concat(ary, rb_str_split(rb_convert_type(v, T_STRING, "String", "to_s"), " "));
195
+ }
196
+ }
197
+ rb_funcall(ary, id_sort_bang, 0);
198
+ rb_funcall(ary, id_uniq_bang, 0);
199
+ rb_hash_aset(attributes, key, rb_ary_join(ary, rb_const_get(rb_mAttributeBuilder, id_space)));
200
+ }
201
+ }
202
+
203
+ static void
204
+ join_id_attribute(VALUE attributes, VALUE key)
205
+ {
206
+ long len;
207
+ VALUE val;
208
+
209
+ val = rb_hash_delete(attributes, key);
210
+ Check_Type(val, T_ARRAY);
211
+ len = RARRAY_LEN(val);
212
+ if (len != 0) {
213
+ long i;
214
+ VALUE ary = rb_ary_new_capa(len);
215
+ for (i = 0; i < len; i++) {
216
+ VALUE v = RARRAY_AREF(val, i);
217
+ if (RTEST(v)) {
218
+ rb_ary_push(ary, rb_convert_type(v, T_STRING, "String", "to_s"));
219
+ }
220
+ }
221
+ rb_hash_aset(attributes, key, rb_ary_join(ary, rb_const_get(rb_mAttributeBuilder, id_underscore)));
222
+ }
223
+ }
224
+
225
+ static VALUE
226
+ merge(VALUE object_ref, int argc, VALUE *argv)
227
+ {
228
+ VALUE attributes, id_str, class_str;
182
229
  int i;
183
230
 
231
+ attributes = rb_hash_new();
232
+ id_str = rb_const_get(rb_mAttributeBuilder, id_id);
233
+ class_str = rb_const_get(rb_mAttributeBuilder, id_class);
234
+ rb_hash_aset(attributes, id_str, rb_ary_new());
235
+ rb_hash_aset(attributes, class_str, rb_ary_new());
236
+
184
237
  for (i = 0; i < argc; i++) {
185
238
  merge_one(attributes, argv[i]);
186
239
  }
187
240
  if (!NIL_P(object_ref)) {
188
241
  merge_one(attributes, object_ref);
189
242
  }
243
+
244
+ join_class_attribute(attributes, class_str);
245
+ join_id_attribute(attributes, id_str);
246
+
247
+ return attributes;
190
248
  }
191
249
 
192
250
  static void
@@ -212,41 +270,7 @@ static void
212
270
  build_attribute(VALUE buf, VALUE attr_quote, int is_html, VALUE key, VALUE value)
213
271
  {
214
272
  Check_Type(key, T_STRING);
215
- if (RSTRING_LEN(key) == 5 && memcmp(RSTRING_PTR(key), "class", 5) == 0) {
216
- long len;
217
-
218
- Check_Type(value, T_ARRAY);
219
- len = RARRAY_LEN(value);
220
- if (len != 0) {
221
- long i;
222
- VALUE ary = rb_ary_new_capa(len);
223
- for (i = 0; i < len; i++) {
224
- VALUE v = RARRAY_AREF(value, i);
225
- if (RTEST(v)) {
226
- rb_ary_push(ary, rb_convert_type(v, T_STRING, "String", "to_s"));
227
- }
228
- }
229
- rb_funcall(ary, id_sort_bang, 0);
230
- rb_funcall(ary, id_uniq_bang, 0);
231
- put_attribute(buf, attr_quote, key, rb_ary_join(ary, rb_const_get(rb_mAttributeBuilder, id_space)));
232
- }
233
- } else if (RSTRING_LEN(key) == 2 && memcmp(RSTRING_PTR(key), "id", 2) == 0) {
234
- long len = RARRAY_LEN(value);
235
-
236
- Check_Type(value, T_ARRAY);
237
- len = RARRAY_LEN(value);
238
- if (len != 0) {
239
- long i;
240
- VALUE ary = rb_ary_new_capa(len);
241
- for (i = 0; i < len; i++) {
242
- VALUE v = RARRAY_AREF(value, i);
243
- if (RTEST(v)) {
244
- rb_ary_push(ary, rb_convert_type(v, T_STRING, "String", "to_s"));
245
- }
246
- }
247
- put_attribute(buf, attr_quote, key, rb_ary_join(ary, rb_const_get(rb_mAttributeBuilder, id_underscore)));
248
- }
249
- } else if (RB_TYPE_P(value, T_TRUE)) {
273
+ if (RB_TYPE_P(value, T_TRUE)) {
250
274
  if (is_html) {
251
275
  rb_ary_push(buf, rb_const_get(rb_mAttributeBuilder, id_space));
252
276
  rb_ary_push(buf, key);
@@ -269,10 +293,7 @@ m_build(int argc, VALUE *argv, RB_UNUSED_VAR(VALUE self))
269
293
  attr_quote = argv[0];
270
294
  is_html = RTEST(argv[1]);
271
295
  object_ref = argv[2];
272
- attributes = rb_hash_new();
273
- rb_hash_aset(attributes, rb_const_get(rb_mAttributeBuilder, id_id), rb_ary_new());
274
- rb_hash_aset(attributes, rb_const_get(rb_mAttributeBuilder, id_class), rb_ary_new());
275
- merge(attributes, object_ref, argc-3, argv+3);
296
+ attributes = merge(object_ref, argc-3, argv+3);
276
297
 
277
298
  keys = rb_funcall(attributes, id_keys, 0);
278
299
  rb_funcall(keys, id_sort_bang, 0);
@@ -292,6 +313,13 @@ m_normalize_data(RB_UNUSED_VAR(VALUE self), VALUE data)
292
313
  return normalize_data(data);
293
314
  }
294
315
 
316
+ static VALUE
317
+ m_merge(int argc, VALUE *argv, RB_UNUSED_VAR(VALUE self))
318
+ {
319
+ rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
320
+ return merge(argv[0], argc-1, argv+1);
321
+ }
322
+
295
323
  void
296
324
  Init_attribute_builder(void)
297
325
  {
@@ -299,6 +327,7 @@ Init_attribute_builder(void)
299
327
  rb_mAttributeBuilder = rb_define_module_under(mFaml, "AttributeBuilder");
300
328
  rb_define_singleton_method(rb_mAttributeBuilder, "build", RUBY_METHOD_FUNC(m_build), -1);
301
329
  rb_define_singleton_method(rb_mAttributeBuilder, "normalize_data", RUBY_METHOD_FUNC(m_normalize_data), 1);
330
+ rb_define_singleton_method(rb_mAttributeBuilder, "merge", RUBY_METHOD_FUNC(m_merge), -1);
302
331
 
303
332
  id_keys = rb_intern("keys");
304
333
  id_sort_bang = rb_intern("sort!");
@@ -1,7 +1,7 @@
1
1
  # Incompatibilities
2
2
  ## Versions
3
3
  - Haml 4.1.0.beta.1
4
- - Faml 0.6.2
4
+ - Faml 0.6.3
5
5
  - Hamlit 1.7.2
6
6
 
7
7
  ## Table of contents
@@ -37,7 +37,45 @@
37
37
 
38
38
  ```
39
39
 
40
- # [./spec/render/attribute_spec.rb:68](../../../spec/render/attribute_spec.rb#L68)
40
+ # [./spec/render/attribute_spec.rb:62](../../../spec/render/attribute_spec.rb#L62)
41
+ ## Input
42
+ ```haml
43
+ - v = 'foo bar'
44
+ %span.foo{class: v}
45
+ ```
46
+
47
+ ## Faml, Haml
48
+ ```html
49
+ <span class='bar foo'></span>
50
+
51
+ ```
52
+
53
+ ## Hamlit
54
+ ```html
55
+ <span class='foo foo bar'></span>
56
+
57
+ ```
58
+
59
+ # [./spec/render/attribute_spec.rb:62](../../../spec/render/attribute_spec.rb#L62)
60
+ ## Input
61
+ ```haml
62
+ - h = {class: 'foo bar'}
63
+ %span.foo{h}
64
+ ```
65
+
66
+ ## Faml, Haml
67
+ ```html
68
+ <span class='bar foo'></span>
69
+
70
+ ```
71
+
72
+ ## Hamlit
73
+ ```html
74
+ <span class='foo foo bar'></span>
75
+
76
+ ```
77
+
78
+ # [./spec/render/attribute_spec.rb:80](../../../spec/render/attribute_spec.rb#L80)
41
79
  ## Input
42
80
  ```haml
43
81
  %span{class: []}
@@ -55,7 +93,7 @@
55
93
 
56
94
  ```
57
95
 
58
- # [./spec/render/attribute_spec.rb:72](../../../spec/render/attribute_spec.rb#L72)
96
+ # [./spec/render/attribute_spec.rb:84](../../../spec/render/attribute_spec.rb#L84)
59
97
  ## Input
60
98
  ```haml
61
99
  %span{class: [1, nil, false, true]}
@@ -73,7 +111,7 @@
73
111
 
74
112
  ```
75
113
 
76
- # [./spec/render/attribute_spec.rb:72](../../../spec/render/attribute_spec.rb#L72)
114
+ # [./spec/render/attribute_spec.rb:84](../../../spec/render/attribute_spec.rb#L84)
77
115
  ## Input
78
116
  ```haml
79
117
  - v = [1, nil, false, true]
@@ -92,7 +130,7 @@
92
130
 
93
131
  ```
94
132
 
95
- # [./spec/render/attribute_spec.rb:72](../../../spec/render/attribute_spec.rb#L72)
133
+ # [./spec/render/attribute_spec.rb:84](../../../spec/render/attribute_spec.rb#L84)
96
134
  ## Input
97
135
  ```haml
98
136
  - h = { class: [1, nil, false, true] }
@@ -111,7 +149,7 @@
111
149
 
112
150
  ```
113
151
 
114
- # [./spec/render/attribute_spec.rb:82](../../../spec/render/attribute_spec.rb#L82)
152
+ # [./spec/render/attribute_spec.rb:94](../../../spec/render/attribute_spec.rb#L94)
115
153
  ## Input
116
154
  ```haml
117
155
  %span{id: []}
@@ -129,7 +167,7 @@
129
167
 
130
168
  ```
131
169
 
132
- # [./spec/render/attribute_spec.rb:86](../../../spec/render/attribute_spec.rb#L86)
170
+ # [./spec/render/attribute_spec.rb:98](../../../spec/render/attribute_spec.rb#L98)
133
171
  ## Input
134
172
  ```haml
135
173
  %span{id: [1, nil, false, true]}
@@ -147,7 +185,7 @@
147
185
 
148
186
  ```
149
187
 
150
- # [./spec/render/attribute_spec.rb:86](../../../spec/render/attribute_spec.rb#L86)
188
+ # [./spec/render/attribute_spec.rb:98](../../../spec/render/attribute_spec.rb#L98)
151
189
  ## Input
152
190
  ```haml
153
191
  - v = [1, nil, false, true]
@@ -166,7 +204,7 @@
166
204
 
167
205
  ```
168
206
 
169
- # [./spec/render/attribute_spec.rb:86](../../../spec/render/attribute_spec.rb#L86)
207
+ # [./spec/render/attribute_spec.rb:98](../../../spec/render/attribute_spec.rb#L98)
170
208
  ## Input
171
209
  ```haml
172
210
  - h = { id: [1, nil, false, true] }
@@ -185,7 +223,7 @@
185
223
 
186
224
  ```
187
225
 
188
- # [./spec/render/attribute_spec.rb:92](../../../spec/render/attribute_spec.rb#L92)
226
+ # [./spec/render/attribute_spec.rb:104](../../../spec/render/attribute_spec.rb#L104)
189
227
  ## Input
190
228
  ```haml
191
229
  %span{class: "x\"y'z"} hello
@@ -203,7 +241,7 @@
203
241
 
204
242
  ```
205
243
 
206
- # [./spec/render/attribute_spec.rb:110](../../../spec/render/attribute_spec.rb#L110)
244
+ # [./spec/render/attribute_spec.rb:122](../../../spec/render/attribute_spec.rb#L122)
207
245
  ## Input (with options={:format=>:xhtml})
208
246
  ```haml
209
247
  - foo = true
@@ -222,7 +260,7 @@
222
260
 
223
261
  ```
224
262
 
225
- # [./spec/render/attribute_spec.rb:110](../../../spec/render/attribute_spec.rb#L110)
263
+ # [./spec/render/attribute_spec.rb:122](../../../spec/render/attribute_spec.rb#L122)
226
264
  ## Input (with options={:format=>:xhtml})
227
265
  ```haml
228
266
  - h = {foo: true, bar: 1}
@@ -241,7 +279,7 @@
241
279
 
242
280
  ```
243
281
 
244
- # [./spec/render/attribute_spec.rb:117](../../../spec/render/attribute_spec.rb#L117)
282
+ # [./spec/render/attribute_spec.rb:129](../../../spec/render/attribute_spec.rb#L129)
245
283
  ## Input
246
284
  ```haml
247
285
  %span{foo: {bar: 1+2}} hello
@@ -259,7 +297,7 @@
259
297
 
260
298
  ```
261
299
 
262
- # [./spec/render/attribute_spec.rb:121](../../../spec/render/attribute_spec.rb#L121)
300
+ # [./spec/render/attribute_spec.rb:133](../../../spec/render/attribute_spec.rb#L133)
263
301
  ## Input
264
302
  ```haml
265
303
  - attrs = { foo: 1, bar: { hoge: :fuga }, baz: true }
@@ -285,7 +323,7 @@
285
323
 
286
324
  ```
287
325
 
288
- # [./spec/render/attribute_spec.rb:135](../../../spec/render/attribute_spec.rb#L135)
326
+ # [./spec/render/attribute_spec.rb:147](../../../spec/render/attribute_spec.rb#L147)
289
327
  ## Input
290
328
  ```haml
291
329
  - data = { foo: 1 }
@@ -305,7 +343,7 @@
305
343
 
306
344
  ```
307
345
 
308
- # [./spec/render/attribute_spec.rb:149](../../../spec/render/attribute_spec.rb#L149)
346
+ # [./spec/render/attribute_spec.rb:161](../../../spec/render/attribute_spec.rb#L161)
309
347
  ## Input
310
348
  ```haml
311
349
  %span{foo: {bar: 1+2}} hello
@@ -323,7 +361,7 @@
323
361
 
324
362
  ```
325
363
 
326
- # [./spec/render/attribute_spec.rb:172](../../../spec/render/attribute_spec.rb#L172)
364
+ # [./spec/render/attribute_spec.rb:184](../../../spec/render/attribute_spec.rb#L184)
327
365
  ## Input
328
366
  ```haml
329
367
  %span{data: {foo: 1, bar: 'baz', :hoge => :fuga, k1: { k2: 'v3' }}} hello
@@ -341,7 +379,7 @@
341
379
 
342
380
  ```
343
381
 
344
- # [./spec/render/attribute_spec.rb:180](../../../spec/render/attribute_spec.rb#L180)
382
+ # [./spec/render/attribute_spec.rb:192](../../../spec/render/attribute_spec.rb#L192)
345
383
  ## Input
346
384
  ```haml
347
385
  %span{data: {foo: 1, bar: 2+3}} hello
@@ -359,7 +397,7 @@
359
397
 
360
398
  ```
361
399
 
362
- # [./spec/render/attribute_spec.rb:184](../../../spec/render/attribute_spec.rb#L184)
400
+ # [./spec/render/attribute_spec.rb:196](../../../spec/render/attribute_spec.rb#L196)
363
401
  ## Input
364
402
  ```haml
365
403
  - data = { foo: 1, bar: 2 }
@@ -379,7 +417,7 @@
379
417
 
380
418
  ```
381
419
 
382
- # [./spec/render/attribute_spec.rb:202](../../../spec/render/attribute_spec.rb#L202)
420
+ # [./spec/render/attribute_spec.rb:214](../../../spec/render/attribute_spec.rb#L214)
383
421
  ## Input
384
422
  ```haml
385
423
  %span{b: __LINE__,
@@ -399,7 +437,7 @@
399
437
 
400
438
  ```
401
439
 
402
- # [./spec/render/attribute_spec.rb:209](../../../spec/render/attribute_spec.rb#L209)
440
+ # [./spec/render/attribute_spec.rb:221](../../../spec/render/attribute_spec.rb#L221)
403
441
  ## Input
404
442
  ```haml
405
443
  %span{"foo\0bar" => "hello"}
@@ -417,7 +455,7 @@
417
455
 
418
456
  ```
419
457
 
420
- # [./spec/render/attribute_spec.rb:209](../../../spec/render/attribute_spec.rb#L209)
458
+ # [./spec/render/attribute_spec.rb:221](../../../spec/render/attribute_spec.rb#L221)
421
459
  ## Input
422
460
  ```haml
423
461
  - val = "hello"
@@ -437,7 +475,7 @@
437
475
 
438
476
  ```
439
477
 
440
- # [./spec/render/attribute_spec.rb:209](../../../spec/render/attribute_spec.rb#L209)
478
+ # [./spec/render/attribute_spec.rb:221](../../../spec/render/attribute_spec.rb#L221)
441
479
  ## Input
442
480
  ```haml
443
481
  - key = "foo\0bar"
@@ -459,7 +497,7 @@
459
497
  ... ^
460
498
  ```
461
499
 
462
- # [./spec/render/attribute_spec.rb:223](../../../spec/render/attribute_spec.rb#L223)
500
+ # [./spec/render/attribute_spec.rb:235](../../../spec/render/attribute_spec.rb#L235)
463
501
  ## Input
464
502
  ```haml
465
503
  %span[Faml::TestStruct.new(123)] hello
@@ -477,7 +515,7 @@
477
515
 
478
516
  ```
479
517
 
480
- # [./spec/render/attribute_spec.rb:227](../../../spec/render/attribute_spec.rb#L227)
518
+ # [./spec/render/attribute_spec.rb:239](../../../spec/render/attribute_spec.rb#L239)
481
519
  ## Input
482
520
  ```haml
483
521
  %span[Faml::TestStruct.new(123), :hello] hello
@@ -495,7 +533,7 @@
495
533
 
496
534
  ```
497
535
 
498
- # [./spec/render/attribute_spec.rb:231](../../../spec/render/attribute_spec.rb#L231)
536
+ # [./spec/render/attribute_spec.rb:243](../../../spec/render/attribute_spec.rb#L243)
499
537
  ## Input
500
538
  ```haml
501
539
  %span[Faml::TestRefStruct.new(123)] hello
@@ -513,7 +551,7 @@
513
551
 
514
552
  ```
515
553
 
516
- # [./spec/render/attribute_spec.rb:235](../../../spec/render/attribute_spec.rb#L235)
554
+ # [./spec/render/attribute_spec.rb:247](../../../spec/render/attribute_spec.rb#L247)
517
555
  ## Input
518
556
  ```haml
519
557
  %span#baz[Faml::TestStruct.new(123)]{id: "foo"} hello
@@ -531,7 +569,7 @@
531
569
 
532
570
  ```
533
571
 
534
- # [./spec/render/attribute_spec.rb:241](../../../spec/render/attribute_spec.rb#L241)
572
+ # [./spec/render/attribute_spec.rb:253](../../../spec/render/attribute_spec.rb#L253)
535
573
  ## Input
536
574
  ```haml
537
575
  %span{foo: 1}(foo=2)
@@ -549,7 +587,7 @@
549
587
 
550
588
  ```
551
589
 
552
- # [./spec/render/attribute_spec.rb:241](../../../spec/render/attribute_spec.rb#L241)
590
+ # [./spec/render/attribute_spec.rb:253](../../../spec/render/attribute_spec.rb#L253)
553
591
  ## Input
554
592
  ```haml
555
593
  %span(foo=2){foo: 1}
@@ -567,7 +605,7 @@
567
605
 
568
606
  ```
569
607
 
570
- # [./spec/render/attribute_spec.rb:241](../../../spec/render/attribute_spec.rb#L241)
608
+ # [./spec/render/attribute_spec.rb:253](../../../spec/render/attribute_spec.rb#L253)
571
609
  ## Input
572
610
  ```haml
573
611
  - v = 2
@@ -586,7 +624,7 @@
586
624
 
587
625
  ```
588
626
 
589
- # [./spec/render/attribute_spec.rb:241](../../../spec/render/attribute_spec.rb#L241)
627
+ # [./spec/render/attribute_spec.rb:253](../../../spec/render/attribute_spec.rb#L253)
590
628
  ## Input
591
629
  ```haml
592
630
  - v = 2
@@ -605,7 +643,7 @@
605
643
 
606
644
  ```
607
645
 
608
- # [./spec/render/attribute_spec.rb:241](../../../spec/render/attribute_spec.rb#L241)
646
+ # [./spec/render/attribute_spec.rb:253](../../../spec/render/attribute_spec.rb#L253)
609
647
  ## Input
610
648
  ```haml
611
649
  - h = {foo: 1}
@@ -624,7 +662,7 @@
624
662
 
625
663
  ```
626
664
 
627
- # [./spec/render/attribute_spec.rb:241](../../../spec/render/attribute_spec.rb#L241)
665
+ # [./spec/render/attribute_spec.rb:253](../../../spec/render/attribute_spec.rb#L253)
628
666
  ## Input
629
667
  ```haml
630
668
  - h = {foo: 1}
@@ -643,7 +681,7 @@
643
681
 
644
682
  ```
645
683
 
646
- # [./spec/render/attribute_spec.rb:260](../../../spec/render/attribute_spec.rb#L260)
684
+ # [./spec/render/attribute_spec.rb:272](../../../spec/render/attribute_spec.rb#L272)
647
685
  ## Input
648
686
  ```haml
649
687
  %span{id: 1}(id=2)
@@ -42,7 +42,7 @@ module Faml
42
42
  def try_optimize_attributes(old_attributes, new_attributes, static_id, static_class)
43
43
  static_attributes, dynamic_attributes = AttributeOptimizer.new.try_optimize(old_attributes, new_attributes, static_id, static_class)
44
44
  if static_attributes
45
- (static_attributes.keys + dynamic_attributes.keys).sort.flat_map do |k|
45
+ (static_attributes.keys + dynamic_attributes.keys).sort.map do |k|
46
46
  if static_attributes.key?(k)
47
47
  compile_static_attribute(k, static_attributes[k])
48
48
  else
@@ -53,17 +53,6 @@ module Faml
53
53
  end
54
54
 
55
55
  def compile_static_attribute(key, value)
56
- if value.is_a?(Hash) && key == 'data'
57
- data = AttributeBuilder.normalize_data(value)
58
- data.keys.sort.map do |k|
59
- compile_static_simple_attribute("data-#{k}", data[k])
60
- end
61
- else
62
- [compile_static_simple_attribute(key, value)]
63
- end
64
- end
65
-
66
- def compile_static_simple_attribute(key, value)
67
56
  case
68
57
  when value == true
69
58
  [:haml, :attr, key, [:multi]]
@@ -75,13 +64,13 @@ module Faml
75
64
  end
76
65
 
77
66
  def compile_dynamic_attribute(key, value)
78
- [[:haml, :attr, key, [:dvalue, value]]]
67
+ [:haml, :attr, key, [:dvalue, value]]
79
68
  end
80
69
 
81
70
  def compile_slow_attributes(old_attributes, new_attributes, static_id, static_class, object_ref)
82
71
  h = {}
83
72
  unless static_class.empty?
84
- h[:class] = static_class.split(/ +/)
73
+ h[:class] = static_class
85
74
  end
86
75
  unless static_id.empty?
87
76
  h[:id] = static_id
@@ -1,4 +1,5 @@
1
1
  # frozen-string-literal: true
2
+ require 'faml/attribute_builder'
2
3
  require_relative 'error'
3
4
  require_relative 'ruby_syntax_checker'
4
5
  require_relative 'static_hash_parser'
@@ -44,38 +45,13 @@ module Faml
44
45
  end
45
46
 
46
47
  def build_optimized_static_attributes(parser, static_id, static_class)
47
- static_attributes = {}
48
- class_list = []
49
- id_list = []
50
- parser.static_attributes.each do |k, v|
51
- k = k.to_s
52
- case k
53
- when 'id'
54
- id_list.concat(Array(v))
55
- when 'class'
56
- class_list.concat(Array(v))
57
- else
58
- static_attributes[k] = v
59
- end
60
- end
61
-
62
- class_list = class_list.select { |v| v }.flat_map { |c| c.to_s.split(/ +/) }
63
- unless static_class.empty?
64
- class_list.concat(static_class.split(/ +/))
48
+ if static_id.empty?
49
+ static_id = nil
65
50
  end
66
- unless class_list.empty?
67
- static_attributes['class'] = class_list.uniq.sort.join(' ')
51
+ if static_class.empty?
52
+ static_class = nil
68
53
  end
69
-
70
- id_list = id_list.select { |v| v }
71
- unless static_id.empty?
72
- id_list = [static_id].concat(id_list)
73
- end
74
- unless id_list.empty?
75
- static_attributes['id'] = id_list.join('_')
76
- end
77
-
78
- static_attributes
54
+ AttributeBuilder.merge(parser.static_attributes, id: static_id, class: static_class)
79
55
  end
80
56
 
81
57
  def build_optimized_dynamic_attributes(parser, static_attributes)
@@ -1,4 +1,4 @@
1
1
  # frozen-string-literal: true
2
2
  module Faml
3
- VERSION = '0.6.2'
3
+ VERSION = '0.6.3'
4
4
  end
@@ -60,9 +60,21 @@ HAML
60
60
  end
61
61
 
62
62
  it 'remove duplicated classes' do
63
- expect(render_string('%span.foo{class: :foo}')).to eq("<span class='foo'></span>\n")
64
- expect(render_string('%span.foo{class: "foo bar"}')).to eq("<span class='bar foo'></span>\n")
65
- expect(render_string('%span.foo{class: %w[foo bar]}')).to eq("<span class='bar foo'></span>\n")
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")
67
+ end
68
+ aggregate_failures do
69
+ expect(render_string("- v = :foo\n%span.foo{class: v}")).to eq("<span class='foo'></span>\n")
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")
72
+ end
73
+ aggregate_failures do
74
+ expect(render_string("- h = {class: :foo}\n%span.foo{h}")).to eq("<span class='foo'></span>\n")
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")
77
+ end
66
78
  end
67
79
 
68
80
  it 'skips empty array class' do
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.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kohei Suzuki