From 871ee4db27295b212bfdbc03550ed81f1f2e8b12 Mon Sep 17 00:00:00 2001 From: Pixel Date: Fri, 25 Nov 2011 08:01:18 -0800 Subject: Adding a small documentation. --- src/SimpleMustache.cc | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'src/SimpleMustache.cc') 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[] = +"

{{header}}

\n" +"{{#bug}}\n" +"{{/bug}}\n" +"\n" +"{{#items}}\n" +" {{#first}}\n" +"
  • {{name}}
  • \n" +" {{/first}}\n" +" {{#link}}\n" +"
  • {{name}}
  • \n" +" {{/link}}\n" +"{{/items}}\n" +"\n" +"{{#empty}}\n" +"

    The list is empty.

    \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 b(new HPrinter); + tpl.render(b, &ctx); + + + +will output: + +

    Colors

    +
  • red
  • +
  • green
  • +
  • blue
  • + +(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; -- cgit v1.2.3