summaryrefslogtreecommitdiffstats
path: root/web/server/h2o/libh2o/misc/picotemplate/README.mkdn
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--web/server/h2o/libh2o/misc/picotemplate/README.mkdn42
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
+```