Archived
1
0
This repository has been archived on 2023-08-12. You can view files and clone it, but cannot push or open issues or pull requests.
nntpchan/contrib/backends/nntpchan-daemon/libmustache/render_context.hpp

48 lines
1.2 KiB
C++
Raw Normal View History

2017-10-11 18:48:27 +05:00
#pragma once
#include <deque>
#include <list>
#include <sstream>
#include <stack>
2017-10-17 19:29:56 +05:00
#include <string>
2017-10-11 18:48:27 +05:00
#include "state/render_state.hpp"
#include "template_type.hpp"
2017-10-17 19:29:56 +05:00
#include <mstch/mstch.hpp>
2017-10-11 18:48:27 +05:00
2017-10-17 19:29:56 +05:00
namespace mstch
{
2017-10-11 18:48:27 +05:00
2017-10-17 19:29:56 +05:00
class render_context
{
public:
class push
{
public:
push(render_context &context, const mstch::node &node = {});
2017-10-11 18:48:27 +05:00
~push();
2017-10-17 19:29:56 +05:00
std::string render(const template_type &templt);
private:
render_context &m_context;
2017-10-11 18:48:27 +05:00
};
2017-10-17 19:29:56 +05:00
render_context(const mstch::node &node, const std::map<std::string, template_type> &partials);
const mstch::node &get_node(const std::string &token);
std::string render(const template_type &templt, const std::string &prefix = "");
std::string render_partial(const std::string &partial_name, const std::string &prefix);
template <class T, class... Args> void set_state(Args &&... args)
{
m_state.top() = std::unique_ptr<render_state>(new T(std::forward<Args>(args)...));
2017-10-11 18:48:27 +05:00
}
2017-10-17 19:29:56 +05:00
private:
2017-10-11 18:48:27 +05:00
static const mstch::node null_node;
2017-10-17 19:29:56 +05:00
const mstch::node &find_node(const std::string &token, std::list<node const *> current_nodes);
2017-10-11 18:48:27 +05:00
std::map<std::string, template_type> m_partials;
std::deque<mstch::node> m_nodes;
2017-10-17 19:29:56 +05:00
std::list<const mstch::node *> m_node_ptrs;
2017-10-11 18:48:27 +05:00
std::stack<std::unique_ptr<render_state>> m_state;
};
}