Added comment() inja function - Fixes #30
This commit is contained in:
10
README.md
10
README.md
@@ -319,24 +319,24 @@ each diagram using simple YAML configuration:
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
include:
|
include:
|
||||||
# Include elements from 2 namespaces
|
# Include only elements from these namespaces
|
||||||
namespaces:
|
namespaces:
|
||||||
- clanguml::common
|
- clanguml::common
|
||||||
- clanguml::config
|
- clanguml::config
|
||||||
# Include all subclasses of ClassA (including ClassA)
|
# Include all subclasses of ClassA (including ClassA)
|
||||||
subclasses:
|
subclasses:
|
||||||
- clanguml::common::ClassA
|
- clanguml::common::ClassA
|
||||||
|
# and classes in direct relation to ClassB (including ClassB)
|
||||||
|
context:
|
||||||
|
- clanguml::common::ClassB
|
||||||
# Include only inheritance relationships
|
# Include only inheritance relationships
|
||||||
relationships:
|
relationships:
|
||||||
- inheritance
|
- inheritance
|
||||||
# Include only classes in direct relation to ClassB (including ClassB)
|
|
||||||
context:
|
|
||||||
- clanguml::common::ClassB
|
|
||||||
exclude:
|
exclude:
|
||||||
# Exclude all elements from detail namespace
|
# Exclude all elements from detail namespace
|
||||||
namespaces:
|
namespaces:
|
||||||
- clanguml::common::detail
|
- clanguml::common::detail
|
||||||
# Exclude ClassF
|
# and also exclude ClassF
|
||||||
exclude:
|
exclude:
|
||||||
- clanguml::common::ClassF
|
- clanguml::common::ClassF
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -41,6 +41,21 @@ common::model::diagram_t diagram::type() const
|
|||||||
return common::model::diagram_t::kClass;
|
return common::model::diagram_t::kClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type_safe::optional_ref<const clanguml::common::model::element> diagram::get(
|
||||||
|
const std::string &full_name) const
|
||||||
|
{
|
||||||
|
type_safe::optional_ref<const clanguml::common::model::element> res;
|
||||||
|
|
||||||
|
res = get_class(full_name);
|
||||||
|
|
||||||
|
if (res.has_value())
|
||||||
|
return res;
|
||||||
|
|
||||||
|
res = get_enum(full_name);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
bool diagram::has_class(const class_ &c) const
|
bool diagram::has_class(const class_ &c) const
|
||||||
{
|
{
|
||||||
return std::any_of(classes_.cbegin(), classes_.cend(),
|
return std::any_of(classes_.cbegin(), classes_.cend(),
|
||||||
@@ -65,6 +80,18 @@ type_safe::optional_ref<const class_> diagram::get_class(
|
|||||||
return type_safe::nullopt;
|
return type_safe::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type_safe::optional_ref<const enum_> diagram::get_enum(
|
||||||
|
const std::string &name) const
|
||||||
|
{
|
||||||
|
for (const auto &e : enums_) {
|
||||||
|
if (e.get().full_name(false) == name) {
|
||||||
|
return {e};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return type_safe::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
void diagram::add_type_alias(std::unique_ptr<type_alias> &&ta)
|
void diagram::add_type_alias(std::unique_ptr<type_alias> &&ta)
|
||||||
{
|
{
|
||||||
LOG_DBG(
|
LOG_DBG(
|
||||||
|
|||||||
@@ -43,6 +43,9 @@ public:
|
|||||||
|
|
||||||
common::model::diagram_t type() const override;
|
common::model::diagram_t type() const override;
|
||||||
|
|
||||||
|
type_safe::optional_ref<const clanguml::common::model::element> get(
|
||||||
|
const std::string &full_name) const override;
|
||||||
|
|
||||||
const std::vector<type_safe::object_ref<const class_>> classes() const;
|
const std::vector<type_safe::object_ref<const class_>> classes() const;
|
||||||
|
|
||||||
const std::vector<type_safe::object_ref<const enum_>> enums() const;
|
const std::vector<type_safe::object_ref<const enum_>> enums() const;
|
||||||
@@ -54,6 +57,9 @@ public:
|
|||||||
type_safe::optional_ref<const class_> get_class(
|
type_safe::optional_ref<const class_> get_class(
|
||||||
const std::string &name) const;
|
const std::string &name) const;
|
||||||
|
|
||||||
|
type_safe::optional_ref<const enum_> get_enum(
|
||||||
|
const std::string &name) const;
|
||||||
|
|
||||||
void add_type_alias(std::unique_ptr<type_alias> &&ta);
|
void add_type_alias(std::unique_ptr<type_alias> &&ta);
|
||||||
|
|
||||||
void add_class(std::unique_ptr<class_> &&c);
|
void add_class(std::unique_ptr<class_> &&c);
|
||||||
|
|||||||
@@ -325,6 +325,27 @@ template <typename C, typename D> void generator<C, D>::init_env()
|
|||||||
return m_model.to_alias(
|
return m_model.to_alias(
|
||||||
m_config.using_namespace().relative(alias_match));
|
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;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
#include "enums.h"
|
#include "enums.h"
|
||||||
|
|
||||||
|
#include <type_safe/optional_ref.hpp>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -36,6 +38,9 @@ public:
|
|||||||
|
|
||||||
virtual diagram_t type() const = 0;
|
virtual diagram_t type() const = 0;
|
||||||
|
|
||||||
|
virtual type_safe::optional_ref<const element> get(
|
||||||
|
const std::string &full_name) const = 0;
|
||||||
|
|
||||||
diagram(const diagram &) = delete;
|
diagram(const diagram &) = delete;
|
||||||
diagram(diagram &&);
|
diagram(diagram &&);
|
||||||
diagram &operator=(const diagram &) = delete;
|
diagram &operator=(const diagram &) = delete;
|
||||||
|
|||||||
@@ -80,6 +80,9 @@ inja::json element::context() const
|
|||||||
ctx["alias"] = alias();
|
ctx["alias"] = alias();
|
||||||
ctx["full_name"] = full_name(false);
|
ctx["full_name"] = full_name(false);
|
||||||
ctx["namespace"] = get_namespace().to_string();
|
ctx["namespace"] = get_namespace().to_string();
|
||||||
|
if (comment().has_value())
|
||||||
|
ctx["comment"] = comment().value();
|
||||||
|
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,12 @@ common::model::diagram_t diagram::type() const
|
|||||||
return common::model::diagram_t::kPackage;
|
return common::model::diagram_t::kPackage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type_safe::optional_ref<const clanguml::common::model::element> diagram::get(
|
||||||
|
const std::string &full_name) const
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
std::string diagram::to_alias(const std::string &full_name) const
|
std::string diagram::to_alias(const std::string &full_name) const
|
||||||
{
|
{
|
||||||
LOG_DBG("Looking for alias for {}", full_name);
|
LOG_DBG("Looking for alias for {}", full_name);
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ public:
|
|||||||
|
|
||||||
common::model::diagram_t type() const override;
|
common::model::diagram_t type() const override;
|
||||||
|
|
||||||
|
type_safe::optional_ref<const clanguml::common::model::element> get(
|
||||||
|
const std::string &full_name) const;
|
||||||
|
|
||||||
std::string to_alias(const std::string &full_name) const;
|
std::string to_alias(const std::string &full_name) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,12 @@ common::model::diagram_t diagram::type() const
|
|||||||
return common::model::diagram_t::kSequence;
|
return common::model::diagram_t::kSequence;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type_safe::optional_ref<const clanguml::common::model::element> diagram::get(
|
||||||
|
const std::string &full_name) const
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
std::string diagram::to_alias(const std::string &full_name) const
|
std::string diagram::to_alias(const std::string &full_name) const
|
||||||
{
|
{
|
||||||
return full_name;
|
return full_name;
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ public:
|
|||||||
|
|
||||||
common::model::diagram_t type() const override;
|
common::model::diagram_t type() const override;
|
||||||
|
|
||||||
|
type_safe::optional_ref<const clanguml::common::model::element> get(
|
||||||
|
const std::string &full_name) const;
|
||||||
|
|
||||||
std::string to_alias(const std::string &full_name) const;
|
std::string to_alias(const std::string &full_name) const;
|
||||||
|
|
||||||
bool started{false};
|
bool started{false};
|
||||||
|
|||||||
@@ -12,4 +12,9 @@ diagrams:
|
|||||||
- clanguml::t00002
|
- clanguml::t00002
|
||||||
plantuml:
|
plantuml:
|
||||||
after:
|
after:
|
||||||
- 'note left of @A(A) : Base abstract interface.'
|
- 'note left of @A(A) : {{ comment("A") }}'
|
||||||
|
- 'note top of @A(B) : {{ comment("clanguml::t00002::B") }}'
|
||||||
|
- |
|
||||||
|
note right of {{ alias("D") }}
|
||||||
|
{{ comment("D") }}
|
||||||
|
end note
|
||||||
@@ -56,6 +56,9 @@ TEST_CASE("t00002", "[test-case][class]")
|
|||||||
|
|
||||||
REQUIRE_THAT(puml, IsAssociation(_A("D"), _A("A"), "-as"));
|
REQUIRE_THAT(puml, IsAssociation(_A("D"), _A("A"), "-as"));
|
||||||
|
|
||||||
|
REQUIRE_THAT(puml, HasNote(_A("A"), "left", "This is class A"));
|
||||||
|
REQUIRE_THAT(puml, HasNote(_A("B"), "top", "This is class B"));
|
||||||
|
|
||||||
save_puml(
|
save_puml(
|
||||||
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
|
"./" + config.output_directory() + "/" + diagram->name + ".puml", puml);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user