Added options to render diagrams using plantuml and mermaidjs external tools

This commit is contained in:
Bartek Kryza
2023-11-12 22:57:37 +01:00
parent 429e1c47a9
commit 35f45a07e6
21 changed files with 266 additions and 40 deletions

View File

@@ -170,12 +170,16 @@ void plantuml::append(const plantuml &r)
{
before.insert(before.end(), r.before.begin(), r.before.end());
after.insert(after.end(), r.after.begin(), r.after.end());
if (cmd.empty())
cmd = r.cmd;
}
void mermaid::append(const mermaid &r)
{
before.insert(before.end(), r.before.begin(), r.before.end());
after.insert(after.end(), r.after.begin(), r.after.end());
if (cmd.empty())
cmd = r.cmd;
}
void inheritable_diagram_options::inherit(
@@ -188,6 +192,7 @@ void inheritable_diagram_options::inherit(
include.override(parent.include);
exclude.override(parent.exclude);
puml.override(parent.puml);
mermaid.override(parent.mermaid);
generate_method_arguments.override(parent.generate_method_arguments);
generate_packages.override(parent.generate_packages);
generate_template_argument_dependencies.override(

View File

@@ -121,6 +121,8 @@ struct plantuml {
std::vector<std::string> before;
/*! List of directives to add before diagram */
std::vector<std::string> after;
/*! Command template to render diagram using PlantUML */
std::string cmd;
void append(const plantuml &r);
};
@@ -137,6 +139,8 @@ struct mermaid {
std::vector<std::string> before;
/*! List of directives to add before diagram */
std::vector<std::string> after;
/*! Command template to render diagram using MermaidJS */
std::string cmd;
void append(const mermaid &r);
};
@@ -448,6 +452,10 @@ struct source_location {
struct inheritable_diagram_options {
virtual ~inheritable_diagram_options() = default;
void inherit(const inheritable_diagram_options &parent);
std::string simplify_template_type(std::string full_name) const;
option<std::vector<std::string>> glob{"glob"};
option<common::model::namespace_> using_namespace{"using_namespace"};
option<bool> include_relations_also_as_members{
@@ -494,10 +502,6 @@ struct inheritable_diagram_options {
"message_comment_width", clanguml::util::kDefaultMessageCommentWidth};
option<bool> debug_mode{"debug_mode", false};
option<bool> generate_metadata{"generate_metadata", true};
void inherit(const inheritable_diagram_options &parent);
std::string simplify_template_type(std::string full_name) const;
};
/**
@@ -648,6 +652,8 @@ struct config : public inheritable_diagram_options {
* Initialize predefined diagram templates.
*/
void initialize_diagram_templates();
void inherit();
};
/**
@@ -659,6 +665,7 @@ struct config : public inheritable_diagram_options {
* @embed{load_config_sequence.svg}
*
* @param config_file Path to the configuration file
* @param inherit If true, common options will be propagated to diagram configs
* @param paths_relative_to_pwd Whether the paths in the configuration file
* should be relative to the parent directory of
* the configuration file or to the current
@@ -667,7 +674,7 @@ struct config : public inheritable_diagram_options {
* @param validate If true, perform schema validation
* @return Configuration instance
*/
config load(const std::string &config_file,
config load(const std::string &config_file, bool inherit = true,
std::optional<bool> paths_relative_to_pwd = {},
std::optional<bool> no_metadata = {}, bool validate = true);

View File

@@ -24,6 +24,7 @@ namespace clanguml {
namespace config {
template <typename T> void append_value(T &l, const T &r) { l = r; }
/**
* Possible option inheritance methods from top level to diagram level.
*/

View File

@@ -157,9 +157,11 @@ types:
plantuml: !optional
before: !optional [string]
after: !optional [string]
cmd: !optional string
mermaid: !optional
before: !optional [string]
after: !optional [string]
cmd: !optional string
relative_to: !optional string
using_namespace: !optional [string, [string]]
generate_metadata: !optional bool
@@ -194,9 +196,11 @@ types:
plantuml: !optional
before: !optional [string]
after: !optional [string]
cmd: !optional string
mermaid: !optional
before: !optional [string]
after: !optional [string]
cmd: !optional string
relative_to: !optional string
using_namespace: !optional [string, [string]]
generate_metadata: !optional bool
@@ -231,9 +235,11 @@ types:
plantuml: !optional
before: !optional [string]
after: !optional [string]
cmd: !optional string
mermaid: !optional
before: !optional [string]
after: !optional [string]
cmd: !optional string
relative_to: !optional string
using_namespace: !optional [string, [string]]
generate_metadata: !optional bool
@@ -260,9 +266,11 @@ types:
plantuml: !optional
before: !optional [string]
after: !optional [string]
cmd: !optional string
mermaid: !optional
before: !optional [string]
after: !optional [string]
cmd: !optional string
relative_to: !optional string
using_namespace: !optional [string, [string]]
generate_metadata: !optional bool
@@ -306,9 +314,11 @@ root:
plantuml: !optional
before: !optional [string]
after: !optional [string]
cmd: !optional string
mermaid: !optional
before: !optional [string]
after: !optional [string]
cmd: !optional string
relative_to: !optional string
using_namespace: !optional [string, [string]]
generate_metadata: !optional bool

View File

@@ -387,6 +387,10 @@ template <> struct convert<plantuml> {
if (node["after"])
rhs.after = node["after"].as<decltype(rhs.after)>();
if (node["cmd"])
rhs.cmd = node["cmd"].as<decltype(rhs.cmd)>();
return true;
}
};
@@ -399,6 +403,10 @@ template <> struct convert<mermaid> {
if (node["after"])
rhs.after = node["after"].as<decltype(rhs.after)>();
if (node["cmd"])
rhs.cmd = node["cmd"].as<decltype(rhs.cmd)>();
return true;
}
};
@@ -831,7 +839,6 @@ template <> struct convert<config> {
diagram_config = parse_diagram_config(d.second);
if (diagram_config) {
diagram_config->name = name;
diagram_config->inherit(rhs);
rhs.diagrams[name] = diagram_config;
}
else {
@@ -860,6 +867,13 @@ void config::initialize_diagram_templates()
predefined_templates.as<std::map<std::string, diagram_template>>());
}
void config::inherit()
{
for (auto &[name, diagram] : diagrams) {
diagram->inherit(*this);
}
}
namespace {
void resolve_option_path(YAML::Node &doc, const std::string &option)
{
@@ -881,7 +895,7 @@ void resolve_option_path(YAML::Node &doc, const std::string &option)
}
} // namespace
config load(const std::string &config_file,
config load(const std::string &config_file, bool inherit,
std::optional<bool> paths_relative_to_pwd, std::optional<bool> no_metadata,
bool validate)
{
@@ -997,6 +1011,9 @@ config load(const std::string &config_file,
auto d = doc.as<config>();
if (inherit)
d.inherit();
d.initialize_diagram_templates();
return d;