summaryrefslogtreecommitdiff
path: root/src/SimpleMustache.cc
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2011-11-25 08:01:18 -0800
committerPixel <pixel@nobis-crew.org>2011-11-25 08:01:18 -0800
commit871ee4db27295b212bfdbc03550ed81f1f2e8b12 (patch)
tree43773dcd1254610d6c39034edb6184f84e96d38e /src/SimpleMustache.cc
parent5ed7471257348063b156ef1f0c0a5f2898112636 (diff)
Adding a small documentation.
Diffstat (limited to 'src/SimpleMustache.cc')
-rw-r--r--src/SimpleMustache.cc55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/SimpleMustache.cc b/src/SimpleMustache.cc
index f14d460..c7cbee4 100644
--- a/src/SimpleMustache.cc
+++ b/src/SimpleMustache.cc
@@ -2,6 +2,61 @@
#include "BStream.h"
#include "BRegex.h"
+/* Example of use
+
+
+ SimpleMustache tpl;
+ const char tplStr[] =
+"<h1>{{header}}</h1>\n"
+"{{#bug}}\n"
+"{{/bug}}\n"
+"\n"
+"{{#items}}\n"
+" {{#first}}\n"
+" <li><strong>{{name}}</strong></li>\n"
+" {{/first}}\n"
+" {{#link}}\n"
+" <li><a href=\"{{url}}\">{{name}}</a></li>\n"
+" {{/link}}\n"
+"{{/items}}\n"
+"\n"
+"{{#empty}}\n"
+" <p>The list is empty.</p>\n"
+"{{/empty}}\n";
+ tpl.setTemplate(tplStr, sizeof(tplStr) - 1);
+ SimpleMustache::Context ctx;
+ ctx["header"] = "Colors";
+ ctx["items"][0]["name"] = "red";
+ ctx["items"][-1]["first"] = true;
+ ctx["items"][-1]["url"] = "#Red";
+ ctx["items"][0]["name"] = "green";
+ ctx["items"][-1]["link"] = true;
+ ctx["items"][-1]["url"] = "#Green";
+ ctx["items"][0]["name"] = "blue";
+ ctx["items"][-1]["link"] = true;
+ ctx["items"][-1]["url"] = "#Blue";
+ ctx["empty"] = false;
+
+ IO<HPrinter> b(new HPrinter);
+ tpl.render(b, &ctx);
+
+
+
+will output:
+
+<h1>Colors</h1>
+ <li><strong>red</strong></li>
+ <li><a href="#Green">green</a></li>
+ <li><a href="#Blue">blue</a></li>
+
+(and a few extra blank lines)
+
+indexes for contextes are counting from 1
+index 0 of a context == new slot
+index -x of a context == slot number size - x
+
+*/
+
Balau::SimpleMustache::Context & Balau::SimpleMustache::Context::Proxy::operator[](const char * str) {
Assert(m_parent->m_type == CONTEXTLIST);
String key = str;