mirror of https://github.com/kiwix/libkiwix.git
Enter ContentResponseBlueprint::Data
ContentResponseBlueprint::m_data is now an opaque data member implemented in the .cpp and ready to be switched from kainjow::mustache::data to a different implementation.
This commit is contained in:
parent
d39e91f6bc
commit
e72fc2391d
|
@ -151,6 +151,13 @@ std::unique_ptr<Response> Response::build_304(const ETag& etag)
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ContentResponseBlueprint::Data : public kainjow::mustache::data
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Data() {}
|
||||||
|
template<class T> Data(const T& t) : kainjow::mustache::data(t) {}
|
||||||
|
};
|
||||||
|
|
||||||
ContentResponseBlueprint::ContentResponseBlueprint(const RequestContext* request,
|
ContentResponseBlueprint::ContentResponseBlueprint(const RequestContext* request,
|
||||||
int httpStatusCode,
|
int httpStatusCode,
|
||||||
const std::string& mimeType,
|
const std::string& mimeType,
|
||||||
|
@ -159,8 +166,11 @@ ContentResponseBlueprint::ContentResponseBlueprint(const RequestContext* request
|
||||||
, m_httpStatusCode(httpStatusCode)
|
, m_httpStatusCode(httpStatusCode)
|
||||||
, m_mimeType(mimeType)
|
, m_mimeType(mimeType)
|
||||||
, m_template(templateStr)
|
, m_template(templateStr)
|
||||||
|
, m_data(new Data)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
ContentResponseBlueprint::~ContentResponseBlueprint() = default;
|
||||||
|
|
||||||
std::string ContentResponseBlueprint::getMessage(const std::string& msgId) const
|
std::string ContentResponseBlueprint::getMessage(const std::string& msgId) const
|
||||||
{
|
{
|
||||||
return getTranslatedString(m_request.get_user_language(), msgId);
|
return getTranslatedString(m_request.get_user_language(), msgId);
|
||||||
|
@ -168,7 +178,7 @@ std::string ContentResponseBlueprint::getMessage(const std::string& msgId) const
|
||||||
|
|
||||||
std::unique_ptr<ContentResponse> ContentResponseBlueprint::generateResponseObject() const
|
std::unique_ptr<ContentResponse> ContentResponseBlueprint::generateResponseObject() const
|
||||||
{
|
{
|
||||||
auto r = ContentResponse::build(m_template, m_data, m_mimeType);
|
auto r = ContentResponse::build(m_template, *m_data, m_mimeType);
|
||||||
r->set_code(m_httpStatusCode);
|
r->set_code(m_httpStatusCode);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
@ -184,7 +194,7 @@ HTTPErrorResponse::HTTPErrorResponse(const RequestContext& request,
|
||||||
request.get_requested_format() == "html" ? RESOURCE::templates::error_html : RESOURCE::templates::error_xml)
|
request.get_requested_format() == "html" ? RESOURCE::templates::error_html : RESOURCE::templates::error_xml)
|
||||||
{
|
{
|
||||||
kainjow::mustache::list emptyList;
|
kainjow::mustache::list emptyList;
|
||||||
this->m_data = kainjow::mustache::object{
|
*this->m_data = kainjow::mustache::object{
|
||||||
{"CSS_URL", onlyAsNonEmptyMustacheValue(cssUrl) },
|
{"CSS_URL", onlyAsNonEmptyMustacheValue(cssUrl) },
|
||||||
{"PAGE_TITLE", getMessage(pageTitleMsgId)},
|
{"PAGE_TITLE", getMessage(pageTitleMsgId)},
|
||||||
{"PAGE_HEADING", getMessage(headingMsgId)},
|
{"PAGE_HEADING", getMessage(headingMsgId)},
|
||||||
|
@ -210,7 +220,7 @@ UrlNotFoundResponse::UrlNotFoundResponse(const RequestContext& request)
|
||||||
HTTPErrorResponse& HTTPErrorResponse::operator+(const ParameterizedMessage& details)
|
HTTPErrorResponse& HTTPErrorResponse::operator+(const ParameterizedMessage& details)
|
||||||
{
|
{
|
||||||
const std::string msg = details.getText(m_request.get_user_language());
|
const std::string msg = details.getText(m_request.get_user_language());
|
||||||
m_data["details"].push_back({"p", msg});
|
(*m_data)["details"].push_back({"p", msg});
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -123,6 +123,8 @@ public: // functions
|
||||||
const std::string& mimeType,
|
const std::string& mimeType,
|
||||||
const std::string& templateStr);
|
const std::string& templateStr);
|
||||||
|
|
||||||
|
~ContentResponseBlueprint();
|
||||||
|
|
||||||
operator std::unique_ptr<Response>() const
|
operator std::unique_ptr<Response>() const
|
||||||
{
|
{
|
||||||
return generateResponseObject();
|
return generateResponseObject();
|
||||||
|
@ -130,6 +132,9 @@ public: // functions
|
||||||
|
|
||||||
std::unique_ptr<ContentResponse> generateResponseObject() const;
|
std::unique_ptr<ContentResponse> generateResponseObject() const;
|
||||||
|
|
||||||
|
protected: // types
|
||||||
|
class Data;
|
||||||
|
|
||||||
protected: // functions
|
protected: // functions
|
||||||
std::string getMessage(const std::string& msgId) const;
|
std::string getMessage(const std::string& msgId) const;
|
||||||
|
|
||||||
|
@ -138,7 +143,7 @@ protected: //data
|
||||||
const int m_httpStatusCode;
|
const int m_httpStatusCode;
|
||||||
const std::string m_mimeType;
|
const std::string m_mimeType;
|
||||||
const std::string m_template;
|
const std::string m_template;
|
||||||
kainjow::mustache::data m_data;
|
std::unique_ptr<Data> m_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct HTTPErrorResponse : ContentResponseBlueprint
|
struct HTTPErrorResponse : ContentResponseBlueprint
|
||||||
|
|
Loading…
Reference in New Issue