32 if (
const auto maybe_comment = jc.
get().comment();
33 maybe_comment.has_value()) {
34 ctx[
"element"][
"comment"] = maybe_comment.value();
51 ctx[
"element"][
"type"] = jc.
get().type_name();
52 ctx[
"element"][
"alias"] = jc.
get().alias();
53 ctx[
"element"][
"full_name"] =
55 auto maybe_doxygen_link = jc.
get().doxygen_link();
56 if (maybe_doxygen_link)
57 ctx[
"element"][
"doxygen_link"] = maybe_doxygen_link.value();
66 ctx[
"element"][
"using_namespace"] = jc.
get().using_namespace().to_string();
67 ctx[
"element"][
"namespace"] = jc.
get().get_namespace().to_string();
75 ctx[
"element"][
"type"] =
"relationship";
76 ctx[
"element"][
"name"] = jc.
get().label();
77 ctx[
"element"][
"relationship_type"] =
to_string(jc.
get().type());
78 ctx[
"element"][
"multiplicity"][
"source"] = jc.
get().multiplicity_source();
79 ctx[
"element"][
"multiplicity"][
"destination"] =
80 jc.
get().multiplicity_destination();
90 std::filesystem::path fullNamePath{
91 ctx[
"element"][
"full_name"].get<std::string>()};
92 fullNamePath.make_preferred();
93 ctx[
"element"][
"full_name"] = fullNamePath.string();
98 const auto &e = jc.
get();
100 if (!e.file().empty()) {
101 const std::filesystem::path file{e.file()};
102 std::string git_relative_path = file.string();
103 if (!e.file_relative().empty()) {
105 if (file.is_absolute() && ctx.contains(
"git")) {
107 if (file.is_absolute() && ctx.contains(
"git")) {
109 git_relative_path = std::filesystem::relative(
110 weakly_canonical(file), ctx[
"git"][
"toplevel"])
115 ctx[
"source"][
"path"] = e.file();
119 git_relative_path =
"";
120 ctx[
"source"][
"path"] = e.file();
123 ctx[
"source"][
"full_path"] = file.string();
124 ctx[
"source"][
"name"] = file.filename().string();
125 ctx[
"source"][
"line"] = e.line();
131 const auto &e = jc.
get();
133 if (!e.file().empty()) {
134 const std::filesystem::path file{e.file()};
135 std::string git_relative_path = file.string();
136 if (!e.file_relative().empty()) {
138 if (file.is_absolute() && ctx.contains(
"git")) {
140 if (file.is_absolute() && ctx.contains(
"git")) {
142 git_relative_path = std::filesystem::relative(
143 weakly_canonical(file), ctx[
"git"][
"toplevel"])
146 ctx[
"element"][
"source"][
"path"] =
150 ctx[
"element"][
"source"][
"path"] = e.file();
154 git_relative_path =
"";
155 ctx[
"element"][
"source"][
"path"] = e.file();
158 ctx[
"element"][
"source"][
"full_path"] = file.string();
159 ctx[
"element"][
"source"][
"name"] = file.filename().string();
160 ctx[
"element"][
"source"][
"line"] = e.line();
167 if (
const auto maybe_comment = jc.
get().comment();
168 maybe_comment.has_value()) {
169 ctx[
"comment"] = maybe_comment.value();
179 ctx[
"type"] = jc.
get().type_name();
180 ctx[
"alias"] = jc.
get().alias();
182 auto maybe_doxygen_link = jc.
get().doxygen_link();
183 if (maybe_doxygen_link)
184 ctx[
"doxygen_link"] = maybe_doxygen_link.value();
193 ctx[
"using_namespace"] = jc.
get().using_namespace().to_string();
194 ctx[
"namespace"] = jc.
get().get_namespace().to_string();
195 if (
const auto maybe_comment = jc.
get().comment();
196 maybe_comment.has_value()) {
197 ctx[
"comment"] = maybe_comment.value();
205 std::filesystem::path fullNamePath{ctx[
"full_name"].get<std::string>()};
206 fullNamePath.make_preferred();
207 ctx[
"full_name"] = fullNamePath.string();
211 const inja::json &
context,
const std::string &jinja_template)
213 std::optional<std::string> result;
215 if (jinja_template.empty())
220 auto rendered_template =
221 env.render(std::string_view{jinja_template},
context);
223 result = std::move(rendered_template);
226 LOG_WARN(
"Failed to render Jinja template '{}' due to unresolvable "
228 jinja_template, e.what());
230 catch (
const inja::json::parse_error &e) {
231 LOG_WARN(
"Failed to parse Jinja template: {}", jinja_template);
233 catch (
const inja::json::exception &e) {
234 LOG_WARN(
"Failed to render Jinja template: \n{}\n due to: {}",
235 jinja_template, e.what());
237 catch (
const std::regex_error &e) {
238 LOG_WARN(
"Failed to render Jinja template: \n{}\n due to "
239 "std::regex_error: {}",
240 jinja_template, e.what());
242 catch (
const std::exception &e) {
243 LOG_WARN(
"Failed to render Jinja template: \n{}\n due to: {}",
244 jinja_template, e.what());
251 inja::Environment &env,
const std::string &jinja_template)