diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 02:57:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 02:57:58 +0000 |
commit | be1c7e50e1e8809ea56f2c9d472eccd8ffd73a97 (patch) | |
tree | 9754ff1ca740f6346cf8483ec915d4054bc5da2d /web/server/h2o/libh2o/misc/picotemplate/README.mkdn | |
parent | Initial commit. (diff) | |
download | netdata-be1c7e50e1e8809ea56f2c9d472eccd8ffd73a97.tar.xz netdata-be1c7e50e1e8809ea56f2c9d472eccd8ffd73a97.zip |
Adding upstream version 1.44.3.upstream/1.44.3upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'web/server/h2o/libh2o/misc/picotemplate/README.mkdn')
-rw-r--r-- | web/server/h2o/libh2o/misc/picotemplate/README.mkdn | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/web/server/h2o/libh2o/misc/picotemplate/README.mkdn b/web/server/h2o/libh2o/misc/picotemplate/README.mkdn new file mode 100644 index 00000000..266f4bfa --- /dev/null +++ b/web/server/h2o/libh2o/misc/picotemplate/README.mkdn @@ -0,0 +1,42 @@ +PICOTEMPLATE - a tiny template engine for embedded HTML +======================================================= + +Picotemplate is a tiny template engine (preprocessor) designed to embed HTML (or other types of document) within the source code of any programming language. + +There are often cases where you would like to generate HTML within a program. In such cases, the easiest way would be to use a DSL (domain-specific language) to embed the HTML in the source code and preprocess it. Picotemplate is a preprocesser designed for such an use-case. + +As of now, Perl, C++, JavaScript, and JSX are the supported languages. + +THE LOGIC +--------- + +* lines starting with "?" are considered as embedded document +* <?= ?> within embedded document are considered as expressions (that return strings) +* the output is accumulated to variable named "_" (or $output in case of perl) +* filenames starting with an underscore (_) will be preprocessed, and the name of the output file will be the same omitting the leading underscore (e.g. _foo.cc will be preproccessed and converted to foo.cc) + +EXAMPLE +------- + +The following code (in _foo.cc) will be preprocessed and converted to a function (in foo.cc) that returns an function building an HTML snippet. + +``` +std::string unordered_list(const std::vector<std::string>& strs) +{ + std::string _; // output is accumulated to _ +?<ul> + for (std::vector<std::string>::const_iterator i = strs.begin(); + i != strs.end(); + ++i) { +?<li><?= escapeHTML(*i) ?></li> + } +?</ul> + return _; +} +``` + +To preprocess a source file, simply run the command with the name of the source file to preprocess. The following exmaple preprocesses _foo.cc_ (template files should start with an underscore) and produces _foo.cc_. + +``` +$ picotemplate.pl _foo.cc +``` |