aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main.c7
-rw-r--r--src/renderer.c12
-rw-r--r--tests/check_renderer.c30
3 files changed, 43 insertions, 6 deletions
diff --git a/src/main.c b/src/main.c
index 06b8714..616641f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -195,12 +195,9 @@ main(int argc, char **argv)
sources = b_slist_append(sources, b_strdup(argv[i]));
}
- if (b_slist_length(sources) == 0) {
+ if (!listing && b_slist_length(sources) == 0) {
blogc_print_usage();
- if (listing)
- fprintf(stderr, "blogc: error: at least one source file is required\n");
- else
- fprintf(stderr, "blogc: error: one source file is required\n");
+ fprintf(stderr, "blogc: error: one source file is required\n");
rv = 2;
goto cleanup;
}
diff --git a/src/renderer.c b/src/renderer.c
index bf8b8cc..47a5f87 100644
--- a/src/renderer.c
+++ b/src/renderer.c
@@ -71,7 +71,7 @@ blogc_format_date(const char *date, b_trie_t *global, b_trie_t *local)
char*
blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing)
{
- if (tmpl == NULL || sources == NULL)
+ if (tmpl == NULL)
return NULL;
b_slist_t *current_source = NULL;
@@ -136,6 +136,16 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, b_trie_t *config, bool listing
}
}
if (0 == strcmp("listing", stmt->value)) {
+ if (sources == NULL) {
+
+ // we can just skip anything and walk until the next
+ // 'endblock'
+ while (stmt->type != BLOGC_TEMPLATE_ENDBLOCK_STMT) {
+ tmp = tmp->next;
+ stmt = tmp->data;
+ }
+ break;
+ }
if (current_source == NULL) {
listing_start = tmp;
current_source = sources;
diff --git a/tests/check_renderer.c b/tests/check_renderer.c
index 154a8f0..fbe38de 100644
--- a/tests/check_renderer.c
+++ b/tests/check_renderer.c
@@ -143,6 +143,35 @@ test_render_listing(void **state)
static void
+test_render_listing_empty(void **state)
+{
+ const char *str =
+ "foo\n"
+ "{% block listing_once %}fuuu{% endblock %}\n"
+ "{% block entry %}\n"
+ "{% ifdef GUDA %}{{ GUDA }}{% endif %}\n"
+ "{% ifdef CHUNDA %}{{ CHUNDA }}{% endif %}\n"
+ "{% endblock %}\n"
+ "{% block listing %}\n"
+ "{% ifdef DATE_FORMATTED %}{{ DATE_FORMATTED }}{% endif %}\n"
+ "bola: {% ifdef BOLA %}{{ BOLA }}{% endif %}\n"
+ "{% endblock %}\n";
+ blogc_error_t *err = NULL;
+ b_slist_t *l = blogc_template_parse(str, strlen(str), &err);
+ assert_non_null(l);
+ assert_null(err);
+ char *out = blogc_render(l, NULL, NULL, true);
+ assert_string_equal(out,
+ "foo\n"
+ "fuuu\n"
+ "\n"
+ "\n");
+ blogc_template_free_stmts(l);
+ free(out);
+}
+
+
+static void
test_render_ifdef(void **state)
{
const char *str =
@@ -685,6 +714,7 @@ main(void)
const UnitTest tests[] = {
unit_test(test_render_entry),
unit_test(test_render_listing),
+ unit_test(test_render_listing_empty),
unit_test(test_render_ifdef),
unit_test(test_render_ifdef2),
unit_test(test_render_ifdef3),