aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--man/blogc-template.7.ronn14
-rw-r--r--src/renderer.c12
-rw-r--r--tests/check_renderer.c10
3 files changed, 19 insertions, 17 deletions
diff --git a/man/blogc-template.7.ronn b/man/blogc-template.7.ronn
index 46413c2..2875e36 100644
--- a/man/blogc-template.7.ronn
+++ b/man/blogc-template.7.ronn
@@ -176,15 +176,13 @@ The content of a `foreach` iterator is included in the output file when the targ
variable is defined, and is repeated for each item in the list parsed from the variable
value.
-The variable value should be formatted as a comma-separated list of items. Quotes are
+The variable value should be formatted as a space-separated list of items. Quotes are
not supported, as this is intended to work with identifiers, like slugs, and not with
arbitrary strings.
-Spaces and tabs before and after list items are stripped for consistency.
+This is how a variable value would be formatted:
-This is how a variable would be formatted:
-
- item1, item2, item3
+ item1 item2 item3
For more info about how to define variables, see blogc(1) and blogc-source(7).
@@ -194,12 +192,12 @@ This is how a `foreach` iterator is defined in a template:
<a href="/tag/{{ FOREACH_ITEM }}/">{{ FOREACH_ITEM }}</a>
{% endforeach %}
-Where `TAGS` is the variable with comma-separated list of items, and `FOREACH_ITEM`
+Where `TAGS` is the variable with space-separated list of items, and `FOREACH_ITEM`
is the variable defined by blogc(1), that will store the item value for a given
iteration.
-If the value of the `TAGS` variable is "item1, item2, item3", this template would be
-rendered as 3 times, one for each item value.
+If the value of the `TAGS` variable is "item1 item2 item3", this template is
+rendered 3 times, one for each item value.
## BUGS
diff --git a/src/renderer.c b/src/renderer.c
index 6cf924e..defbe10 100644
--- a/src/renderer.c
+++ b/src/renderer.c
@@ -97,10 +97,14 @@ blogc_split_list_variable(const char *name, b_trie_t *global, b_trie_t *local)
b_slist_t *rv = NULL;
- char **tmp = b_str_split(value, ',', 0);
- for (unsigned int i = 0; tmp[i] != NULL; i++)
- rv = b_slist_append(rv, b_strdup(b_str_strip(tmp[i])));
- b_strv_free(tmp);
+ char **tmp = b_str_split(value, ' ', 0);
+ for (unsigned int i = 0; tmp[i] != NULL; i++) {
+ if (tmp[i][0] != '\0') // ignore empty strings
+ rv = b_slist_append(rv, tmp[i]);
+ else
+ free(tmp[i]);
+ }
+ free(tmp);
return rv;
}
diff --git a/tests/check_renderer.c b/tests/check_renderer.c
index cc04fdc..e380be7 100644
--- a/tests/check_renderer.c
+++ b/tests/check_renderer.c
@@ -31,7 +31,7 @@ create_sources(unsigned int count)
"GUDA2: zxc\n"
"DATE: 2015-01-02 03:04:05\n"
"DATE_FORMAT: %R\n"
- "TAGS: foo, bar,baz\n"
+ "TAGS: foo bar baz\n"
"-----\n"
"ahahahahahahahaha",
"BOLA: asd2\n"
@@ -796,9 +796,9 @@ static void
test_split_list_variable(void **state)
{
b_trie_t *g = b_trie_new(free);
- b_trie_insert(g, "TAGS", b_strdup("asd, lol,hehe"));
+ b_trie_insert(g, "TAGS", b_strdup("asd lol hehe"));
b_trie_t *l = b_trie_new(free);
- b_trie_insert(l, "TAGS", b_strdup("asd, lol,XD"));
+ b_trie_insert(l, "TAGS", b_strdup("asd lol XD"));
b_slist_t *tmp = blogc_split_list_variable("TAGS", g, l);
assert_string_equal(tmp->data, "asd");
assert_string_equal(tmp->next->data, "lol");
@@ -813,9 +813,9 @@ static void
test_split_list_variable_not_found(void **state)
{
b_trie_t *g = b_trie_new(free);
- b_trie_insert(g, "TAGS", b_strdup("asd, lol,hehe"));
+ b_trie_insert(g, "TAGS", b_strdup("asd lol hehe"));
b_trie_t *l = b_trie_new(free);
- b_trie_insert(l, "TAGS", b_strdup("asd, lol,XD"));
+ b_trie_insert(l, "TAGS", b_strdup("asd lol XD"));
b_slist_t *tmp = blogc_split_list_variable("TAG", g, l);
assert_null(tmp);
b_trie_free(g);