mirror of
https://github.com/KingDuckZ/kamokan.git
synced 2024-12-27 21:35:41 +00:00
Revert "Pass the ResponseFactory object down to the Response itself."
This reverts commit 3bc6c56c03
.
This commit is contained in:
parent
3bc6c56c03
commit
73707c2ad0
12 changed files with 11 additions and 38 deletions
|
@ -54,14 +54,8 @@ namespace {
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
std::unique_ptr<tawashi::Response> make_response (
|
||||
const Kakoune::SafePtr<tawashi::ResponseFactory>& parFactory,
|
||||
const Kakoune::SafePtr<tawashi::SettingsBag>& parSettings,
|
||||
const Kakoune::SafePtr<tawashi::cgi::Env>& parCgiEnv
|
||||
) {
|
||||
return static_cast<std::unique_ptr<tawashi::Response>>(
|
||||
std::make_unique<T>(parFactory, parSettings, &std::cout, parCgiEnv)
|
||||
);
|
||||
std::unique_ptr<tawashi::Response> make_response (const Kakoune::SafePtr<tawashi::SettingsBag>& parSettings, const Kakoune::SafePtr<tawashi::cgi::Env>& parCgiEnv) {
|
||||
return static_cast<std::unique_ptr<tawashi::Response>>(std::make_unique<T>(parSettings, &std::cout, parCgiEnv));
|
||||
}
|
||||
|
||||
void fill_defaults (tawashi::SettingsBag& parSettings) {
|
||||
|
|
|
@ -20,12 +20,11 @@
|
|||
|
||||
namespace tawashi {
|
||||
IndexResponse::IndexResponse (
|
||||
const Kakoune::SafePtr<ResponseFactory>& parFactory,
|
||||
const Kakoune::SafePtr<SettingsBag>& parSettings,
|
||||
std::ostream* parStreamOut,
|
||||
const Kakoune::SafePtr<cgi::Env>& parCgiEnv
|
||||
) :
|
||||
Response(parFactory, parSettings, parStreamOut, parCgiEnv, false)
|
||||
Response(parSettings, parStreamOut, parCgiEnv, false)
|
||||
{
|
||||
}
|
||||
} //namespace tawashi
|
||||
|
|
|
@ -24,7 +24,6 @@ namespace tawashi {
|
|||
class IndexResponse : public Response {
|
||||
public:
|
||||
IndexResponse (
|
||||
const Kakoune::SafePtr<ResponseFactory>& parFactory,
|
||||
const Kakoune::SafePtr<SettingsBag>& parSettings,
|
||||
std::ostream* parStreamOut,
|
||||
const Kakoune::SafePtr<cgi::Env>& parCgiEnv
|
||||
|
|
|
@ -31,12 +31,11 @@ namespace tawashi {
|
|||
} //unnamed namespace
|
||||
|
||||
PastieResponse::PastieResponse (
|
||||
const Kakoune::SafePtr<ResponseFactory>& parFactory,
|
||||
const Kakoune::SafePtr<SettingsBag>& parSettings,
|
||||
std::ostream* parStreamOut,
|
||||
const Kakoune::SafePtr<cgi::Env>& parCgiEnv
|
||||
) :
|
||||
Response(parFactory, parSettings, parStreamOut, parCgiEnv, true),
|
||||
Response(parSettings, parStreamOut, parCgiEnv, true),
|
||||
m_langmap_dir(parSettings->as<std::string>("langmap_dir")),
|
||||
m_plain_text(false),
|
||||
m_syntax_highlight(true)
|
||||
|
|
|
@ -25,7 +25,6 @@ namespace tawashi {
|
|||
class PastieResponse : public Response {
|
||||
public:
|
||||
PastieResponse (
|
||||
const Kakoune::SafePtr<ResponseFactory>& parFactory,
|
||||
const Kakoune::SafePtr<SettingsBag>& parSettings,
|
||||
std::ostream* parStreamOut,
|
||||
const Kakoune::SafePtr<cgi::Env>& parCgiEnv
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "pathname/pathname.hpp"
|
||||
#include "list_highlight_langs.hpp"
|
||||
#include "cgi_env.hpp"
|
||||
#include "response_factory.hpp"
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
#include <fstream>
|
||||
|
@ -109,14 +108,12 @@ namespace tawashi {
|
|||
} //unnamed namespace
|
||||
|
||||
Response::Response (
|
||||
const Kakoune::SafePtr<ResponseFactory>& parFactory,
|
||||
const Kakoune::SafePtr<SettingsBag>& parSettings,
|
||||
std::ostream* parStreamOut,
|
||||
const Kakoune::SafePtr<cgi::Env>& parCgiEnv,
|
||||
bool parWantRedis
|
||||
) :
|
||||
m_resp_value(g_def_response_type),
|
||||
m_factory(parFactory),
|
||||
//m_page_basename(fetch_page_basename(m_cgi_env)),
|
||||
m_cgi_env(parCgiEnv),
|
||||
m_settings(parSettings),
|
||||
|
@ -127,7 +124,6 @@ namespace tawashi {
|
|||
{
|
||||
assert(m_cgi_env);
|
||||
assert(m_stream_out);
|
||||
assert(m_factory);
|
||||
|
||||
if (parWantRedis) {
|
||||
m_redis = std::make_unique<redis::IncRedis>(make_incredis(*parSettings));
|
||||
|
|
|
@ -30,7 +30,6 @@ namespace redis {
|
|||
|
||||
namespace tawashi {
|
||||
class SettingsBag;
|
||||
class ResponseFactory;
|
||||
|
||||
namespace cgi {
|
||||
class Env;
|
||||
|
@ -49,7 +48,6 @@ namespace tawashi {
|
|||
};
|
||||
|
||||
Response (
|
||||
const Kakoune::SafePtr<ResponseFactory>& parFactory,
|
||||
const Kakoune::SafePtr<SettingsBag>& parSettings,
|
||||
std::ostream* parStreamOut,
|
||||
const Kakoune::SafePtr<cgi::Env>& parCgiEnv,
|
||||
|
@ -69,7 +67,6 @@ namespace tawashi {
|
|||
virtual std::string on_mustache_retrieve();
|
||||
|
||||
std::string m_resp_value;
|
||||
Kakoune::SafePtr<ResponseFactory> m_factory;
|
||||
Kakoune::SafePtr<cgi::Env> m_cgi_env;
|
||||
Kakoune::SafePtr<SettingsBag> m_settings;
|
||||
std::string m_website_root;
|
||||
|
|
|
@ -45,12 +45,11 @@ namespace tawashi {
|
|||
//spdlog::get("statuslog")->info("making response object for \"{}\"", parName);
|
||||
|
||||
auto maker_it = m_local_data->makers.find(std::string(parName.data(), parName.size()));
|
||||
Kakoune::SafePtr<ResponseFactory> self(this);
|
||||
if (m_local_data->makers.end() != maker_it) {
|
||||
return maker_it->second(self, m_local_data->settings, m_local_data->cgi_env);
|
||||
return maker_it->second(m_local_data->settings, m_local_data->cgi_env);
|
||||
}
|
||||
else if (m_local_data->jolly_maker) {
|
||||
return m_local_data->jolly_maker(self, m_local_data->settings, m_local_data->cgi_env);
|
||||
return m_local_data->jolly_maker(m_local_data->settings, m_local_data->cgi_env);
|
||||
}
|
||||
else {
|
||||
assert(false);
|
||||
|
|
|
@ -28,13 +28,9 @@ namespace tawashi {
|
|||
class Env;
|
||||
} //namespace cgi
|
||||
|
||||
class ResponseFactory : public Kakoune::SafeCountable {
|
||||
class ResponseFactory {
|
||||
public:
|
||||
typedef std::function<std::unique_ptr<Response>(
|
||||
const Kakoune::SafePtr<ResponseFactory>&,
|
||||
const Kakoune::SafePtr<SettingsBag>&,
|
||||
const Kakoune::SafePtr<cgi::Env>&
|
||||
)> ResponseMakerFunc;
|
||||
typedef std::function<std::unique_ptr<Response>(const Kakoune::SafePtr<SettingsBag>&, const Kakoune::SafePtr<cgi::Env>& parCgiEnv)> ResponseMakerFunc;
|
||||
|
||||
explicit ResponseFactory (const Kakoune::SafePtr<SettingsBag>& parSettings, const Kakoune::SafePtr<cgi::Env>& parCgiEnv);
|
||||
~ResponseFactory() noexcept;
|
||||
|
|
|
@ -90,12 +90,11 @@ namespace tawashi {
|
|||
} //unnamed namespace
|
||||
|
||||
SubmitPasteResponse::SubmitPasteResponse (
|
||||
const Kakoune::SafePtr<ResponseFactory>& parFactory,
|
||||
const Kakoune::SafePtr<SettingsBag>& parSettings,
|
||||
std::ostream* parStreamOut,
|
||||
const Kakoune::SafePtr<cgi::Env>& parCgiEnv
|
||||
) :
|
||||
Response(parFactory, parSettings, parStreamOut, parCgiEnv, true)
|
||||
Response(parSettings, parStreamOut, parCgiEnv, true)
|
||||
{
|
||||
this->change_type(Response::ContentType, "text/plain");
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@ namespace tawashi {
|
|||
class SubmitPasteResponse : public Response {
|
||||
public:
|
||||
SubmitPasteResponse (
|
||||
const Kakoune::SafePtr<ResponseFactory>& parFactory,
|
||||
const Kakoune::SafePtr<SettingsBag>& parSettings,
|
||||
std::ostream* parStreamOut,
|
||||
const Kakoune::SafePtr<cgi::Env>& parCgiEnv
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "ini_file.hpp"
|
||||
#include "settings_bag.hpp"
|
||||
#include "safe_stack_object.hpp"
|
||||
#include "response_factory.hpp"
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
#include <string>
|
||||
|
@ -58,12 +57,11 @@ namespace tawashi {
|
|||
class IndexResponseCustomMustache : public IndexResponse {
|
||||
public:
|
||||
IndexResponseCustomMustache (
|
||||
const Kakoune::SafePtr<ResponseFactory>& parFactory,
|
||||
const Kakoune::SafePtr<SettingsBag>& parSettings,
|
||||
std::ostream* parStreamOut,
|
||||
const Kakoune::SafePtr<cgi::Env>& parCgiEnv
|
||||
) :
|
||||
IndexResponse(parFactory, parSettings, parStreamOut, parCgiEnv)
|
||||
IndexResponse(parSettings, parStreamOut, parCgiEnv)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -108,8 +106,7 @@ TEST_CASE ("Index response", "[index][response]") {
|
|||
|
||||
std::stringstream response_stream;
|
||||
|
||||
SafeStackObject<tawashi::ResponseFactory> resp_factory(settings, fake_env);
|
||||
tawashi::IndexResponseCustomMustache response(resp_factory, settings, &response_stream, fake_env);
|
||||
tawashi::IndexResponseCustomMustache response(settings, &response_stream, fake_env);
|
||||
response.send();
|
||||
|
||||
response_stream.seekg(0);
|
||||
|
|
Loading…
Reference in a new issue