Added comment() inja function - Fixes #30

This commit is contained in:
Bartek Kryza
2022-04-02 14:52:00 +02:00
parent 7a8cd5925b
commit 2d9f7c88f5
12 changed files with 94 additions and 6 deletions

View File

@@ -325,6 +325,27 @@ template <typename C, typename D> void generator<C, D>::init_env()
return m_model.to_alias(
m_config.using_namespace().relative(alias_match));
});
m_env.add_callback("comment", 1, [this](inja::Arguments &args) {
std::string res{};
auto full_name = args[0]->get<std::string>();
auto element = m_model.get(full_name);
if (!element.has_value()) {
// Try with current using namespace prepended
element = m_model.get(fmt::format(
"{}::{}", m_config.using_namespace().to_string(), full_name));
}
if (element.has_value()) {
auto comment = element.value().comment();
if (comment.has_value())
res = comment.value();
}
return res;
});
}
}