diff options
-rw-r--r-- | man/blogc-template.7.ronn | 15 | ||||
-rw-r--r-- | man/blogc.1.ronn | 34 | ||||
-rw-r--r-- | src/blogc/main.c | 30 | ||||
-rw-r--r-- | src/blogc/renderer.c | 16 | ||||
-rw-r--r-- | src/blogc/renderer.h | 4 | ||||
-rw-r--r-- | src/blogc/template-parser.c | 12 | ||||
-rwxr-xr-x | tests/blogc/check_blogc.sh.in | 97 | ||||
-rw-r--r-- | tests/blogc/check_renderer.c | 160 | ||||
-rw-r--r-- | tests/blogc/check_template_parser.c | 13 |
9 files changed, 332 insertions, 49 deletions
diff --git a/man/blogc-template.7.ronn b/man/blogc-template.7.ronn index afa884b..cf397b7 100644 --- a/man/blogc-template.7.ronn +++ b/man/blogc-template.7.ronn @@ -87,6 +87,21 @@ that the `TITLE` variable is defined: </ul> {% endblock %} +### listing_entry block + +This block is identical to the `entry` block, but its content is included in +the output file only when blogc(1) is called with `-l` and `-e` <SOURCE>. The +variables available in the block are provided by the source file provided +using `-e`. + +This is how a `listing_entry` block is defined: + + {% block listing_entry %} + This content will only be included when rendering a listing, but with + content provided by a single entry. + {% endblock %} + + ## TEMPLATE VARIABLES Template variables are used to provide content to templates from blogc(1) diff --git a/man/blogc.1.ronn b/man/blogc.1.ronn index 11af48c..8bcd12d 100644 --- a/man/blogc.1.ronn +++ b/man/blogc.1.ronn @@ -4,14 +4,15 @@ blogc(1) -- a blog compiler ## SYNOPSIS `blogc` [`-d`] [`-D` <KEY>=<VALUE> ...] `-t` <TEMPLATE> [`-o` <OUTPUT>] <SOURCE><br> -`blogc` `-l` [`-d`] [`-D` <KEY>=<VALUE> ...] `-t` <TEMPLATE> [`-o` <OUTPUT>] [<SOURCE> ...]<br> -`blogc` `-l` `-p` <KEY> [`-d`] [`-D` <KEY>=<VALUE> ...] [<SOURCE> ...]<br> +`blogc` `-l` [`-e` <SOURCE>] [`-d`] [`-D` <KEY>=<VALUE> ...] `-t` <TEMPLATE> [`-o` <OUTPUT>] [<SOURCE> ...]<br> +`blogc` `-l` [`-e` <SOURCE>] [`-d`] [`-D` <KEY>=<VALUE> ...] `-t` <TEMPLATE> [`-o` <OUTPUT>] [<SOURCE> ...]<br> +`blogc` `-l` [`-e` <SOURCE>] `-p` <KEY> [`-d`] [`-D` <KEY>=<VALUE> ...] [<SOURCE> ...]<br> `blogc` `-i` [`-d`] [`-D` <KEY>=<VALUE> ...] `-t` <TEMPLATE> [`-o` <OUTPUT>] < <FILE_LIST><br> -`blogc` `-i` `-l` [`-d`] [`-D` <KEY>=<VALUE> ...] `-t` <TEMPLATE> [`-o` <OUTPUT>] < <FILE_LIST><br> -`blogc` `-i` `-l` `-p` <KEY> [`-d`] [`-D` <KEY>=<VALUE> ...] < <FILE_LIST><br> +`blogc` `-i` `-l` [`-e` <SOURCE>] [`-d`] [`-D` <KEY>=<VALUE> ...] `-t` <TEMPLATE> [`-o` <OUTPUT>] < <FILE_LIST><br> +`blogc` `-i` `-l` [`-e` <SOURCE>] `-p` <KEY> [`-d`] [`-D` <KEY>=<VALUE> ...] < <FILE_LIST><br> `echo` `-e` "<SOURCE>\n..." | `blogc` `-i` [`-d`] [`-D` <KEY>=<VALUE> ...] `-t` <TEMPLATE> [`-o` <OUTPUT>]<br> -`echo` `-e` "<SOURCE>\n..." | `blogc` `-i` `-l` [`-d`] [`-D` <KEY>=<VALUE> ...] `-t` <TEMPLATE> [`-o` <OUTPUT>]<br> -`echo` `-e` "<SOURCE>\n..." | `blogc` `-i` `-l` `-p` <KEY> [`-d`] [`-D` <KEY>=<VALUE> ...]<br> +`echo` `-e` "<SOURCE>\n..." | `blogc` `-i` `-l` [`-e` <SOURCE>] [`-d`] [`-D` <KEY>=<VALUE> ...] `-t` <TEMPLATE> [`-o` <OUTPUT>]<br> +`echo` `-e` "<SOURCE>\n..." | `blogc` `-i` `-l` [`-e` <SOURCE>] `-p` <KEY> [`-d`] [`-D` <KEY>=<VALUE> ...]<br> `blogc` [`-h`|`-v`] ## DESCRIPTION @@ -29,10 +30,14 @@ designed to be used with make(1). page or a post. * `listing`: - Listing mode, second example in [SYNOPSIS][], activated when - calling `blogc` with `-l` option. Accepts multiple source files, and allow - users to iterate over the content of all the source files to produce listing - pages, like indexes and feeds. + Listing mode, second example in [SYNOPSIS][], activated when calling `blogc` + with `-l` option. Accepts multiple source files, and allow users to iterate + over the content of all the source files to produce listing pages, like + indexes and feeds. By providing another source file to `blogc` with `-e` + option, third example in [SYNOPSIS][], its content will be available for usage + during listing, similar to the default entry mode. This is useful for users + that want to have an index page with content and posts listing together. + See blogc-template(7) for details. ## OPTIONS @@ -50,6 +55,11 @@ designed to be used with make(1). Activates listing mode, allowing user to provide multiple source files. See blogc-source(7) for details. + * `-e` <SOURCE>: + When used together with `-l` the source file will be parsed and its content + will be made available for usage in the templates in listing mode. See + blogc-template(7) for details. + * `-D` <KEY>=<VALUE>: Set global configuration parameter. <KEY> must be an ascii uppercase string, with only letters, numbers (after the first letter) and underscores (after @@ -100,6 +110,10 @@ Build index from source files: $ blogc -l -t template.tmpl -o index.html source1.txt source2.txt source3.txt +Build index from source files, with additional content from `index.txt`: + + $ blogc -l -e index.txt -t template.tmpl -o index.html source1.txt source2.txt source3.txt + Build entry page from source file: $ blogc -t template.tmpl -o entry.html entry.txt diff --git a/src/blogc/main.c b/src/blogc/main.c index bae3c80..5a4df99 100644 --- a/src/blogc/main.c +++ b/src/blogc/main.c @@ -54,8 +54,8 @@ blogc_print_help(void) #ifdef MAKE_EMBEDDED "[-m] " #endif - "[-h] [-v] [-d] [-i] [-l] [-D KEY=VALUE ...] [-p KEY] [-t TEMPLATE]\n" - " [-o OUTPUT] [SOURCE ...] - A blog compiler.\n" + "[-h] [-v] [-d] [-i] [-l [-e SOURCE]] [-D KEY=VALUE ...] [-p KEY]\n" + " [-t TEMPLATE] [-o OUTPUT] [SOURCE ...] - A blog compiler.\n" "\n" "positional arguments:\n" " SOURCE source file(s)\n" @@ -66,6 +66,7 @@ blogc_print_help(void) " -d enable debug\n" " -i read list of source files from standard input\n" " -l build listing page, from multiple source files\n" + " -e SOURCE source file with content for listing page. requires '-l'\n" " -D KEY=VALUE set global variable\n" " -p KEY show the value of a variable after source parsing and exit\n" " -t TEMPLATE template file\n" @@ -85,8 +86,8 @@ blogc_print_usage(void) #ifdef MAKE_EMBEDDED "[-m] " #endif - "[-h] [-v] [-d] [-i] [-l] [-D KEY=VALUE ...] [-p KEY] [-t TEMPLATE]\n" - " [-o OUTPUT] [SOURCE ...]\n"); + "[-h] [-v] [-d] [-i] [-l [-e SOURCE]] [-D KEY=VALUE ...] [-p KEY]\n" + " [-t TEMPLATE] [-o OUTPUT] [SOURCE ...]\n"); } @@ -160,6 +161,7 @@ main(int argc, char **argv) bool debug = false; bool input_stdin = false; bool listing = false; + char *listing_entry = NULL; char *template = NULL; char *output = NULL; char *print = NULL; @@ -167,6 +169,7 @@ main(int argc, char **argv) char **pieces = NULL; bc_slist_t *sources = NULL; + bc_trie_t *listing_entry_source = NULL; bc_trie_t *config = bc_trie_new(free); bc_trie_insert(config, "BLOGC_VERSION", bc_strdup(PACKAGE_VERSION)); @@ -189,6 +192,12 @@ main(int argc, char **argv) case 'l': listing = true; break; + case 'e': + if (argv[i][2] != '\0') + listing_entry = bc_strdup(argv[i] + 2); + else if (i + 1 < argc) + listing_entry = bc_strdup(argv[++i]); + break; case 't': if (argv[i][2] != '\0') template = bc_strdup(argv[i] + 2); @@ -296,6 +305,15 @@ main(int argc, char **argv) goto cleanup2; } + if (listing && listing_entry != NULL) { + listing_entry_source = blogc_source_parse_from_file(listing_entry, &err); + if (err != NULL) { + bc_error_print(err, "blogc"); + rv = 1; + goto cleanup2; + } + } + if (print != NULL) { const char *val = NULL; if (!listing && s != NULL) { @@ -332,7 +350,7 @@ main(int argc, char **argv) if (debug) blogc_debug_template(l); - char *out = blogc_render(l, s, config, listing); + char *out = blogc_render(l, s, listing_entry_source, config, listing); bool write_to_stdout = (output == NULL || (0 == strcmp(output, "-"))); @@ -366,6 +384,8 @@ cleanup: free(template); free(output); free(print); + free(listing_entry); + bc_trie_free(listing_entry_source); bc_slist_free_full(sources, free); return rv; } diff --git a/src/blogc/renderer.c b/src/blogc/renderer.c index 035f71b..87b3f5a 100644 --- a/src/blogc/renderer.c +++ b/src/blogc/renderer.c @@ -166,7 +166,7 @@ blogc_split_list_variable(const char *name, bc_trie_t *global, bc_trie_t *local) char* -blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *config, bool listing) +blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *listing_entry, bc_trie_t *config, bool listing) { if (tmpl == NULL) return NULL; @@ -221,6 +221,20 @@ blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *config, bool list current_source = sources; tmp_source = current_source != NULL ? current_source->data : NULL; } + if (0 == strcmp("listing_entry", node->data[0])) { + if (listing_entry == NULL || !listing) { + + // 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; + } + current_source = NULL; + tmp_source = listing_entry; + } else if ((0 == strcmp("listing", node->data[0])) || (0 == strcmp("listing_once", node->data[0]))) { if (!listing) { diff --git a/src/blogc/renderer.h b/src/blogc/renderer.h index 0b2b058..8f2516a 100644 --- a/src/blogc/renderer.h +++ b/src/blogc/renderer.h @@ -18,7 +18,7 @@ char* blogc_format_variable(const char *name, bc_trie_t *global, bc_trie_t *loca bc_slist_t *foreach_var); bc_slist_t* blogc_split_list_variable(const char *name, bc_trie_t *global, bc_trie_t *local); -char* blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *config, - bool listing); +char* blogc_render(bc_slist_t *tmpl, bc_slist_t *sources, bc_trie_t *listing_entr, + bc_trie_t *config, bool listing); #endif /* _RENDERER_H */ diff --git a/src/blogc/template-parser.c b/src/blogc/template-parser.c index a53f1aa..0b4eb55 100644 --- a/src/blogc/template-parser.c +++ b/src/blogc/template-parser.c @@ -379,11 +379,19 @@ 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_entry", src + start, 13))) + { + block_open = true; + end = current; + state = TEMPLATE_BLOCK_END_WHITESPACE_CLEANER; + break; + } } *err = bc_error_parser(BLOGC_ERROR_TEMPLATE_PARSER, src, src_len, current, - "Invalid block type. Allowed types are: 'entry', 'listing' " - "and 'listing_once'."); + "Invalid block type. Allowed types are: 'entry', 'listing', " + "'listing_once' and 'listing_entry'."); break; case TEMPLATE_BLOCK_IF_START: diff --git a/tests/blogc/check_blogc.sh.in b/tests/blogc/check_blogc.sh.in index 56d66e0..fcd7172 100755 --- a/tests/blogc/check_blogc.sh.in +++ b/tests/blogc/check_blogc.sh.in @@ -29,6 +29,13 @@ DATE: 2010-01-01 22:22:22 bar? EOF +cat > "${TEMP}/post3.txt" <<EOF +TITLE: baz +DATE: 2010-02-02 22:22:22 +------------------------- +bar? +EOF + cat > "${TEMP}/atom.tmpl" <<EOF <?xml version="1.0" encoding="utf-8"?> <feed xmlns="http://www.w3.org/2005/Atom"> @@ -163,7 +170,7 @@ cat > "${TEMP}/main.tmpl" <<EOF <title>{% block entry %}{{ TITLE }}{% endblock %}{% block listing_once %}{{ SITE_TITLE }}{% endblock %}</title> </head> <body> - <a href="{{ BASE_URL }}/"><div class="name">{{ SITE_TITLE }}</div></a> + <a href="{{ BASE_URL }}/"><div class="name">{{ SITE_TITLE }}</div></a>{% block listing_entry %}{{ CONTENT }}{% endblock %} {% block listing_once %} <section class="main"> <div class="container"> @@ -370,6 +377,94 @@ echo -e "${TEMP}/post1.txt" | ${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc \ diff -uN "${TEMP}/output8.html" "${TEMP}/expected-output2.html" +cat > "${TEMP}/expected-output3.html" <<EOF +<!DOCTYPE html> +<html lang="en"> + <head> + <title>Chunda's website</title> + </head> + <body> + <a href="/"><div class="name">Chunda's website</div></a><p>bar?</p> + + + <section class="main"> + <div class="container"> + <div class="content"> + <div class="page-heading">Blog</div> + <ul> + + + <li class="post-item"> + <div class="meta">Jan 01, 2010, 11:11 AM GMT</div> + <a href="/post/post1/"><div>foo</div></a> + </li> + + <li class="post-item"> + <div class="meta">Jan 01, 2010, 10:22 PM GMT</div> + <a href="/post/post2/"><div>bar</div></a> + </li> + + + </ul> + </div> + </div> + </section> + + + </body> +</html> +EOF + +${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc \ + -D BASE_DOMAIN=http://bola.com/ \ + -D BASE_URL= \ + -D SITE_TITLE="Chunda's website" \ + -D DATE_FORMAT="%b %d, %Y, %I:%M %p GMT" \ + -e "${TEMP}/post3.txt" \ + -t "${TEMP}/main.tmpl" \ + -o "${TEMP}/output9.html" \ + -l \ + "${TEMP}/post1.txt" "${TEMP}/post2.txt" + +diff -uN "${TEMP}/output9.html" "${TEMP}/expected-output3.html" + +echo -e "${TEMP}/post1.txt\n${TEMP}/post2.txt" | ${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc \ + -D BASE_DOMAIN=http://bola.com/ \ + -D BASE_URL= \ + -D SITE_TITLE="Chunda's website" \ + -D DATE_FORMAT="%b %d, %Y, %I:%M %p GMT" \ + -e "${TEMP}/post3.txt" \ + -t "${TEMP}/main.tmpl" \ + -o "${TEMP}/output10.html" \ + -l \ + -i + +diff -uN "${TEMP}/output10.html" "${TEMP}/expected-output3.html" + +${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc \ + -D BASE_DOMAIN=http://bola.com/ \ + -D BASE_URL= \ + -D SITE_TITLE="Chunda's website" \ + -D DATE_FORMAT="%b %d, %Y, %I:%M %p GMT" \ + -e "${TEMP}/post3.txt" \ + -t "${TEMP}/main.tmpl" \ + -l \ + "${TEMP}/post1.txt" "${TEMP}/post2.txt" > "${TEMP}/output11.html" + +diff -uN "${TEMP}/output11.html" "${TEMP}/expected-output3.html" + +echo -e "${TEMP}/post1.txt\n${TEMP}/post2.txt" | ${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc \ + -D BASE_DOMAIN=http://bola.com/ \ + -D BASE_URL= \ + -D SITE_TITLE="Chunda's website" \ + -D DATE_FORMAT="%b %d, %Y, %I:%M %p GMT" \ + -e "${TEMP}/post3.txt" \ + -t "${TEMP}/main.tmpl" \ + -l \ + -i > "${TEMP}/output12.html" + +diff -uN "${TEMP}/output12.html" "${TEMP}/expected-output3.html" + echo "{% block listig %}foo{% endblock %}\n" > "${TEMP}/error.tmpl" ${TESTS_ENVIRONMENT} @abs_top_builddir@/blogc \ diff --git a/tests/blogc/check_renderer.c b/tests/blogc/check_renderer.c index 1e2d1e5..479c239 100644 --- a/tests/blogc/check_renderer.c +++ b/tests/blogc/check_renderer.c @@ -82,7 +82,7 @@ test_render_entry(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "foo\n" "\n" @@ -129,7 +129,7 @@ test_render_listing(void **state) assert_null(err); bc_slist_t *s = create_sources(3); assert_non_null(s); - char *out = blogc_render(l, s, NULL, true); + char *out = blogc_render(l, s, NULL, NULL, true); assert_string_equal(out, "foo\n" "fuuu\n" @@ -157,6 +157,114 @@ test_render_listing(void **state) static void +test_render_listing_entry(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_entry %}asd{% endblock %}\n" + "{% block listing %}\n" + "{% ifdef DATE_FORMATTED %}{{ DATE_FORMATTED }}{% endif %}\n" + "bola: {% ifdef BOLA %}{{ BOLA }}{% endif %}\n" + "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" + "{% foreach TAGS_ASD %}yay{% endforeach %}\n" + "{% endblock %}\n"; + bc_error_t *err = NULL; + bc_slist_t *l = blogc_template_parse(str, strlen(str), &err); + assert_non_null(l); + assert_null(err); + bc_slist_t *s = create_sources(3); + assert_non_null(s); + char *out = blogc_render(l, s, NULL, NULL, true); + assert_string_equal(out, + "foo\n" + "fuuu\n" + "\n" + "\n" + "\n" + "03:04\n" + "bola: asd\n" + "lol foo haha lol bar haha lol baz haha \n" + "\n" + "\n" + "2014-02-03 04:05:06\n" + "bola: asd2\n" + "\n" + "\n" + "\n" + "2013-01-02 03:04:05\n" + "bola: asd3\n" + "\n" + "\n" + "\n"); + blogc_template_free_ast(l); + bc_slist_free_full(s, (bc_free_func_t) bc_trie_free); + free(out); +} + + +static void +test_render_listing_entry2(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_entry %}{{ FUUUUU }}{% endblock %}\n" + "{% block listing_entry %}{{ BAAAAA }}{% endblock %}\n" + "{% block listing %}\n" + "{% ifdef DATE_FORMATTED %}{{ DATE_FORMATTED }}{% endif %}\n" + "bola: {% ifdef BOLA %}{{ BOLA }}{% endif %}\n" + "{% foreach TAGS %}lol {{ FOREACH_ITEM }} haha {% endforeach %}\n" + "{% foreach TAGS_ASD %}yay{% endforeach %}\n" + "{% endblock %}\n"; + bc_error_t *err = NULL; + bc_slist_t *l = blogc_template_parse(str, strlen(str), &err); + assert_non_null(l); + assert_null(err); + bc_slist_t *s = create_sources(3); + assert_non_null(s); + bc_trie_t *entry = bc_trie_new(free); + bc_trie_insert(entry, "FUUUUU", bc_strdup("XD")); + bc_trie_insert(entry, "BAAAAA", bc_strdup(":p")); + char *out = blogc_render(l, s, entry, NULL, true); + bc_trie_free(entry); + assert_string_equal(out, + "foo\n" + "fuuu\n" + "\n" + "XD\n" + ":p\n" + "\n" + "03:04\n" + "bola: asd\n" + "lol foo haha lol bar haha lol baz haha \n" + "\n" + "\n" + "2014-02-03 04:05:06\n" + "bola: asd2\n" + "\n" + "\n" + "\n" + "2013-01-02 03:04:05\n" + "bola: asd3\n" + "\n" + "\n" + "\n"); + blogc_template_free_ast(l); + bc_slist_free_full(s, (bc_free_func_t) bc_trie_free); + free(out); +} + + +static void test_render_listing_empty(void **state) { const char *str = @@ -175,7 +283,7 @@ test_render_listing_empty(void **state) bc_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); + char *out = blogc_render(l, NULL, NULL, NULL, true); assert_string_equal(out, "foo\n" "fuuu\n" @@ -204,7 +312,7 @@ test_render_ifdef(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "\n" @@ -233,7 +341,7 @@ test_render_ifdef2(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "guda\n" @@ -264,7 +372,7 @@ test_render_ifdef3(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "guda\n" @@ -299,7 +407,7 @@ test_render_ifdef4(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "guda\n" @@ -335,7 +443,7 @@ test_render_ifdef5(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "guda\n" @@ -369,7 +477,7 @@ test_render_ifdef6(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "lol\n" @@ -402,7 +510,7 @@ test_render_ifdef7(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "guda\n" @@ -438,7 +546,7 @@ test_render_ifndef(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "chunda\n" @@ -474,7 +582,7 @@ test_render_if_eq(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "gudabola\n" @@ -511,7 +619,7 @@ test_render_if_neq(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "gudabola\n" @@ -548,7 +656,7 @@ test_render_if_lt(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "gudabola\n" @@ -585,7 +693,7 @@ test_render_if_gt(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "gudabola\n" @@ -624,7 +732,7 @@ test_render_if_lt_eq(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "gudabola\n" @@ -665,7 +773,7 @@ test_render_if_gt_eq(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "gudabola\n" @@ -697,7 +805,7 @@ test_render_foreach(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" " foo bar baz \n" @@ -722,7 +830,7 @@ test_render_foreach_if(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" " bar \n" @@ -748,7 +856,7 @@ test_render_foreach_if_else(void **state) assert_null(err); bc_slist_t *s = create_sources(1); assert_non_null(s); - char *out = blogc_render(l, s, NULL, false); + char *out = blogc_render(l, s, NULL, NULL, false); assert_string_equal(out, "\n" "foo yay baz \n" @@ -762,7 +870,7 @@ test_render_foreach_if_else(void **state) static void test_render_null(void **state) { - assert_null(blogc_render(NULL, NULL, NULL, false)); + assert_null(blogc_render(NULL, NULL, NULL, NULL, false)); } @@ -781,7 +889,7 @@ test_render_outside_block(void **state) assert_non_null(s); bc_trie_t *c = bc_trie_new(free); bc_trie_insert(c, "GUDA", bc_strdup("asd")); - char *out = blogc_render(l, s, c, false); + char *out = blogc_render(l, s, NULL, c, false); assert_string_equal(out, "bola\n" "\n" @@ -815,7 +923,7 @@ test_render_prefer_local_variable(void **state) bc_trie_t *c = bc_trie_new(free); bc_trie_insert(c, "GUDA", bc_strdup("hehe")); bc_trie_insert(c, "LOL", bc_strdup("hmm")); - char *out = blogc_render(l, s, c, false); + char *out = blogc_render(l, s, NULL, c, false); assert_string_equal(out, "\n" "hmm\n" @@ -849,7 +957,7 @@ test_render_respect_variable_scope(void **state) bc_slist_t *s = create_sources(1); assert_non_null(s); bc_trie_t *c = bc_trie_new(free); - char *out = blogc_render(l, s, c, false); + char *out = blogc_render(l, s, NULL, c, false); assert_string_equal(out, "\n" "\n" @@ -882,7 +990,7 @@ test_render_ifcount_bug(void **state) s = bc_slist_append(s, bc_trie_new(free)); bc_trie_insert(s->data, "TITLE", bc_strdup("bola")); bc_trie_t *c = bc_trie_new(free); - char *out = blogc_render(l, s, c, false); + char *out = blogc_render(l, s, NULL, c, false); assert_string_equal(out, "\n" "<h3>bola</h3>\n" @@ -1117,6 +1225,8 @@ main(void) const UnitTest tests[] = { unit_test(test_render_entry), unit_test(test_render_listing), + unit_test(test_render_listing_entry), + unit_test(test_render_listing_entry2), unit_test(test_render_listing_empty), unit_test(test_render_ifdef), unit_test(test_render_ifdef2), diff --git a/tests/blogc/check_template_parser.c b/tests/blogc/check_template_parser.c index 0121f73..15ef7c4 100644 --- a/tests/blogc/check_template_parser.c +++ b/tests/blogc/check_template_parser.c @@ -58,7 +58,8 @@ test_template_parse(void **state) "{% block listing %}{{ BOLA }}{% endblock %}\n" "{% block listing_once %}asd{% endblock %}\n" "{%- foreach BOLA %}hahaha{% endforeach %}\n" - "{% if BOLA == \"1\\\"0\" %}aee{% else %}fffuuuuuuu{% endif %}"; + "{% if BOLA == \"1\\\"0\" %}aee{% else %}fffuuuuuuu{% endif %}\n" + "{% block listing_entry %}lol{% endblock %}"; bc_error_t *err = NULL; bc_slist_t *ast = blogc_template_parse(a, strlen(a), &err); assert_null(err); @@ -120,7 +121,12 @@ test_template_parse(void **state) "fffuuuuuuu", BLOGC_TEMPLATE_NODE_CONTENT); blogc_assert_template_node(tmp->next->next->next->next->next->next->next->next, NULL, BLOGC_TEMPLATE_NODE_ENDIF); - assert_null(tmp->next->next->next->next->next->next->next->next->next); + tmp = tmp->next->next->next->next->next->next->next->next->next; + blogc_assert_template_node(tmp, "\n", BLOGC_TEMPLATE_NODE_CONTENT); + blogc_assert_template_node(tmp->next, "listing_entry", BLOGC_TEMPLATE_NODE_BLOCK); + blogc_assert_template_node(tmp->next->next, "lol", BLOGC_TEMPLATE_NODE_CONTENT); + blogc_assert_template_node(tmp->next->next->next, NULL, BLOGC_TEMPLATE_NODE_ENDBLOCK); + assert_null(tmp->next->next->next->next); blogc_template_free_ast(ast); } @@ -835,7 +841,8 @@ test_template_parse_invalid_block_type(void **state) assert_null(ast); assert_int_equal(err->type, BLOGC_ERROR_TEMPLATE_PARSER); assert_string_equal(err->msg, - "Invalid block type. Allowed types are: 'entry', 'listing' and 'listing_once'.\n" + "Invalid block type. Allowed types are: 'entry', 'listing', 'listing_once' " + "and 'listing_entry'.\n" "Error occurred near line 1, position 16: {% block chunda %}"); bc_error_free(err); } |