From 8e12ae57ebe87d25c2c34ec304047fec3013da85 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Sat, 16 May 2020 03:33:22 +0200 Subject: blogc: added listing_empty template block --- src/blogc/renderer.c | 13 +++++++++++++ src/blogc/template-parser.c | 10 +++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/blogc/renderer.c b/src/blogc/renderer.c index 140a86e..8f576e0 100644 --- a/src/blogc/renderer.c +++ b/src/blogc/renderer.c @@ -242,6 +242,7 @@ blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_slist_t *listing_entries, tmp_source = listing_entry; } else if ((0 == strcmp("listing", node->data[0])) || + (0 == strcmp("listing_empty", node->data[0])) || (0 == strcmp("listing_once", node->data[0]))) { if (!listing) { @@ -254,6 +255,18 @@ blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_slist_t *listing_entries, break; } } + if (0 == strcmp("listing_empty", node->data[0])) { + if (sources != NULL) { + + // we can just skip anything and walk until the next + // 'endblock' + while (node->type != BLOGC_TEMPLATE_NODE_ENDBLOCK) { + tmp = tmp->next; + node = tmp->data; + } + break; + } + } if (0 == strcmp("listing", node->data[0])) { if (sources == NULL) { diff --git a/src/blogc/template-parser.c b/src/blogc/template-parser.c index 0b4eb55..d3e9daf 100644 --- a/src/blogc/template-parser.c +++ b/src/blogc/template-parser.c @@ -379,6 +379,14 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err) state = TEMPLATE_BLOCK_END_WHITESPACE_CLEANER; break; } + else if ((current - start == 13) && + (0 == strncmp("listing_empty", src + start, 13))) + { + block_open = true; + end = current; + state = TEMPLATE_BLOCK_END_WHITESPACE_CLEANER; + break; + } else if ((current - start == 13) && (0 == strncmp("listing_entry", src + start, 13))) { @@ -391,7 +399,7 @@ blogc_template_parse(const char *src, size_t src_len, bc_error_t **err) *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src, src_len, current, "Invalid block type. Allowed types are: 'entry', 'listing', " - "'listing_once' and 'listing_entry'."); + "'listing_once', 'listing_empty' and 'listing_entry'."); break; case TEMPLATE_BLOCK_IF_START: -- cgit v1.2.3-18-g5258