1
0
Fork 0
mirror of https://github.com/KingDuckZ/kamokan.git synced 2024-11-23 00:33:44 +00:00

Add a host_path token to mustache.

It expands to the host_path setting in the ini file, with
the last slash removed if present. Use it to make absolute
links like {{host_path}}/tawashi.css.
This commit is contained in:
King_DuckZ 2017-05-26 18:44:48 +01:00
parent 5d4041aed8
commit 84470cfc57

View file

@ -50,6 +50,10 @@ namespace tawashi {
// return path.substr(start_index, substr_len); // return path.substr(start_index, substr_len);
//} //}
std::string to_string (const boost::string_ref& parStr) {
return std::string(parStr.data(), parStr.size());
}
std::string make_root_path (const SettingsBag& parSettings) { std::string make_root_path (const SettingsBag& parSettings) {
auto retval = parSettings["website_root"]; auto retval = parSettings["website_root"];
if (retval.empty()) { if (retval.empty()) {
@ -109,6 +113,13 @@ namespace tawashi {
return parStr; return parStr;
}; };
boost::string_ref make_host_path (const SettingsBag& parSettings) {
boost::string_ref host_path = parSettings.at("host_path");
if (not host_path.empty() and host_path[host_path.size() - 1] == '/')
host_path = host_path.substr(0, host_path.size() - 1);
return host_path;
}
std::string make_base_uri (const Kakoune::SafePtr<SettingsBag>& parSettings, const Kakoune::SafePtr<cgi::Env>& parCgiEnv) { std::string make_base_uri (const Kakoune::SafePtr<SettingsBag>& parSettings, const Kakoune::SafePtr<cgi::Env>& parCgiEnv) {
assert(parSettings); assert(parSettings);
assert(parCgiEnv); assert(parCgiEnv);
@ -131,10 +142,8 @@ namespace tawashi {
oss << ':' << host_port; oss << ':' << host_port;
} }
} }
boost::string_ref host_path = parSettings->at("host_path");
if (not host_path.empty() and host_path[host_path.size() - 1] == '/') oss << make_host_path(*parSettings);
host_path = host_path.substr(0, host_path.size() - 1);
oss << host_path;
return oss.str(); return oss.str();
} }
} //unnamed namespace } //unnamed namespace
@ -189,6 +198,7 @@ namespace tawashi {
mstch::map mustache_context { mstch::map mustache_context {
{"version", std::string{STRINGIZE(VERSION_MAJOR) "." STRINGIZE(VERSION_MINOR) "." STRINGIZE(VERSION_PATCH)}}, {"version", std::string{STRINGIZE(VERSION_MAJOR) "." STRINGIZE(VERSION_MINOR) "." STRINGIZE(VERSION_PATCH)}},
{"base_uri", std::string(base_uri())}, {"base_uri", std::string(base_uri())},
{"host_path", to_string(make_host_path(this->settings()))},
{"languages", make_mstch_langmap(*m_settings)} {"languages", make_mstch_langmap(*m_settings)}
}; };