27#include <inja/inja.hpp>
37 inja::json &context,
const std::string &prefix);
44template <
typename ConfigType,
typename DiagramType>
class generator {
72 virtual void generate(std::ostream &ostr)
const = 0;
122 const inja::json &
context()
const;
124 inja::Environment &
env()
const;
140 m_context[
"git"][
"branch"] = config.git().branch;
141 m_context[
"git"][
"revision"] = config.git().revision;
142 m_context[
"git"][
"commit"] = config.git().commit;
143 m_context[
"git"][
"toplevel"] = config.git().toplevel;
146 if (config.user_data) {
147 m_context[
"user_data"] = config.user_data();
151template <
typename C,
typename D>
157template <
typename C,
typename D>
173 m_env.add_callback(
"empty", 1, [](inja::Arguments &args) {
174 return args.at(0)->get<std::string>().empty();
178 m_env.add_callback(
"ltrim", 1, [](inja::Arguments &args) {
179 return util::ltrim(args.at(0)->get<std::string>());
183 m_env.add_callback(
"rtrim", 1, [](inja::Arguments &args) {
184 return util::rtrim(args.at(0)->get<std::string>());
188 m_env.add_callback(
"trim", 1, [](inja::Arguments &args) {
189 return util::trim(args.at(0)->get<std::string>());
193 m_env.add_callback(
"abbrv", 2, [](inja::Arguments &args) {
195 args.at(0)->get<std::string>(), args.at(1)->get<
unsigned>());
198 m_env.add_callback(
"replace", 3, [](inja::Arguments &args) {
199 std::string result = args[0]->get<std::string>();
200 std::regex pattern(args[1]->get<std::string>());
201 return std::regex_replace(result, pattern, args[2]->get<std::string>());
204 m_env.add_callback(
"split", 2, [](inja::Arguments &args) {
206 args[0]->get<std::string>(), args[1]->get<std::string>());
217 m_env.add_callback(
"element", 1, [&model, &config](inja::Arguments &args) {
219 auto element_opt = model.get_with_namespace(
220 args[0]->get<std::string>(), config.using_namespace());
222 if (element_opt.has_value()) {
235 m_env.add_callback(
"alias", 1, [&model, &config](inja::Arguments &args) {
236 const auto &element_name = args[0]->get<std::string>();
238 model.get_with_namespace(element_name, config.using_namespace());
240 if (!element_opt.has_value())
242 args[0]->get<std::string>());
244 return element_opt.value().alias();
252 m_env.add_callback(
"comment", 1, [&model, &config](inja::Arguments &args) {
254 auto element_opt = model.get_with_namespace(
255 args[0]->get<std::string>(), config.using_namespace());
257 if (!element_opt.has_value())
259 args[0]->get<std::string>());
261 auto comment = element_opt.value().comment();
263 if (comment.has_value()) {
264 assert(comment.value().is_object());
265 res = comment.value();
272template <
typename C,
typename D>
273std::optional<std::pair<std::string, std::string>>
278 return config().generate_links().get_link_pattern(sl.
file());
281 return config().generate_links().get_link_pattern(sl.
file_relative());
284template <
typename C,
typename D>
285std::optional<std::pair<std::string, std::string>>
290 return config().generate_links().get_tooltip_pattern(sl.
file());
293 return config().generate_links().get_tooltip_pattern(sl.
file_relative());
296template <
typename C,
typename D>
308 if (!maybe_link_pattern)
311 const auto &[link_prefix, link_pattern] = *maybe_link_pattern;
318 return render_template(
322template <
typename C,
typename D>
334 if (!maybe_link_pattern)
337 const auto &[link_prefix, link_pattern] = *maybe_link_pattern;
344 return render_template(
348template <
typename C,
typename D>
358 auto maybe_tooltip_pattern =
361 if (!maybe_tooltip_pattern)
364 const auto &[tooltip_prefix, tooltip_pattern] = *maybe_tooltip_pattern;
371 return render_template(
375template <
typename C,
typename D>
385 auto maybe_tooltip_pattern =
388 if (!maybe_tooltip_pattern)
391 const auto &[tooltip_prefix, tooltip_pattern] = *maybe_tooltip_pattern;
398 return render_template(