C and C++ web framework.
http://rapida.vilor.one/docs
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
789 B
36 lines
789 B
/* SPDX-License-Identifier: GPL-3.0-or-later */ |
|
/* Copyright 2022 Ivan Polyakov */ |
|
|
|
#include "Response.hxx" |
|
|
|
#ifdef EXTENSIONS_INJA |
|
#include <inja/inja.hpp> |
|
#endif |
|
|
|
using namespace rpd; |
|
|
|
#ifdef EXTENSIONS_INJA |
|
void Response::render(const char *path, nlohmann::json data) |
|
{ |
|
inja::Environment env; |
|
inja::Template tpl; |
|
|
|
try { |
|
std::string tplpath = DIST_PATH; |
|
tplpath += path; |
|
tpl = env.parse_template(tplpath); |
|
} catch (inja::FileError &e) { |
|
std::cerr << e.what() << std::endl; |
|
return; |
|
} |
|
|
|
try { |
|
std::string result = env.render(tpl, data); |
|
body(result.c_str()); |
|
} catch (inja::RenderError &e) { |
|
std::cerr << e.what() << std::endl; |
|
status(internal_server_error); |
|
return; |
|
} |
|
} |
|
#endif
|
|
|