diff --git a/src/render_context.hpp b/src/render_context.hpp index d0f2456..d522012 100644 --- a/src/render_context.hpp +++ b/src/render_context.hpp @@ -20,6 +20,7 @@ namespace mstch { private: render_context& context; }; + render_context( const mstch::object& object, const std::map& partials); diff --git a/src/state/in_section.cpp b/src/state/in_section.cpp index 23ec6c4..b3eb77e 100644 --- a/src/state/in_section.cpp +++ b/src/state/in_section.cpp @@ -18,8 +18,7 @@ std::string state::in_section::render(render_context& ctx, const token& token) { std::string out; if (!boost::apply_visitor(visitor::is_node_empty(), section_node)) out = boost::apply_visitor( - visitor::render_section(ctx, section), - section_node); + visitor::render_section(ctx, section), section_node); ctx.set_state(); return out; } else { diff --git a/src/state/outside_section.cpp b/src/state/outside_section.cpp index 7d51084..ef78353 100644 --- a/src/state/outside_section.cpp +++ b/src/state/outside_section.cpp @@ -5,6 +5,7 @@ #include "render_context.hpp" using namespace mstch; +using flag = visitor::render_node::flag; std::string state::outside_section::render( render_context& ctx, const token& token) @@ -17,13 +18,10 @@ std::string state::outside_section::render( ctx.set_state(token.content()); break; case token::type::variable: - case token::type::unescaped_variable: { - std::set flags{}; - if (token.token_type() == token::type::variable) - flags.insert(visitor::render_node::flag::escape_html); - return boost::apply_visitor( - visitor::render_node(flags), ctx.get_node(token.content())); - } + case token::type::unescaped_variable: + return boost::apply_visitor(visitor::render_node((token.token_type() == + token::type::variable)?flag::escape_html:flag::none), + ctx.get_node(token.content())); case token::type::comment: break; case token::type::text: return token.content(); diff --git a/src/template_type.cpp b/src/template_type.cpp index 9de0f3c..802fbba 100644 --- a/src/template_type.cpp +++ b/src/template_type.cpp @@ -33,14 +33,12 @@ void template_type::tokenize(const std::string& t) { else pstate = parse_state::start; } else if(pstate == parse_state::in_del) { - if (*it == '{') { + if (*it == '{') pstate = parse_state::in_esccontent; - } else if (*it == delim_end[0]) { + else if (*it == delim_end[0] && (del_pos = 1)) pstate = parse_state::in_del_end; - del_pos = 1; - } else { + else pstate = parse_state::in_content; - } } else if(pstate == parse_state::in_esccontent && *it == '}') { pstate = parse_state::in_content; } else if(pstate == parse_state::in_content && *it == delim_end[0]) { diff --git a/src/visitor/render_node.cpp b/src/visitor/render_node.cpp index 4a0797c..dae74f6 100644 --- a/src/visitor/render_node.cpp +++ b/src/visitor/render_node.cpp @@ -3,7 +3,7 @@ using namespace mstch; -visitor::render_node::render_node(std::set flags): flags(flags) { +visitor::render_node::render_node(flag p_flag): m_flag(p_flag) { } std::string visitor::render_node::operator()(const boost::blank& blank) const { @@ -19,7 +19,7 @@ std::string visitor::render_node::operator()(const bool& b) const { } std::string visitor::render_node::operator()(const std::string& str) const { - return (flags.find(flag::escape_html) != flags.end())?html_escape(str):str; + return (m_flag == flag::escape_html)?html_escape(str):str; } std::string visitor::render_node::operator()(const array& arr) const { diff --git a/src/visitor/render_node.hpp b/src/visitor/render_node.hpp index 47d7b0f..892b319 100644 --- a/src/visitor/render_node.hpp +++ b/src/visitor/render_node.hpp @@ -10,8 +10,8 @@ namespace mstch { namespace visitor { class render_node: public boost::static_visitor { public: - enum class flag { escape_html }; - render_node(std::set flags = {}); + enum class flag { none, escape_html }; + render_node(flag p_flag = flag::none); std::string operator()(const boost::blank& blank) const; std::string operator()(const int& i) const; std::string operator()(const bool& b) const; @@ -21,7 +21,7 @@ namespace mstch { std::string operator()(const string_lambda& lambda) const; std::string operator()(const renderer_lambda& lambda) const; private: - std::set flags; + flag m_flag; }; } } diff --git a/src/visitor/render_section.cpp b/src/visitor/render_section.cpp index 13cd3a1..b6ef551 100644 --- a/src/visitor/render_section.cpp +++ b/src/visitor/render_section.cpp @@ -3,8 +3,8 @@ using namespace mstch; visitor::render_section::render_section( - render_context& ctx, const template_type& section,std::set flags): - ctx(ctx), section(section), flags(flags) + render_context& ctx, const template_type& section, flag p_flag): + ctx(ctx), section(section), m_flag(p_flag) { } @@ -32,12 +32,12 @@ std::string visitor::render_section::operator()(const object& obj) const { std::string visitor::render_section::operator()(const array& a) const { std::string out; - if(flags.find(flag::keep_array) != flags.end()) + if(m_flag == flag::keep_array) out += render_context::push(ctx, {{".", a}}).render(section); else for (auto& item: a) out += boost::apply_visitor( - render_section(ctx, section, {flag::keep_array}), item); + render_section(ctx, section, flag::keep_array), item); return out; } diff --git a/src/visitor/render_section.hpp b/src/visitor/render_section.hpp index 8064c6e..7656552 100644 --- a/src/visitor/render_section.hpp +++ b/src/visitor/render_section.hpp @@ -11,11 +11,11 @@ namespace mstch { namespace visitor { class render_section: public boost::static_visitor { public: - enum class flag { keep_array }; + enum class flag { none, keep_array }; render_section( render_context& ctx, const template_type& section, - std::set flags = {}); + flag p_flag = flag::none); std::string operator()(const boost::blank& blank) const; std::string operator()(const int& i) const; std::string operator()(const bool& b) const; @@ -27,7 +27,7 @@ namespace mstch { private: render_context& ctx; const template_type& section; - std::set flags; + flag m_flag; }; } }