aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2018-03-10 23:42:31 +0100
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2018-03-10 23:42:31 +0100
commit9c3065d9cfadd860eea1d96765c642c5a529d9d4 (patch)
tree18b014c98bccb07141491b2bda740743dba26b03
parentf7ae4bffadd232a758dfe9dce7025899b6fe7bad (diff)
downloadblogc-9c3065d9cfadd860eea1d96765c642c5a529d9d4.tar.gz
blogc-9c3065d9cfadd860eea1d96765c642c5a529d9d4.tar.bz2
blogc-9c3065d9cfadd860eea1d96765c642c5a529d9d4.zip
make: pass TAG_CLOUD variable to blogc.
this variable includes all the tags configured in blogcfile(5) as a space-separated string.
-rw-r--r--man/blogcfile.5.ronn6
-rw-r--r--src/blogc-make/exec.c6
-rw-r--r--tests/blogc-make/check_exec.c45
3 files changed, 56 insertions, 1 deletions
diff --git a/man/blogcfile.5.ronn b/man/blogcfile.5.ronn
index 4fe3de8..f93d0af 100644
--- a/man/blogcfile.5.ronn
+++ b/man/blogcfile.5.ronn
@@ -136,6 +136,10 @@ The `[tags]` section is a listing of the tags that should be listed in the
website. blogc-make(1) will generate post listing indexes and Atom feeds for
each tag listed in the section.
+The tags will be also provided to blogc as a `TAG_CLOUD` variable, that is a
+space-separated list of the tags, useful to generate tag clouds using the
+`foreach` template iterator. See blogc-template(7).
+
### Copy listing
The `[copy]` section is a listing of the files that should be copied to the
@@ -180,4 +184,4 @@ Rafael G. Martins &lt;<rafael@rafaelmartins.eng.br>&gt;
## SEE ALSO
-blogc(1), blogc-make(1), strftime(3)
+blogc(1), blogc-make(1), blogc-template(7) strftime(3)
diff --git a/src/blogc-make/exec.c b/src/blogc-make/exec.c
index 551c7d7..a324d47 100644
--- a/src/blogc-make/exec.c
+++ b/src/blogc-make/exec.c
@@ -235,6 +235,12 @@ bm_exec_build_blogc_cmd(const char *blogc_bin, bm_settings_t *settings,
bc_string_append(rv, blogc_bin);
if (settings != NULL) {
+ if (settings->tags != NULL) {
+ char *tags = bc_strv_join(settings->tags, " ");
+ bc_string_append_printf(rv, " -D TAG_CLOUD='%s'", tags);
+ free(tags);
+ }
+
bc_trie_foreach(settings->global,
(bc_trie_foreach_func_t) list_variables, rv);
}
diff --git a/tests/blogc-make/check_exec.c b/tests/blogc-make/check_exec.c
index e0c9931..a6cec3e 100644
--- a/tests/blogc-make/check_exec.c
+++ b/tests/blogc-make/check_exec.c
@@ -83,6 +83,7 @@ test_build_blogc_cmd_with_settings(void **state)
bc_trie_insert(settings->global, "BAR", bc_strdup("BAZ"));
bc_trie_t *variables = bc_trie_new(free);
bc_trie_insert(variables, "LOL", bc_strdup("HEHE"));
+ settings->tags = NULL;
char *rv = bm_exec_build_blogc_cmd("blogc", settings, variables, true,
"main.tmpl", "foo.html", false, true);
@@ -121,6 +122,7 @@ test_build_blogc_cmd_with_settings_and_dev(void **state)
bc_trie_insert(settings->global, "BAR", bc_strdup("BAZ"));
bc_trie_t *variables = bc_trie_new(free);
bc_trie_insert(variables, "LOL", bc_strdup("HEHE"));
+ settings->tags = NULL;
char *rv = bm_exec_build_blogc_cmd("blogc", settings, variables, true,
"main.tmpl", "foo.html", true, true);
@@ -151,6 +153,48 @@ test_build_blogc_cmd_with_settings_and_dev(void **state)
static void
+test_build_blogc_cmd_with_settings_and_tags(void **state)
+{
+ bm_settings_t *settings = bc_malloc(sizeof(bm_settings_t));
+ settings->settings = bc_trie_new(free);
+ bc_trie_insert(settings->settings, "locale", bc_strdup("en_US.utf8"));
+ settings->global = bc_trie_new(free);
+ bc_trie_insert(settings->global, "FOO", bc_strdup("BAR"));
+ bc_trie_insert(settings->global, "BAR", bc_strdup("BAZ"));
+ bc_trie_t *variables = bc_trie_new(free);
+ bc_trie_insert(variables, "LOL", bc_strdup("HEHE"));
+ settings->tags = bc_str_split("asd foo bar", ' ', 0);
+
+ char *rv = bm_exec_build_blogc_cmd("blogc", settings, variables, true,
+ "main.tmpl", "foo.html", true, true);
+ assert_string_equal(rv,
+ "LC_ALL='en_US.utf8' blogc -D TAG_CLOUD='asd foo bar' -D FOO='BAR' "
+ "-D BAR='BAZ' -D LOL='HEHE' -D MAKE_ENV_DEV=1 -D MAKE_ENV='dev' -l -t "
+ "'main.tmpl' -o 'foo.html' -i");
+ free(rv);
+
+ rv = bm_exec_build_blogc_cmd("blogc", settings, variables, false, NULL, NULL,
+ true, false);
+ assert_string_equal(rv,
+ "LC_ALL='en_US.utf8' blogc -D TAG_CLOUD='asd foo bar' -D FOO='BAR' "
+ "-D BAR='BAZ' -D LOL='HEHE' -D MAKE_ENV_DEV=1 -D MAKE_ENV='dev'");
+ free(rv);
+
+ rv = bm_exec_build_blogc_cmd("blogc", settings, NULL, false, NULL, NULL,
+ true, false);
+ assert_string_equal(rv,
+ "LC_ALL='en_US.utf8' blogc -D TAG_CLOUD='asd foo bar' -D FOO='BAR' "
+ "-D BAR='BAZ' -D MAKE_ENV_DEV=1 -D MAKE_ENV='dev'");
+ free(rv);
+
+ bc_trie_free(variables);
+ bc_trie_free(settings->settings);
+ bc_trie_free(settings->global);
+ free(settings);
+}
+
+
+static void
test_build_blogc_cmd_without_settings(void **state)
{
bc_trie_t *variables = bc_trie_new(free);
@@ -187,6 +231,7 @@ main(void)
#endif
unit_test(test_build_blogc_cmd_with_settings),
unit_test(test_build_blogc_cmd_with_settings_and_dev),
+ unit_test(test_build_blogc_cmd_with_settings_and_tags),
unit_test(test_build_blogc_cmd_without_settings),
};
return run_tests(tests);