4 #include <boost/variant/static_visitor.hpp>
6 #include "render_context.hpp"
7 #include "mstch/mstch.hpp"
12 class render_node: public boost::static_visitor<std::string> {
14 enum class flag { none, escape_html };
15 render_node(render_context& ctx, flag p_flag = flag::none):
16 m_ctx(ctx), m_flag(p_flag)
21 std::string operator()(const T&) const {
25 std::string operator()(const int& value) const {
26 return std::to_string(value);
29 std::string operator()(const double& value) const {
35 std::string operator()(const bool& value) const {
36 return value ? "true" : "false";
39 std::string operator()(const lambda& value) const {
40 template_type interpreted{value([this](const mstch::node& n) {
41 return visit(render_node(m_ctx), n);
43 auto rendered = render_context::push(m_ctx).render(interpreted);
44 return (m_flag == flag::escape_html) ? html_escape(rendered) : rendered;
47 std::string operator()(const std::string& value) const {
48 return (m_flag == flag::escape_html) ? html_escape(value) : value;
52 render_context& m_ctx;