From 8980a1d1ff82b1df6d8056b3f26219178aa84d3d Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Sat, 6 May 2017 19:16:57 +0100 Subject: [PATCH] I don't really need to store the page name in the base class. --- src/tawashi_implem/index_response.cpp | 2 +- src/tawashi_implem/index_response.hpp | 3 +++ src/tawashi_implem/pastie_response.cpp | 2 +- src/tawashi_implem/pastie_response.hpp | 3 +++ src/tawashi_implem/response.cpp | 9 ++------- src/tawashi_implem/response.hpp | 10 +++++++--- src/tawashi_implem/submit_paste_response.cpp | 2 +- src/tawashi_implem/submit_paste_response.hpp | 3 +++ 8 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/tawashi_implem/index_response.cpp b/src/tawashi_implem/index_response.cpp index c3f1bbe..f9d2a9e 100644 --- a/src/tawashi_implem/index_response.cpp +++ b/src/tawashi_implem/index_response.cpp @@ -20,7 +20,7 @@ namespace tawashi { IndexResponse::IndexResponse (const Kakoune::SafePtr& parSettings) : - Response(Response::ContentType, "text/html", "index", parSettings, false) + Response(Response::ContentType, "text/html", parSettings, false) { } } //namespace tawashi diff --git a/src/tawashi_implem/index_response.hpp b/src/tawashi_implem/index_response.hpp index c62a9a8..7a0fe9f 100644 --- a/src/tawashi_implem/index_response.hpp +++ b/src/tawashi_implem/index_response.hpp @@ -25,6 +25,9 @@ namespace tawashi { public: explicit IndexResponse (const Kakoune::SafePtr& parSettings); + protected: + virtual boost::string_ref page_basename() const override { return boost::string_ref("index"); } + private: }; } //namespace tawashi diff --git a/src/tawashi_implem/pastie_response.cpp b/src/tawashi_implem/pastie_response.cpp index 565b7e2..2637352 100644 --- a/src/tawashi_implem/pastie_response.cpp +++ b/src/tawashi_implem/pastie_response.cpp @@ -30,7 +30,7 @@ namespace tawashi { } //unnamed namespace PastieResponse::PastieResponse (const Kakoune::SafePtr& parSettings) : - Response(Response::ContentType, "text/html", "text", parSettings, true), + Response(Response::ContentType, "text/html", parSettings, true), m_langmap_dir(parSettings->as("langmap_dir")), m_plain_text(false), m_syntax_highlight(true) diff --git a/src/tawashi_implem/pastie_response.hpp b/src/tawashi_implem/pastie_response.hpp index e6ae4ac..72f59ee 100644 --- a/src/tawashi_implem/pastie_response.hpp +++ b/src/tawashi_implem/pastie_response.hpp @@ -26,6 +26,9 @@ namespace tawashi { public: explicit PastieResponse (const Kakoune::SafePtr& 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; diff --git a/src/tawashi_implem/response.cpp b/src/tawashi_implem/response.cpp index 368f838..79e0bff 100644 --- a/src/tawashi_implem/response.cpp +++ b/src/tawashi_implem/response.cpp @@ -72,7 +72,7 @@ namespace tawashi { } } - boost::optional load_whole_file (const std::string& parWebsiteRoot, const char* parSuffix, const std::string& parName, bool parThrow) { + boost::optional 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& parSettings, bool parWantRedis) : + Response::Response (Types parRespType, std::string&& parValue, const Kakoune::SafePtr& 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 content = load_whole_file(m_website_root, ".html.mstch", page_basename(), true); return *content; diff --git a/src/tawashi_implem/response.hpp b/src/tawashi_implem/response.hpp index 05bd8ea..e111b2b 100644 --- a/src/tawashi_implem/response.hpp +++ b/src/tawashi_implem/response.hpp @@ -44,11 +44,16 @@ namespace tawashi { Location }; - Response (Types parRespType, std::string&& parValue, std::string&& parPageBaseName, const Kakoune::SafePtr& parSettings, bool parWantRedis); + Response ( + Types parRespType, + std::string&& parValue, + const Kakoune::SafePtr& 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 m_settings; std::string m_website_root; - std::string m_page_basename; Types m_resp_type; std::unique_ptr m_redis; bool m_header_sent; diff --git a/src/tawashi_implem/submit_paste_response.cpp b/src/tawashi_implem/submit_paste_response.cpp index 4bc0fc2..252b867 100644 --- a/src/tawashi_implem/submit_paste_response.cpp +++ b/src/tawashi_implem/submit_paste_response.cpp @@ -61,7 +61,7 @@ namespace tawashi { } //unnamed namespace SubmitPasteResponse::SubmitPasteResponse (const Kakoune::SafePtr& parSettings) : - Response(Response::ContentType, "text/plain", "paste", parSettings, true) + Response(Response::ContentType, "text/plain", parSettings, true) { } diff --git a/src/tawashi_implem/submit_paste_response.hpp b/src/tawashi_implem/submit_paste_response.hpp index e6e44a8..6bc4482 100644 --- a/src/tawashi_implem/submit_paste_response.hpp +++ b/src/tawashi_implem/submit_paste_response.hpp @@ -27,6 +27,9 @@ namespace tawashi { public: explicit SubmitPasteResponse (const Kakoune::SafePtr& parSettings); + protected: + virtual boost::string_ref page_basename() const override { return boost::string_ref("paste"); } + private: virtual void on_process() override; boost::optional submit_to_redis (const boost::string_ref& parText, uint32_t parExpiry, const boost::string_ref& parLang) const;