From 7582a32c837c8b55613b547799d1a6405e926cba Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Thu, 23 Apr 2015 19:44:39 -0300 Subject: template parser: added "if not" support --- src/renderer.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/renderer.c') diff --git a/src/renderer.c b/src/renderer.c index 69206c3..92fa7d4 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -34,6 +34,8 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, bool listing) unsigned int if_count = 0; unsigned int if_skip = 0; + bool if_not = false; + b_slist_t *tmp = tmpl; while (tmp != NULL) { blogc_template_stmt_t *stmt = tmp->data; @@ -104,9 +106,14 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, bool listing) } break; + case BLOGC_TEMPLATE_IF_NOT_STMT: + if_not = true; + case BLOGC_TEMPLATE_IF_STMT: if (stmt->value != NULL && tmp_source != NULL) { - if (b_trie_lookup(tmp_source, stmt->value) == NULL) { + if ((!if_not && (b_trie_lookup(tmp_source, stmt->value) == NULL)) || + (if_not && (b_trie_lookup(tmp_source, stmt->value) != NULL))) + { if_skip = if_count; // at this point we can just skip anything, counting the @@ -115,7 +122,9 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, bool listing) while (1) { tmp = tmp->next; stmt = tmp->data; - if (stmt->type == BLOGC_TEMPLATE_IF_STMT) { + if ((stmt->type == BLOGC_TEMPLATE_IF_STMT) || + (stmt->type == BLOGC_TEMPLATE_IF_NOT_STMT)) + { if_count++; continue; } @@ -129,6 +138,7 @@ blogc_render(b_slist_t *tmpl, b_slist_t *sources, bool listing) } } } + if_not = false; } break; -- cgit v1.2.3-18-g5258