Added diagram templates to config
This commit is contained in:
@@ -50,6 +50,11 @@ struct plantuml {
|
||||
void append(const plantuml &r);
|
||||
};
|
||||
|
||||
struct diagram_template {
|
||||
common::model::diagram_t type;
|
||||
std::string jinja_template;
|
||||
};
|
||||
|
||||
struct filter {
|
||||
std::vector<common::model::namespace_> namespaces;
|
||||
|
||||
@@ -218,6 +223,9 @@ struct config : public inheritable_diagram_options {
|
||||
"compilation_database_dir", "."};
|
||||
option<std::string> output_directory{"output_directory"};
|
||||
|
||||
option<std::map<std::string, diagram_template>> diagram_templates{
|
||||
"diagram_templates"};
|
||||
|
||||
std::map<std::string, std::shared_ptr<diagram>> diagrams;
|
||||
};
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ using clanguml::common::model::access_t;
|
||||
using clanguml::common::model::relationship_t;
|
||||
using clanguml::config::class_diagram;
|
||||
using clanguml::config::config;
|
||||
using clanguml::config::diagram_template;
|
||||
using clanguml::config::filter;
|
||||
using clanguml::config::generate_links_config;
|
||||
using clanguml::config::git_config;
|
||||
@@ -101,6 +102,21 @@ void get_option<clanguml::config::comment_parser_t>(const Node &node,
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
void get_option<std::map<std::string, clanguml::config::diagram_template>>(
|
||||
const Node &node,
|
||||
clanguml::config::option<
|
||||
std::map<std::string, clanguml::config::diagram_template>> &option)
|
||||
{
|
||||
if (!node[option.name]) {
|
||||
return;
|
||||
}
|
||||
|
||||
option.set(
|
||||
node[option.name]
|
||||
.as<std::map<std::string, clanguml::config::diagram_template>>());
|
||||
}
|
||||
|
||||
std::shared_ptr<clanguml::config::diagram> parse_diagram_config(const Node &d)
|
||||
{
|
||||
const auto diagram_type = d["type"].as<std::string>();
|
||||
@@ -526,6 +542,31 @@ template <> struct convert<relationship_hint_t> {
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// diagram_template Yaml decoder
|
||||
//
|
||||
template <> struct convert<diagram_template> {
|
||||
static bool decode(const Node &node, diagram_template &rhs)
|
||||
{
|
||||
assert(node.Type() == NodeType::Map || node.Type() == NodeType::Scalar);
|
||||
|
||||
if (node.Type() == NodeType::Scalar) {
|
||||
// Check that the template provided as string is at least valid YAML
|
||||
const auto yaml_node = Load(node.as<std::string>());
|
||||
const auto diagram_type = yaml_node["type"].as<std::string>();
|
||||
rhs.type = clanguml::common::model::from_string(diagram_type);
|
||||
rhs.jinja_template = Dump(yaml_node);
|
||||
}
|
||||
else {
|
||||
const auto diagram_type = node["type"].as<std::string>();
|
||||
rhs.type = clanguml::common::model::from_string(diagram_type);
|
||||
rhs.jinja_template = Dump(node);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// config Yaml decoder
|
||||
//
|
||||
@@ -547,6 +588,8 @@ template <> struct convert<config> {
|
||||
rhs.base_directory.set(node["__parent_path"].as<std::string>());
|
||||
get_option(node, rhs.relative_to);
|
||||
|
||||
get_option(node, rhs.diagram_templates);
|
||||
|
||||
auto diagrams = node["diagrams"];
|
||||
|
||||
assert(diagrams.Type() == NodeType::Map);
|
||||
|
||||
Reference in New Issue
Block a user