From 8d96c02e5118cf7bd656fde9100570a67115d19a Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Tue, 29 Dec 2015 00:12:51 +0100 Subject: man: renderer: template-parser: added foreach iterator support --- man/blogc-template.7.ronn | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'man') diff --git a/man/blogc-template.7.ronn b/man/blogc-template.7.ronn index 77073af..46413c2 100644 --- a/man/blogc-template.7.ronn +++ b/man/blogc-template.7.ronn @@ -163,6 +163,44 @@ Or: Title is the default title {% endif %} +## TEMPLATE ITERATORS + +Template iterators are used to iterate over the value of a variable, that is handled +as a list. + +The available conditionals are: `foreach`. + +### foreach iterator + +The content of a `foreach` iterator is included in the output file when the target +variable is defined, and is repeated for each item in the list parsed from the variable +value. + +The variable value should be formatted as a comma-separated list of items. Quotes are +not supported, as this is intended to work with identifiers, like slugs, and not with +arbitrary strings. + +Spaces and tabs before and after list items are stripped for consistency. + +This is how a variable would be formatted: + + item1, item2, item3 + +For more info about how to define variables, see blogc(1) and blogc-source(7). + +This is how a `foreach` iterator is defined in a template: + + {% foreach TAGS %} + {{ FOREACH_ITEM }} + {% endforeach %} + +Where `TAGS` is the variable with comma-separated list of items, and `FOREACH_ITEM` +is the variable defined by blogc(1), that will store the item value for a given +iteration. + +If the value of the `TAGS` variable is "item1, item2, item3", this template would be +rendered as 3 times, one for each item value. + ## BUGS The template content is handled by handwritten parsers, that even being well -- cgit v1.2.3-18-g5258 From 3d24a8847e156804e19515ddeefd3912402515be Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Tue, 29 Dec 2015 01:46:50 +0100 Subject: renderer: foreach variables should be splitted in spaces rather than commas --- man/blogc-template.7.ronn | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'man') diff --git a/man/blogc-template.7.ronn b/man/blogc-template.7.ronn index 46413c2..2875e36 100644 --- a/man/blogc-template.7.ronn +++ b/man/blogc-template.7.ronn @@ -176,15 +176,13 @@ The content of a `foreach` iterator is included in the output file when the targ variable is defined, and is repeated for each item in the list parsed from the variable value. -The variable value should be formatted as a comma-separated list of items. Quotes are +The variable value should be formatted as a space-separated list of items. Quotes are not supported, as this is intended to work with identifiers, like slugs, and not with arbitrary strings. -Spaces and tabs before and after list items are stripped for consistency. +This is how a variable value would be formatted: -This is how a variable would be formatted: - - item1, item2, item3 + item1 item2 item3 For more info about how to define variables, see blogc(1) and blogc-source(7). @@ -194,12 +192,12 @@ This is how a `foreach` iterator is defined in a template: {{ FOREACH_ITEM }} {% endforeach %} -Where `TAGS` is the variable with comma-separated list of items, and `FOREACH_ITEM` +Where `TAGS` is the variable with space-separated list of items, and `FOREACH_ITEM` is the variable defined by blogc(1), that will store the item value for a given iteration. -If the value of the `TAGS` variable is "item1, item2, item3", this template would be -rendered as 3 times, one for each item value. +If the value of the `TAGS` variable is "item1 item2 item3", this template is +rendered 3 times, one for each item value. ## BUGS -- cgit v1.2.3-18-g5258 From be71d0c966e558555ccdc25539e7f9be2ca1693b Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 30 Dec 2015 01:53:31 +0100 Subject: man: fix blogc-template man page --- man/blogc-template.7.ronn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'man') diff --git a/man/blogc-template.7.ronn b/man/blogc-template.7.ronn index 2875e36..3a665ab 100644 --- a/man/blogc-template.7.ronn +++ b/man/blogc-template.7.ronn @@ -4,8 +4,8 @@ blogc-template(7) -- blogc's template format ## DESCRIPTION Template files are used as base to build output files by blogc(1). These files -can include variables, blocks and conditionals, that will directly affect the -output files. +can include variables, blocks, conditionals and iterators, that will directly +affect the output files. The syntax of the template files is defined to be simple, without affecting the content output. The syntax is somewhat inspired by Jinja2 syntax. -- cgit v1.2.3-18-g5258 From 542b1d30cca5d6c17b662438d594a91b864ccc56 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Thu, 14 Jan 2016 21:43:39 +0100 Subject: man: added documentation about whitespace control --- man/blogc-template.7.ronn | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'man') diff --git a/man/blogc-template.7.ronn b/man/blogc-template.7.ronn index 3a665ab..bd38618 100644 --- a/man/blogc-template.7.ronn +++ b/man/blogc-template.7.ronn @@ -199,6 +199,19 @@ iteration. If the value of the `TAGS` variable is "item1 item2 item3", this template is rendered 3 times, one for each item value. +## WHITESPACE CONTROL + +Users can control how whitespaces (space, form-feed (`\f`), newline (`\n`), +carriage return (`\r`), horizontal tab (`\t`), and vertical tab (`\v`)) are +handled before and after statements delimited with `{%` and `%}` sequences, +respectively. + +Adding a minus sign (`-`) after a `{%` sequence (`{%-`) will remove whitespaces +before the sequence and after the last non-whitespace character before the sequence. + +Adding a minus sign (`-`) before a `%}` sequence (`-%}`) will remove whitespaces +after the sequence and before the first non-whitespace character after the sequence. + ## BUGS The template content is handled by handwritten parsers, that even being well -- cgit v1.2.3-18-g5258