diff --git a/include/plustache/context.hpp b/include/plustache/context.hpp index 183c700..7ea18f9 100644 --- a/include/plustache/context.hpp +++ b/include/plustache/context.hpp @@ -19,6 +19,7 @@ namespace Plustache { int add(const std::string& key, const PlustacheTypes::ObjectType& o); int add(const PlustacheTypes::ObjectType& o); PlustacheTypes::CollectionType get(const std::string& key) const; + int count(const std::string &key) const; private: /* data */ diff --git a/src/context.cpp b/src/context.cpp index fac54ef..285e30d 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -131,3 +131,13 @@ PlustacheTypes::CollectionType Context::get(const std::string& key) const } return ret; } + +/** + * + * @param key + * @return + */ +int Context::count(const std::string &key) const +{ + return ctx.count(key); +} diff --git a/src/template.cpp b/src/template.cpp index b740372..242c4ca 100644 --- a/src/template.cpp +++ b/src/template.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -124,7 +125,10 @@ std::string template_t::render_tags(const std::string& tmplate, { try { - repl.assign(template_t::html_escape(ctx.get(key)[0][key])); + if (!ctx.count("__not_to_escape")) + { repl.assign(template_t::html_escape(ctx.get(key)[0][key])); } + else + { repl.assign(ctx.get(key)[0][key]); } } catch(int i) { repl.assign(""); } } @@ -236,6 +240,14 @@ std::string template_t::render_sections(const std::string& tmplate, small_ctx.add(*it); repl += template_t::render_tags(matches[3], small_ctx); } + if (ctx.count("__remove_trailing_comma")) + { + boost::algorithm::trim(repl); + while (boost::algorithm::ends_with(repl, ",")) + { + repl.pop_back(); + } + } } } else repl.assign("");