1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Refactor hamlit_build_id

This commit is contained in:
Takashi Kokubun 2015-11-28 15:45:56 +09:00
parent f0a8d77e10
commit f8c6d4b901

View file

@ -5,6 +5,20 @@
VALUE mAttributeBuilder;
static ID id_flatten, id_underscore;
static void
delete_falsey_values(VALUE values)
{
VALUE value;
long i;
for (i = RARRAY_LEN(values) - 1; 0 <= i; i--) {
value = rb_ary_entry(values, i);
if (!RTEST(value)) {
rb_ary_delete_at(values, i);
}
}
}
static VALUE
escape_html(VALUE str)
{
@ -20,6 +34,16 @@ escape_html(VALUE str)
return str;
}
static VALUE
escape_attribute(VALUE escape_attrs, VALUE str)
{
if (RTEST(escape_attrs)) {
return escape_html(str);
} else {
return str;
}
}
static VALUE
rb_escape_html(RB_UNUSED_VAR(VALUE self), VALUE str)
{
@ -27,26 +51,15 @@ rb_escape_html(RB_UNUSED_VAR(VALUE self), VALUE str)
}
static VALUE
hamlit_build_id(VALUE escape_attrs, VALUE ids)
hamlit_build_id(VALUE escape_attrs, VALUE values)
{
VALUE id, attr_value;
long i;
VALUE attr_value;
ids = rb_funcall(ids, id_flatten, 0);
values = rb_funcall(values, id_flatten, 0);
delete_falsey_values(values);
for (i = RARRAY_LEN(ids) - 1; 0 <= i; i--) {
id = rb_ary_entry(ids, i);
if (!RTEST(id)) {
rb_ary_delete_at(ids, i);
}
}
attr_value = rb_ary_join(ids, rb_const_get(mAttributeBuilder, id_underscore));
if (RTEST(escape_attrs)) {
attr_value = escape_html(attr_value);
}
return attr_value;
attr_value = rb_ary_join(values, rb_const_get(mAttributeBuilder, id_underscore));
return escape_attribute(escape_attrs, attr_value);
}
static VALUE