reformat
This commit is contained in:
parent
3b4580186c
commit
e31207b9cf
17 changed files with 160 additions and 93 deletions
|
@ -7,36 +7,43 @@
|
|||
|
||||
using namespace mstch;
|
||||
|
||||
state::in_inverted_section::in_inverted_section(const std::string& section_name):
|
||||
state::in_inverted_section::in_inverted_section(
|
||||
const std::string& section_name):
|
||||
section_name(section_name),
|
||||
skipped_openings(0)
|
||||
{
|
||||
}
|
||||
|
||||
std::string state::in_inverted_section::render(render_context& context, const token& token) {
|
||||
std::string state::in_inverted_section::render(
|
||||
render_context& ctx,
|
||||
const token& token)
|
||||
{
|
||||
switch(token.type()) {
|
||||
case token_type::section_close:
|
||||
if(token.content() == section_name && skipped_openings == 0) {
|
||||
std::ostringstream out;
|
||||
if(boost::apply_visitor(visitor::is_node_empty(), context.get_node(section_name)))
|
||||
out << render_context(mstch::object{}, context).render(section_text.str());
|
||||
context.set_state<outside_section>();
|
||||
return out.str();
|
||||
} else {
|
||||
skipped_openings--;
|
||||
section_text << token.raw();
|
||||
case token_type::section_close:
|
||||
if(token.content() == section_name && skipped_openings == 0) {
|
||||
std::ostringstream out;
|
||||
auto& section_node = ctx.get_node(section_name);
|
||||
if(boost::apply_visitor(visitor::is_node_empty(), section_node)) {
|
||||
auto empty = mstch::object{};
|
||||
out << render_context(empty, ctx).render(section_text.str());
|
||||
}
|
||||
break;
|
||||
case token_type::inverted_section_open:
|
||||
case token_type::section_open:
|
||||
skipped_openings++;
|
||||
case token_type::text:
|
||||
case token_type::variable:
|
||||
case token_type::unescaped_variable:
|
||||
case token_type::comment:
|
||||
case token_type::partial:
|
||||
ctx.set_state<outside_section>();
|
||||
return out.str();
|
||||
} else {
|
||||
skipped_openings--;
|
||||
section_text << token.raw();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case token_type::inverted_section_open:
|
||||
case token_type::section_open:
|
||||
skipped_openings++;
|
||||
case token_type::text:
|
||||
case token_type::variable:
|
||||
case token_type::unescaped_variable:
|
||||
case token_type::comment:
|
||||
case token_type::partial:
|
||||
section_text << token.raw();
|
||||
break;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue