1
0
Fork 0
mirror of https://github.com/KingDuckZ/kamokan.git synced 2025-08-07 12:59:45 +00:00

Add default_pastie_lang() method and language_selected mustache.

This commit is contained in:
King_DuckZ 2017-06-18 15:08:44 +01:00
parent 00e27a774a
commit 9deaa8a0b8
6 changed files with 34 additions and 6 deletions

View file

@ -77,11 +77,15 @@ namespace kamokan {
return boost::make_optional(buffer.str());
}
mstch::array make_mstch_langmap (const SettingsBag& parSettings) {
mstch::array make_mstch_langmap (const SettingsBag& parSettings, const std::string& parSelected) {
mstch::array retval;
for (auto&& lang : list_highlight_langs(parSettings)) {
retval.push_back(mstch::map{{"language_name", std::move(lang)}});
const bool selected = (parSelected == lang);
retval.push_back(mstch::map{
{"language_name", std::move(lang)},
{"language_selected", selected}
});
}
return retval;
}
@ -173,13 +177,13 @@ namespace kamokan {
statuslog->info("Sending response");
SPDLOG_TRACE(statuslog, "Preparing mustache dictionary");
const bool is_submit_page = this->is_submit_page();
mstch::map mustache_context {
{"submit_page", this->is_submit_page()},
{"submit_page", is_submit_page},
{"version", boost::string_view{STRINGIZE(VERSION_MAJOR) "." STRINGIZE(VERSION_MINOR) "." STRINGIZE(VERSION_PATCH)}},
{"tawashi_version", tawashi::version()},
{"base_uri", base_uri()},
{"host_path", make_host_path(this->settings())},
{"languages", make_mstch_langmap(*m_settings)}
{"host_path", make_host_path(this->settings())}
};
m_storage.finalize_connection();
@ -188,6 +192,11 @@ namespace kamokan {
tawashi::HttpHeader http_header = this->on_process();
*m_stream_out << http_header;
if (is_submit_page) {
SPDLOG_TRACE(statuslog, "Adding language list to mustache context");
mustache_context["languages"] = make_mstch_langmap(*m_settings, this->default_pastie_lang());
}
if (http_header.body_required()) {
using std::chrono::steady_clock;
using std::chrono::milliseconds;
@ -275,4 +284,8 @@ namespace kamokan {
assert(parTime <= m_time0);
m_time0 = parTime;
}
std::string Response::default_pastie_lang() {
return std::string();
}
} //namespace kamokan