aboutsummaryrefslogtreecommitdiff
path: root/lib/mstch/src/state/outside_section.cpp
blob: c9817b19fb6d30211c4b09b84b8906948006e245 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "outside_section.hpp"

#include "visitor/render_node.hpp"
#include "in_section.hpp"
#include "render_context.hpp"

using namespace mstch;

std::string outside_section::render(
    render_context& ctx, const token& token)
{
  using flag = render_node::flag;
  switch (token.token_type()) {
    case token::type::section_open:
      ctx.set_state<in_section>(in_section::type::normal, token);
      break;
    case token::type::inverted_section_open:
      ctx.set_state<in_section>(in_section::type::inverted, token);
      break;
    case token::type::variable:
      return visit(render_node(ctx, flag::escape_html), ctx.get_node(token.name()));
    case token::type::unescaped_variable:
      return visit(render_node(ctx, flag::none), ctx.get_node(token.name()));
    case token::type::text:
      return token.raw();
    case token::type::partial:
      return ctx.render_partial(token.name(), token.partial_prefix());
    default:
      break;
  }
  return "";
}