hamlit 2.8.10 → 2.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -2
- data/REFERENCE.md +6 -4
- data/ext/hamlit/hamlit.c +49 -12
- data/lib/hamlit/attribute_compiler.rb +3 -3
- data/lib/hamlit/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 587d2b8d01739c5529f342f9f316b9d13dcec5c9ba4ca693072e83da857fdf20
|
4
|
+
data.tar.gz: 91372701c50b63c2acbcc0f259987da4200a444c33371b1908670edc4c02493f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19f57ff4a0c28e5c6759c54120b37104ae3e4eff9e92cde062da1f195b8c39e3ef38a1f1eef4276fff22bd0961dd1cac126c3bdc38ca03137475ff5cc101fdb9
|
7
|
+
data.tar.gz: 418735e4c178d9a7bf96d6bbc432a0f00da2fd4068df1bee01254a864f2675c9ebe05c5a391a78c9912095f17b666cb9e688b24e30f33b8390bb86741d9228b5
|
data/CHANGELOG.md
CHANGED
@@ -4,14 +4,21 @@ All notable changes to this project will be documented in this file. This
|
|
4
4
|
project adheres to [Semantic Versioning](http://semver.org/). This change log is based upon
|
5
5
|
[keep-a-changelog](https://github.com/olivierlacan/keep-a-changelog).
|
6
6
|
|
7
|
-
## [2.
|
7
|
+
## [2.9.0](https://github.com/k0kubun/hamlit/compare/v2.8.10...v2.9.0) - 2018-10-16
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
- Consider aria attribute as another attribute that supports hyphenation and boolean like data attribute.
|
12
|
+
[#57](https://github.com/k0kubun/hamlit/pull/57). *Thanks to @francesco-loreti*
|
13
|
+
|
14
|
+
## [2.8.10](https://github.com/k0kubun/hamlit/compare/v2.8.9...v2.8.10) - 2018-09-05
|
8
15
|
|
9
16
|
### Fixed
|
10
17
|
|
11
18
|
- Fix uninitialized constant error introduced in v2.8.9
|
12
19
|
[#125](https://github.com/k0kubun/hamlit/pull/125). *Thanks to @vovchynniko*
|
13
20
|
|
14
|
-
## [2.8.9](https://github.com/k0kubun/hamlit/compare/v2.8.8...v2.8.9) - 2018-09-05
|
21
|
+
## [2.8.9](https://github.com/k0kubun/hamlit/compare/v2.8.8...v2.8.9) - 2018-09-05 [YANKED]
|
15
22
|
|
16
23
|
### Fixed
|
17
24
|
|
data/REFERENCE.md
CHANGED
@@ -82,7 +82,7 @@ But some helpers are supported on Rails. Some of not-implemented methods are pla
|
|
82
82
|
|
83
83
|
### Limited attributes hyphenation
|
84
84
|
In Haml, `%a{ foo: { bar: 'baz' } }` is rendered as `<a foo-bar='baz'></a>`, whatever foo is.
|
85
|
-
In Hamlit, this feature is supported only for data attribute. Hamlit renders `%a{ data: { foo: 'bar' } }`
|
85
|
+
In Hamlit, this feature is supported only for aria and data attribute. Hamlit renders `%a{ data: { foo: 'bar' } }`
|
86
86
|
as `<a data-foo='bar'></a>` because it's data attribute. This design allows us to reduce work on runtime
|
87
87
|
and the idea is originally in [Faml](https://github.com/eagletmt/faml).
|
88
88
|
|
@@ -91,7 +91,7 @@ In Haml, `%a{ foo: false }` is rendered as `<a></a>`, whatever `foo` is.
|
|
91
91
|
In Hamlit, this feature is supported for only boolean attributes, which are defined by
|
92
92
|
http://www.w3.org/TR/xhtml1/guidelines.html or https://html.spec.whatwg.org/.
|
93
93
|
The list is the same as `ActionView::Helpers::TagHelper::BOOLEAN_ATTRIBUTES`.
|
94
|
-
In addition, data-\* is also regarded as boolean.
|
94
|
+
In addition, aria-\* and data-\* is also regarded as boolean.
|
95
95
|
|
96
96
|
Since `foo` is not boolean attribute, `%a{ foo: false }` is rendered as `<a foo='false'></a>`
|
97
97
|
This is the same behavior as Rails helpers. Also for `%a{ foo: nil }`,
|
@@ -102,7 +102,7 @@ is the only difference between Faml and Hamlit.
|
|
102
102
|
## 5 Types of Attributes
|
103
103
|
|
104
104
|
Haml has 3 types of attributes: id, class and others.
|
105
|
-
In addition, Hamlit treats data and boolean attributes specially.
|
105
|
+
In addition, Hamlit treats aria/data and boolean attributes specially.
|
106
106
|
So there are 5 types of attributes in Hamlit.
|
107
107
|
|
108
108
|
### id attribute
|
@@ -143,7 +143,7 @@ and merging multiple classes results in unique alphabetical sort.
|
|
143
143
|
<div class=''></div>
|
144
144
|
```
|
145
145
|
|
146
|
-
### data attribute
|
146
|
+
### aria / data attribute
|
147
147
|
Completely compatible with Haml, hyphenation and boolean are supported.
|
148
148
|
|
149
149
|
```rb
|
@@ -156,6 +156,8 @@ Completely compatible with Haml, hyphenation and boolean are supported.
|
|
156
156
|
<div data-foo='bar'></div>
|
157
157
|
```
|
158
158
|
|
159
|
+
aria attribute works in the same way as data attribute.
|
160
|
+
|
159
161
|
### boolean attributes
|
160
162
|
No hyphenation but complete boolean support.
|
161
163
|
|
data/ext/hamlit/hamlit.c
CHANGED
@@ -5,9 +5,10 @@
|
|
5
5
|
|
6
6
|
VALUE mAttributeBuilder, mObjectRef;
|
7
7
|
static ID id_flatten, id_keys, id_parse, id_prepend, id_tr, id_uniq_bang;
|
8
|
-
static ID id_data, id_equal, id_hyphen, id_space, id_underscore;
|
8
|
+
static ID id_aria, id_data, id_equal, id_hyphen, id_space, id_underscore;
|
9
9
|
static ID id_boolean_attributes, id_xhtml;
|
10
10
|
|
11
|
+
static VALUE str_aria() { return rb_const_get(mAttributeBuilder, id_aria); }
|
11
12
|
static VALUE str_data() { return rb_const_get(mAttributeBuilder, id_data); }
|
12
13
|
static VALUE str_equal() { return rb_const_get(mAttributeBuilder, id_equal); }
|
13
14
|
static VALUE str_hyphen() { return rb_const_get(mAttributeBuilder, id_hyphen); }
|
@@ -166,32 +167,45 @@ hamlit_build_class(VALUE escape_attrs, VALUE array)
|
|
166
167
|
}
|
167
168
|
}
|
168
169
|
|
170
|
+
struct merge_data_attrs_var {
|
171
|
+
VALUE merged;
|
172
|
+
VALUE key_str;
|
173
|
+
};
|
174
|
+
|
169
175
|
static int
|
170
|
-
merge_data_attrs_i(VALUE key, VALUE value, VALUE
|
176
|
+
merge_data_attrs_i(VALUE key, VALUE value, VALUE ptr)
|
171
177
|
{
|
178
|
+
struct merge_data_attrs_var *arg = (struct merge_data_attrs_var *)ptr;
|
179
|
+
VALUE merged = arg->merged;
|
180
|
+
VALUE key_str = arg->key_str;
|
181
|
+
|
172
182
|
if (NIL_P(key)) {
|
173
|
-
rb_hash_aset(merged,
|
183
|
+
rb_hash_aset(merged, key_str, value);
|
174
184
|
} else {
|
175
|
-
key = rb_str_concat(rb_str_new_cstr("
|
185
|
+
key = rb_str_concat(rb_str_concat(rb_str_dup(key_str), rb_str_new_cstr("-")), to_s(key));
|
176
186
|
rb_hash_aset(merged, key, value);
|
177
187
|
}
|
178
188
|
return ST_CONTINUE;
|
179
189
|
}
|
180
190
|
|
181
191
|
static VALUE
|
182
|
-
merge_data_attrs(VALUE values)
|
192
|
+
merge_data_attrs(VALUE values, VALUE key_str)
|
183
193
|
{
|
184
194
|
long i;
|
185
195
|
VALUE value, merged = rb_hash_new();
|
186
196
|
|
187
197
|
for (i = 0; i < RARRAY_LEN(values); i++) {
|
198
|
+
struct merge_data_attrs_var arg;
|
199
|
+
arg.merged = merged;
|
200
|
+
arg.key_str = key_str;
|
201
|
+
|
188
202
|
value = rb_ary_entry(values, i);
|
189
203
|
switch (TYPE(value)) {
|
190
204
|
case T_HASH:
|
191
|
-
rb_hash_foreach(value, merge_data_attrs_i,
|
205
|
+
rb_hash_foreach(value, merge_data_attrs_i, (VALUE)&arg);
|
192
206
|
break;
|
193
207
|
default:
|
194
|
-
rb_hash_aset(merged,
|
208
|
+
rb_hash_aset(merged, key_str, value);
|
195
209
|
break;
|
196
210
|
}
|
197
211
|
}
|
@@ -255,12 +269,12 @@ flatten_data_attrs(VALUE attrs)
|
|
255
269
|
}
|
256
270
|
|
257
271
|
static VALUE
|
258
|
-
hamlit_build_data(VALUE escape_attrs, VALUE quote, VALUE values)
|
272
|
+
hamlit_build_data(VALUE escape_attrs, VALUE quote, VALUE values, VALUE key_str)
|
259
273
|
{
|
260
274
|
long i;
|
261
275
|
VALUE attrs, buf, keys, key, value;
|
262
276
|
|
263
|
-
attrs = merge_data_attrs(values);
|
277
|
+
attrs = merge_data_attrs(values, key_str);
|
264
278
|
attrs = flatten_data_attrs(attrs);
|
265
279
|
keys = rb_ary_sort_bang(rb_funcall(attrs, id_keys, 0));
|
266
280
|
buf = rb_str_new("", 0);
|
@@ -304,7 +318,7 @@ merge_all_attrs_i(VALUE key, VALUE value, VALUE merged)
|
|
304
318
|
VALUE array;
|
305
319
|
|
306
320
|
key = to_s(key);
|
307
|
-
if (str_eq(key, "id", 2) || str_eq(key, "class", 5) || str_eq(key, "data", 4)) {
|
321
|
+
if (str_eq(key, "id", 2) || str_eq(key, "class", 5) || str_eq(key, "data", 4) || str_eq(key, "aria", 4)) {
|
308
322
|
array = rb_hash_aref(merged, key);
|
309
323
|
if (NIL_P(array)) {
|
310
324
|
array = rb_ary_new2(1);
|
@@ -338,6 +352,7 @@ is_boolean_attribute(VALUE key)
|
|
338
352
|
{
|
339
353
|
VALUE boolean_attributes;
|
340
354
|
if (str_eq(rb_str_substr(key, 0, 5), "data-", 5)) return 1;
|
355
|
+
if (str_eq(rb_str_substr(key, 0, 5), "aria-", 5)) return 1;
|
341
356
|
|
342
357
|
boolean_attributes = rb_const_get(mAttributeBuilder, id_boolean_attributes);
|
343
358
|
return RTEST(rb_ary_includes(boolean_attributes, key));
|
@@ -364,7 +379,13 @@ hamlit_build_for_class(VALUE escape_attrs, VALUE quote, VALUE buf, VALUE values)
|
|
364
379
|
void
|
365
380
|
hamlit_build_for_data(VALUE escape_attrs, VALUE quote, VALUE buf, VALUE values)
|
366
381
|
{
|
367
|
-
rb_str_concat(buf, hamlit_build_data(escape_attrs, quote, values));
|
382
|
+
rb_str_concat(buf, hamlit_build_data(escape_attrs, quote, values, str_data()));
|
383
|
+
}
|
384
|
+
|
385
|
+
void
|
386
|
+
hamlit_build_for_aria(VALUE escape_attrs, VALUE quote, VALUE buf, VALUE values)
|
387
|
+
{
|
388
|
+
rb_str_concat(buf, hamlit_build_data(escape_attrs, quote, values, str_aria()));
|
368
389
|
}
|
369
390
|
|
370
391
|
void
|
@@ -422,6 +443,8 @@ hamlit_build(VALUE escape_attrs, VALUE quote, VALUE format, VALUE object_ref, VA
|
|
422
443
|
hamlit_build_for_class(escape_attrs, quote, buf, value);
|
423
444
|
} else if (str_eq(key, "data", 4)) {
|
424
445
|
hamlit_build_for_data(escape_attrs, quote, buf, value);
|
446
|
+
} else if (str_eq(key, "aria", 4)) {
|
447
|
+
hamlit_build_for_aria(escape_attrs, quote, buf, value);
|
425
448
|
} else if (is_boolean_attribute(key)) {
|
426
449
|
hamlit_build_for_boolean(escape_attrs, quote, format, buf, key, value);
|
427
450
|
} else {
|
@@ -454,6 +477,17 @@ rb_hamlit_build_class(int argc, VALUE *argv, RB_UNUSED_VAR(VALUE self))
|
|
454
477
|
return hamlit_build_class(argv[0], array);
|
455
478
|
}
|
456
479
|
|
480
|
+
static VALUE
|
481
|
+
rb_hamlit_build_aria(int argc, VALUE *argv, RB_UNUSED_VAR(VALUE self))
|
482
|
+
{
|
483
|
+
VALUE array;
|
484
|
+
|
485
|
+
rb_check_arity(argc, 2, UNLIMITED_ARGUMENTS);
|
486
|
+
rb_scan_args(argc - 2, argv + 2, "*", &array);
|
487
|
+
|
488
|
+
return hamlit_build_data(argv[0], argv[1], array, str_aria());
|
489
|
+
}
|
490
|
+
|
457
491
|
static VALUE
|
458
492
|
rb_hamlit_build_data(int argc, VALUE *argv, RB_UNUSED_VAR(VALUE self))
|
459
493
|
{
|
@@ -462,7 +496,7 @@ rb_hamlit_build_data(int argc, VALUE *argv, RB_UNUSED_VAR(VALUE self))
|
|
462
496
|
rb_check_arity(argc, 2, UNLIMITED_ARGUMENTS);
|
463
497
|
rb_scan_args(argc - 2, argv + 2, "*", &array);
|
464
498
|
|
465
|
-
return hamlit_build_data(argv[0], argv[1], array);
|
499
|
+
return hamlit_build_data(argv[0], argv[1], array, str_data());
|
466
500
|
}
|
467
501
|
|
468
502
|
static VALUE
|
@@ -490,6 +524,7 @@ Init_hamlit(void)
|
|
490
524
|
rb_define_singleton_method(mAttributeBuilder, "build", rb_hamlit_build, -1);
|
491
525
|
rb_define_singleton_method(mAttributeBuilder, "build_id", rb_hamlit_build_id, -1);
|
492
526
|
rb_define_singleton_method(mAttributeBuilder, "build_class", rb_hamlit_build_class, -1);
|
527
|
+
rb_define_singleton_method(mAttributeBuilder, "build_aria", rb_hamlit_build_aria, -1);
|
493
528
|
rb_define_singleton_method(mAttributeBuilder, "build_data", rb_hamlit_build_data, -1);
|
494
529
|
|
495
530
|
id_flatten = rb_intern("flatten");
|
@@ -499,6 +534,7 @@ Init_hamlit(void)
|
|
499
534
|
id_tr = rb_intern("tr");
|
500
535
|
id_uniq_bang = rb_intern("uniq!");
|
501
536
|
|
537
|
+
id_aria = rb_intern("ARIA");
|
502
538
|
id_data = rb_intern("DATA");
|
503
539
|
id_equal = rb_intern("EQUAL");
|
504
540
|
id_hyphen = rb_intern("HYPHEN");
|
@@ -508,6 +544,7 @@ Init_hamlit(void)
|
|
508
544
|
id_boolean_attributes = rb_intern("BOOLEAN_ATTRIBUTES");
|
509
545
|
id_xhtml = rb_intern("xhtml");
|
510
546
|
|
547
|
+
rb_const_set(mAttributeBuilder, id_aria, rb_obj_freeze(rb_str_new_cstr("aria")));
|
511
548
|
rb_const_set(mAttributeBuilder, id_data, rb_obj_freeze(rb_str_new_cstr("data")));
|
512
549
|
rb_const_set(mAttributeBuilder, id_equal, rb_obj_freeze(rb_str_new_cstr("=")));
|
513
550
|
rb_const_set(mAttributeBuilder, id_hyphen, rb_obj_freeze(rb_str_new_cstr("-")));
|
@@ -45,9 +45,9 @@ module Hamlit
|
|
45
45
|
compile_id!(temple, key, values)
|
46
46
|
when 'class'
|
47
47
|
compile_class!(temple, key, values)
|
48
|
-
when 'data'
|
48
|
+
when 'data', 'aria'
|
49
49
|
compile_data!(temple, key, values)
|
50
|
-
when *AttributeBuilder::BOOLEAN_ATTRIBUTES, /\Adata-/
|
50
|
+
when *AttributeBuilder::BOOLEAN_ATTRIBUTES, /\Adata-/, /\Aaria-/
|
51
51
|
compile_boolean!(temple, key, values)
|
52
52
|
else
|
53
53
|
compile_common!(temple, key, values)
|
@@ -76,7 +76,7 @@ module Hamlit
|
|
76
76
|
|
77
77
|
def compile_data!(temple, key, values)
|
78
78
|
args = [@escape_attrs.inspect, "#{@quote.inspect}.freeze", values.map { |v| literal_for(v) }]
|
79
|
-
build_code = "::Hamlit::AttributeBuilder.
|
79
|
+
build_code = "::Hamlit::AttributeBuilder.build_#{key}(#{args.join(', ')})"
|
80
80
|
|
81
81
|
if values.all? { |type, exp| type == :static || Temple::StaticAnalyzer.static?(exp) }
|
82
82
|
temple << [:static, eval(build_code).to_s]
|
data/lib/hamlit/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hamlit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: temple
|