Added alias() template function for resolving PlantUML aliases
This commit is contained in:
@@ -168,16 +168,19 @@ void generator<C, D>::generate_plantuml_directives(
|
|||||||
{
|
{
|
||||||
using common::model::namespace_;
|
using common::model::namespace_;
|
||||||
|
|
||||||
for (const auto &b : directives) {
|
for (const auto &d : directives) {
|
||||||
std::string note{b};
|
// Render the directive with template engine first
|
||||||
|
std::string directive{env().render(std::string_view{d}, context())};
|
||||||
|
|
||||||
|
// Now search for alias @A() directives in the text
|
||||||
std::tuple<std::string, size_t, size_t> alias_match;
|
std::tuple<std::string, size_t, size_t> alias_match;
|
||||||
while (util::find_element_alias(note, alias_match)) {
|
while (util::find_element_alias(directive, alias_match)) {
|
||||||
auto alias = m_model.to_alias(
|
auto alias = m_model.to_alias(
|
||||||
m_config.using_namespace().relative(std::get<0>(alias_match)));
|
m_config.using_namespace().relative(std::get<0>(alias_match)));
|
||||||
note.replace(
|
directive.replace(
|
||||||
std::get<1>(alias_match), std::get<2>(alias_match), alias);
|
std::get<1>(alias_match), std::get<2>(alias_match), alias);
|
||||||
}
|
}
|
||||||
ostr << note << '\n';
|
ostr << directive << '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,7 +271,9 @@ template <typename C, typename D> void generator<C, D>::init_context()
|
|||||||
|
|
||||||
template <typename C, typename D> void generator<C, D>::init_env()
|
template <typename C, typename D> void generator<C, D>::init_env()
|
||||||
{
|
{
|
||||||
|
//
|
||||||
// Add basic string functions to inja environment
|
// Add basic string functions to inja environment
|
||||||
|
//
|
||||||
m_env.add_callback("empty", 1, [](inja::Arguments &args) {
|
m_env.add_callback("empty", 1, [](inja::Arguments &args) {
|
||||||
return args.at(0)->get<std::string>().empty();
|
return args.at(0)->get<std::string>().empty();
|
||||||
});
|
});
|
||||||
@@ -300,6 +305,20 @@ template <typename C, typename D> void generator<C, D>::init_env()
|
|||||||
return util::split(
|
return util::split(
|
||||||
args[0]->get<std::string>(), args[1]->get<std::string>());
|
args[0]->get<std::string>(), args[1]->get<std::string>());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//
|
||||||
|
// Add PlantUML specific functions
|
||||||
|
//
|
||||||
|
|
||||||
|
// Convert C++ entity to PlantUML alias, e.g.
|
||||||
|
// "note left of {{ alias("ClassA") }}: This is a note"
|
||||||
|
// is equivalent to the old syntax:
|
||||||
|
// "note left of @A(ClassA): This is a note"
|
||||||
|
m_env.add_callback("alias", 1, [this](inja::Arguments &args) {
|
||||||
|
auto alias_match = args[0]->get<std::string>();
|
||||||
|
return m_model.to_alias(
|
||||||
|
m_config.using_namespace().relative(alias_match));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,5 +14,5 @@ diagrams:
|
|||||||
after:
|
after:
|
||||||
- '@A(ProductA1) <.. @A(Factory1)'
|
- '@A(ProductA1) <.. @A(Factory1)'
|
||||||
- '@A(ProductB1) <.. @A(Factory1)'
|
- '@A(ProductB1) <.. @A(Factory1)'
|
||||||
- '@A(ProductA2) <.. @A(Factory2)'
|
- '{{ alias("ProductA2") }} <.. {{ alias("Factory2") }}'
|
||||||
- '@A(ProductB2) <.. @A(Factory2)'
|
- '{{ alias("ProductB2") }} <.. {{ alias("Factory2") }}'
|
||||||
|
|||||||
@@ -17,4 +17,4 @@ diagrams:
|
|||||||
before:
|
before:
|
||||||
- "' t30001 test package diagram"
|
- "' t30001 test package diagram"
|
||||||
after:
|
after:
|
||||||
- "note right of @A(A::AA::AAA): A AAA note..."
|
- 'note right of {{ alias("A::AA::AAA") }}: A AAA note...'
|
||||||
Reference in New Issue
Block a user