1
0
Fork 0
mirror of https://github.com/KingDuckZ/kamokan.git synced 2024-12-27 21:35:41 +00:00

I don't really need to store the page name in the base class.

This commit is contained in:
King_DuckZ 2017-05-06 19:16:57 +01:00
parent ebed6fd1d4
commit 8980a1d1ff
8 changed files with 21 additions and 13 deletions

View file

@ -20,7 +20,7 @@
namespace tawashi {
IndexResponse::IndexResponse (const Kakoune::SafePtr<SettingsBag>& parSettings) :
Response(Response::ContentType, "text/html", "index", parSettings, false)
Response(Response::ContentType, "text/html", parSettings, false)
{
}
} //namespace tawashi

View file

@ -25,6 +25,9 @@ namespace tawashi {
public:
explicit IndexResponse (const Kakoune::SafePtr<SettingsBag>& parSettings);
protected:
virtual boost::string_ref page_basename() const override { return boost::string_ref("index"); }
private:
};
} //namespace tawashi

View file

@ -30,7 +30,7 @@ namespace tawashi {
} //unnamed namespace
PastieResponse::PastieResponse (const Kakoune::SafePtr<SettingsBag>& parSettings) :
Response(Response::ContentType, "text/html", "text", parSettings, true),
Response(Response::ContentType, "text/html", parSettings, true),
m_langmap_dir(parSettings->as<std::string>("langmap_dir")),
m_plain_text(false),
m_syntax_highlight(true)

View file

@ -26,6 +26,9 @@ namespace tawashi {
public:
explicit PastieResponse (const Kakoune::SafePtr<SettingsBag>& parSettings);
protected:
virtual boost::string_ref page_basename() const override { return boost::string_ref("text"); }
private:
virtual void on_process() override;
virtual void on_mustache_prepare (mstch::map& parContext) override;

View file

@ -72,7 +72,7 @@ namespace tawashi {
}
}
boost::optional<std::string> load_whole_file (const std::string& parWebsiteRoot, const char* parSuffix, const std::string& parName, bool parThrow) {
boost::optional<std::string> load_whole_file (const std::string& parWebsiteRoot, const char* parSuffix, const boost::string_ref& parName, bool parThrow) {
std::ostringstream oss;
oss << parWebsiteRoot << parName << parSuffix;
spdlog::get("statuslog")->debug("Trying to load \"{}\"", oss.str());
@ -104,12 +104,11 @@ namespace tawashi {
};
} //unnamed namespace
Response::Response (Types parRespType, std::string&& parValue, std::string&& parPageBaseName, const Kakoune::SafePtr<SettingsBag>& parSettings, bool parWantRedis) :
Response::Response (Types parRespType, std::string&& parValue, const Kakoune::SafePtr<SettingsBag>& parSettings, bool parWantRedis) :
m_resp_value(std::move(parValue)),
//m_page_basename(fetch_page_basename(m_cgi_env)),
m_settings(parSettings),
m_website_root(make_root_path(*parSettings)),
m_page_basename(std::move(parPageBaseName)),
m_resp_type(parRespType),
m_header_sent(false)
{
@ -210,10 +209,6 @@ namespace tawashi {
return m_settings->at("base_uri");
}
const std::string& Response::page_basename() const {
return m_page_basename;
}
std::string Response::load_mustache() const {
boost::optional<std::string> content = load_whole_file(m_website_root, ".html.mstch", page_basename(), true);
return *content;

View file

@ -44,11 +44,16 @@ namespace tawashi {
Location
};
Response (Types parRespType, std::string&& parValue, std::string&& parPageBaseName, const Kakoune::SafePtr<SettingsBag>& parSettings, bool parWantRedis);
Response (
Types parRespType,
std::string&& parValue,
const Kakoune::SafePtr<SettingsBag>& parSettings,
bool parWantRedis
);
const cgi::Env& cgi_env() const;
void change_type (Types parRespType, std::string&& parValue);
const boost::string_ref& base_uri() const;
const std::string& page_basename() const;
virtual boost::string_ref page_basename() const = 0;
redis::IncRedis& redis() const;
const SettingsBag& settings() const;
virtual std::string load_mustache() const;
@ -62,7 +67,6 @@ namespace tawashi {
std::string m_resp_value;
Kakoune::SafePtr<SettingsBag> m_settings;
std::string m_website_root;
std::string m_page_basename;
Types m_resp_type;
std::unique_ptr<redis::IncRedis> m_redis;
bool m_header_sent;

View file

@ -61,7 +61,7 @@ namespace tawashi {
} //unnamed namespace
SubmitPasteResponse::SubmitPasteResponse (const Kakoune::SafePtr<SettingsBag>& parSettings) :
Response(Response::ContentType, "text/plain", "paste", parSettings, true)
Response(Response::ContentType, "text/plain", parSettings, true)
{
}

View file

@ -27,6 +27,9 @@ namespace tawashi {
public:
explicit SubmitPasteResponse (const Kakoune::SafePtr<SettingsBag>& parSettings);
protected:
virtual boost::string_ref page_basename() const override { return boost::string_ref("paste"); }
private:
virtual void on_process() override;
boost::optional<std::string> submit_to_redis (const boost::string_ref& parText, uint32_t parExpiry, const boost::string_ref& parLang) const;