forked from external/yambar
oarticles: don't assume particle content is a dictionary
This is done by having each particle implement a top-level verifier function.
This commit is contained in:
parent
9944a8f972
commit
8bc6a0b783
8 changed files with 77 additions and 27 deletions
|
@ -292,8 +292,10 @@ conf_verify_particle_dictionary(keychain_t *chain, const struct yml_node *node)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(info->verify_conf != NULL);
|
||||||
|
|
||||||
chain_push(chain, particle_name);
|
chain_push(chain, particle_name);
|
||||||
if (!conf_verify_dict(chain, values, info->attrs))
|
if (!info->verify_conf(chain, values))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
chain_pop(chain);
|
chain_pop(chain);
|
||||||
|
|
|
@ -14,11 +14,11 @@ struct particle;
|
||||||
struct exposable;
|
struct exposable;
|
||||||
|
|
||||||
struct particle_info {
|
struct particle_info {
|
||||||
|
bool (*verify_conf)(keychain_t *chain, const struct yml_node *node);
|
||||||
struct particle *(*from_conf)(const struct yml_node *node,
|
struct particle *(*from_conf)(const struct yml_node *node,
|
||||||
const struct font *parent_font,
|
const struct font *parent_font,
|
||||||
int left_margin, int right_margin,
|
int left_margin, int right_margin,
|
||||||
const char *on_click_template);
|
const char *on_click_template);
|
||||||
const struct attr_info attrs[];
|
|
||||||
|
|
||||||
#define PARTICLE_COMMON_ATTRS_COUNT 5
|
#define PARTICLE_COMMON_ATTRS_COUNT 5
|
||||||
#define PARTICLE_COMMON_ATTRS \
|
#define PARTICLE_COMMON_ATTRS \
|
||||||
|
|
|
@ -48,9 +48,17 @@ from_conf(const struct yml_node *node, const struct font *parent_font,
|
||||||
return empty_new(left_margin, right_margin, on_click_template);
|
return empty_new(left_margin, right_margin, on_click_template);
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct particle_info plugin_info = {
|
static bool
|
||||||
.from_conf = &from_conf,
|
verify_conf(keychain_t *chain, const struct yml_node *node)
|
||||||
.attrs = {
|
{
|
||||||
|
static const struct attr_info attrs[] = {
|
||||||
PARTICLE_COMMON_ATTRS,
|
PARTICLE_COMMON_ATTRS,
|
||||||
},
|
};
|
||||||
|
|
||||||
|
return conf_verify_dict(chain, node, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct particle_info plugin_info = {
|
||||||
|
.verify_conf = &verify_conf,
|
||||||
|
.from_conf = &from_conf,
|
||||||
};
|
};
|
||||||
|
|
|
@ -198,13 +198,21 @@ from_conf(const struct yml_node *node, const struct font *parent_font,
|
||||||
on_click_template);
|
on_click_template);
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct particle_info plugin_info = {
|
static bool
|
||||||
.from_conf = &from_conf,
|
verify_conf(keychain_t *chain, const struct yml_node *node)
|
||||||
.attrs = {
|
{
|
||||||
|
static const struct attr_info attrs[] = {
|
||||||
{"items", true, &conf_verify_particle_list_items},
|
{"items", true, &conf_verify_particle_list_items},
|
||||||
{"spacing", false, &conf_verify_int},
|
{"spacing", false, &conf_verify_int},
|
||||||
{"left-spacing", false, &conf_verify_int},
|
{"left-spacing", false, &conf_verify_int},
|
||||||
{"right-spacing", false, &conf_verify_int},
|
{"right-spacing", false, &conf_verify_int},
|
||||||
PARTICLE_COMMON_ATTRS,
|
PARTICLE_COMMON_ATTRS,
|
||||||
},
|
};
|
||||||
|
|
||||||
|
return conf_verify_dict(chain, node, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct particle_info plugin_info = {
|
||||||
|
.verify_conf = &verify_conf,
|
||||||
|
.from_conf = &from_conf,
|
||||||
};
|
};
|
||||||
|
|
|
@ -228,12 +228,20 @@ from_conf(const struct yml_node *node, const struct font *parent_font,
|
||||||
default_particle, left_margin, right_margin, on_click_template);
|
default_particle, left_margin, right_margin, on_click_template);
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct particle_info plugin_info = {
|
static bool
|
||||||
.from_conf = &from_conf,
|
verify_conf(keychain_t *chain, const struct yml_node *node)
|
||||||
.attrs = {
|
{
|
||||||
|
static const struct attr_info attrs[] = {
|
||||||
{"tag", true, &conf_verify_string},
|
{"tag", true, &conf_verify_string},
|
||||||
{"values", true, &verify_map_values},
|
{"values", true, &verify_map_values},
|
||||||
{"default", false, &conf_verify_particle},
|
{"default", false, &conf_verify_particle},
|
||||||
PARTICLE_COMMON_ATTRS,
|
PARTICLE_COMMON_ATTRS,
|
||||||
},
|
};
|
||||||
|
|
||||||
|
return conf_verify_dict(chain, node, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct particle_info plugin_info = {
|
||||||
|
.verify_conf = &verify_conf,
|
||||||
|
.from_conf = &from_conf,
|
||||||
};
|
};
|
||||||
|
|
|
@ -257,9 +257,10 @@ from_conf(const struct yml_node *node, const struct font *parent_font,
|
||||||
left_margin, right_margin, on_click_template);
|
left_margin, right_margin, on_click_template);
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct particle_info plugin_info = {
|
static bool
|
||||||
.from_conf = &from_conf,
|
verify_conf(keychain_t *chain, const struct yml_node *node)
|
||||||
.attrs = {
|
{
|
||||||
|
static const struct attr_info attrs[] = {
|
||||||
{"tag", true, &conf_verify_string},
|
{"tag", true, &conf_verify_string},
|
||||||
{"length", true, &conf_verify_int},
|
{"length", true, &conf_verify_int},
|
||||||
/* TODO: make these optional? Default to empty */
|
/* TODO: make these optional? Default to empty */
|
||||||
|
@ -269,5 +270,12 @@ const struct particle_info plugin_info = {
|
||||||
{"empty", true, &conf_verify_particle},
|
{"empty", true, &conf_verify_particle},
|
||||||
{"indicator", true, &conf_verify_particle},
|
{"indicator", true, &conf_verify_particle},
|
||||||
PARTICLE_COMMON_ATTRS,
|
PARTICLE_COMMON_ATTRS,
|
||||||
},
|
};
|
||||||
|
|
||||||
|
return conf_verify_dict(chain, node, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct particle_info plugin_info = {
|
||||||
|
.verify_conf = &verify_conf,
|
||||||
|
.from_conf = &from_conf,
|
||||||
};
|
};
|
||||||
|
|
|
@ -178,11 +178,19 @@ from_conf(const struct yml_node *node, const struct font *parent_font,
|
||||||
on_click_template);
|
on_click_template);
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct particle_info plugin_info = {
|
static bool
|
||||||
.from_conf = &from_conf,
|
verify_conf(keychain_t *chain, const struct yml_node *node)
|
||||||
.attrs = {
|
{
|
||||||
|
static const struct attr_info attrs[] = {
|
||||||
{"tag", true, &conf_verify_string},
|
{"tag", true, &conf_verify_string},
|
||||||
{"items", true, &conf_verify_particle_list_items},
|
{"items", true, &conf_verify_particle_list_items},
|
||||||
PARTICLE_COMMON_ATTRS,
|
PARTICLE_COMMON_ATTRS,
|
||||||
},
|
};
|
||||||
|
|
||||||
|
return conf_verify_dict(chain, node, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct particle_info plugin_info = {
|
||||||
|
.verify_conf = &verify_conf,
|
||||||
|
.from_conf = &from_conf,
|
||||||
};
|
};
|
||||||
|
|
|
@ -171,13 +171,21 @@ from_conf(const struct yml_node *node, const struct font *parent_font,
|
||||||
fg_color, left_margin, right_margin, on_click_template);
|
fg_color, left_margin, right_margin, on_click_template);
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct particle_info plugin_info = {
|
static bool
|
||||||
.from_conf = &from_conf,
|
verify_conf(keychain_t *chain, const struct yml_node *node)
|
||||||
.attrs = {
|
{
|
||||||
|
static const struct attr_info attrs[] = {
|
||||||
{"text", true, &conf_verify_string},
|
{"text", true, &conf_verify_string},
|
||||||
{"max", false, &conf_verify_int},
|
{"max", false, &conf_verify_int},
|
||||||
{"font", false, &conf_verify_font},
|
{"font", false, &conf_verify_font},
|
||||||
{"foreground", false, &conf_verify_color},
|
{"foreground", false, &conf_verify_color},
|
||||||
PARTICLE_COMMON_ATTRS,
|
PARTICLE_COMMON_ATTRS,
|
||||||
},
|
};
|
||||||
|
|
||||||
|
return conf_verify_dict(chain, node, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct particle_info plugin_info = {
|
||||||
|
.verify_conf = &verify_conf,
|
||||||
|
.from_conf = &from_conf,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue