1
0
Fork 0
mirror of https://github.com/KingDuckZ/kamokan.git synced 2025-07-02 14:04:16 +00:00

Return pasties into a proper html page.

I don't think html escaping is needed, since pasties
go through the colorizer first.

I don't really like the workaround to not call on_send() when
I don't want the html output, it's a bit omg what's going on
there... I'll have to rewrite that bit.
This commit is contained in:
King_DuckZ 2017-04-25 22:56:19 +01:00
parent 54e737c171
commit 06920f8d84
6 changed files with 55 additions and 20 deletions

View file

@ -97,6 +97,10 @@ namespace tawashi {
}
return retval;
}
std::string disable_mstch_escaping (const std::string& parStr) {
return parStr;
};
} //unnamed namespace
Response::Response (Types parRespType, std::string&& parValue, std::string&& parPageBaseName, const Kakoune::SafePtr<SettingsBag>& parSettings, bool parWantRedis) :
@ -106,12 +110,15 @@ namespace tawashi {
m_website_root(make_root_path(*parSettings)),
m_page_basename(std::move(parPageBaseName)),
m_resp_type(parRespType),
m_header_sent(false)
m_header_sent(false),
m_call_derived_on_send(true)
{
if (parWantRedis) {
m_redis = std::make_unique<redis::IncRedis>(make_incredis(*parSettings));
m_redis->connect();
}
mstch::config::escape = &disable_mstch_escaping;
}
Response::~Response() noexcept = default;
@ -155,8 +162,13 @@ namespace tawashi {
}
std::ostringstream stream_out;
if (ContentType == m_resp_type)
this->on_send(stream_out);
if (ContentType == m_resp_type) {
if (m_call_derived_on_send)
this->on_send(stream_out);
else
Response::on_send(stream_out);
}
std::cout << mstch::render(
stream_out.str(),
mustache_context,
@ -204,4 +216,8 @@ namespace tawashi {
assert(m_settings);
return *m_settings;
}
void Response::call_on_send (bool parCall) {
m_call_derived_on_send = parCall;
}
} //namespace tawashi