bugfix in section render when context is array

This commit is contained in:
Daniel Sipka 2015-04-11 13:05:23 +02:00
parent 99677a30c4
commit 4c43b33291
3 changed files with 10 additions and 8 deletions

View file

@ -3,13 +3,14 @@
#include "state/outside_section.h"
#include <regex>
#include <visitor/to_json.h>
using namespace mstch;
const mstch::node render_context::null_node;
render_context::render_context(
const mstch::object &object,
const mstch::object& object,
const std::map<std::string,std::string>& partials):
partials(partials),
objects{object},
@ -28,10 +29,10 @@ render_context::render_context(
}
const mstch::node& render_context::find_node(
const std::string &token,
const std::deque<object> &current_objects)
const std::string& token,
const std::deque<object>& current_objects)
{
if(token != "." && token.find('.') != std::string::npos) {
if (token != "." && token.find('.') != std::string::npos) {
return find_node(
token.substr(token.rfind('.') + 1),
{boost::get<object>(find_node(
@ -53,7 +54,7 @@ std::string render_context::render(const std::string& t) {
std::ostringstream output;
auto re = std::regex("\\{{2}[^\\}]*\\}{2}|\\{{3}[^\\}]*\\}{3}");
std::sregex_token_iterator it(t.begin(), t.end(), re, {-1, 0});
for(; it != std::sregex_token_iterator(); ++it)
for (; it != std::sregex_token_iterator(); ++it)
output << state->render(*this, token(it->str()));
return output.str();
}

View file

@ -32,7 +32,8 @@ std::string visitor::render_section::operator()(const std::string& str) const {
std::string visitor::render_section::operator()(const array& arr) const {
std::ostringstream out;
for (auto& item: arr)
out << boost::apply_visitor(*this, item);
out << render_context(mstch::object{{".", item}}, context)
.render(section);
return out.str();
}

View file

@ -21,7 +21,7 @@ MSTCH_TEST("Empty string", mstchtest::empty_string)
MSTCH_TEST("Empty template", mstchtest::empty_template)
MSTCH_TEST("Error not found", mstchtest::error_not_found)
MSTCH_TEST("Falsy", mstchtest::falsy)
//MSTCH_TEST("Falsy array", mstchtest::falsy_array)
MSTCH_TEST("Falsy array", mstchtest::falsy_array)
MSTCH_TEST("Grandparent context", mstchtest::grandparent_context)
MSTCH_TEST("Implicit iterator", mstchtest::implicit_iterator)
MSTCH_TEST("Included tag", mstchtest::included_tag)
@ -32,7 +32,7 @@ MSTCH_TEST("Nested dot", mstchtest::nested_dot)
MSTCH_TEST("Nested iterating", mstchtest::nested_iterating)
MSTCH_TEST("Nesting", mstchtest::nesting)
MSTCH_TEST("Nesting same name", mstchtest::nesting_same_name)
//MSTCH_TEST("Null lookup array", mstchtest::null_lookup_array)
MSTCH_TEST("Null lookup array", mstchtest::null_lookup_array)
MSTCH_TEST("Null lookup object", mstchtest::null_lookup_object)
MSTCH_TEST("Null view", mstchtest::null_view)
MSTCH_TEST("Recursion with same names", mstchtest::recursion_with_same_names)