Skip to content
This repository was archived by the owner on Oct 9, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/plustache/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
10 changes: 10 additions & 0 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
14 changes: 13 additions & 1 deletion src/template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <string>
#include <boost/regex.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/algorithm/string/predicate.hpp>

#include <plustache/plustache_types.hpp>
#include <plustache/context.hpp>
Expand Down Expand Up @@ -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(""); }
}
Expand Down Expand Up @@ -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("");
Expand Down