Updated docs generation scripts

This commit is contained in:
Bartek Kryza
2023-09-10 00:03:47 +02:00
parent 2cc70bcd7e
commit 9a6def801c
6 changed files with 34 additions and 14 deletions

View File

@@ -103,10 +103,14 @@ document_test_cases: test_diagrams
python3 util/format_svg.py docs/test_cases/*.svg
clanguml_diagrams: debug
mkdir -p docs/diagrams
debug/src/clang-uml -g plantuml -g json -p
plantuml -tsvg -nometadata docs/diagrams/*.puml
python3 util/format_svg.py docs/diagrams/*.svg
mkdir -p docs/diagrams/plantuml
mkdir -p docs/diagrams/mermaid
debug/src/clang-uml -g plantuml -g json -g mermaid -p
# Convert .puml files to svg images
plantuml -tsvg -nometadata -o plantuml docs/diagrams/*.puml
# Convert .mmd files to svg images
python3 util/generate_mermaid.py docs/diagrams/*.mmd
python3 util/format_svg.py docs/diagrams/plantuml/*.svg
.PHONY: submodules
submodules:

View File

@@ -124,6 +124,10 @@ void generate_diagram_impl(const std::string &od, const std::string &name,
generate_diagram_select_generator<diagram_config,
json_generator_tag>(od, name, diagram, model);
}
else if (generator_type == generator_type_t::mermaid) {
generate_diagram_select_generator<diagram_config,
mermaid_generator_tag>(od, name, diagram, model);
}
}
}
} // namespace detail

View File

@@ -254,18 +254,24 @@ void generator<C, D>::generate_link(std::ostream &ostr, const E &e) const
ostr << indent(1) << "click " << e.alias() << " href \"";
try {
std::string link{};
if (!config.generate_links().link.empty()) {
ostr << env().render(std::string_view{config.generate_links().link},
link = env().render(std::string_view{config.generate_links().link},
element_context(e));
}
if (link.empty())
link = " ";
ostr << link;
}
catch (const inja::json::parse_error &e) {
LOG_ERROR(
"Failed to parse Jinja template: {}", config.generate_links().link);
ostr << " ";
}
catch (const inja::json::exception &e) {
LOG_ERROR("Failed to render PlantUML directive: \n{}\n due to: {}",
LOG_ERROR("Failed to render comment directive: \n{}\n due to: {}",
config.generate_links().link, e.what());
ostr << " ";
}
ostr << "\"";
@@ -281,10 +287,12 @@ void generator<C, D>::generate_link(std::ostream &ostr, const E &e) const
catch (const inja::json::parse_error &e) {
LOG_ERROR("Failed to parse Jinja template: {}",
config.generate_links().link);
ostr << " ";
}
catch (const inja::json::exception &e) {
LOG_ERROR("Failed to render PlantUML directive: \n{}\n due to: {}",
config.generate_links().link, e.what());
ostr << " ";
}
ostr << "\"";

View File

@@ -1,6 +1,6 @@
type: include
glob:
- src/**/*.cc
- src/config/*.cc
relative_to: .
include:
paths:

View File

@@ -38,8 +38,11 @@ ok = 0
for f in files:
try:
print(f'Generating Mermaid diagram from {f}')
f_svg = Path(f).with_suffix('.svg')
subprocess.check_call(['mmdc', '-i', f, '-o', f_svg])
f_svg = Path(f).with_suffix('.svg').name
target = Path(f).parent.absolute()
target = target.joinpath('mermaid')
target = target.joinpath(f_svg)
subprocess.check_call(['mmdc', '-i', f, '-o', target])
except subprocess.CalledProcessError:
ok = 1
print(f'ERROR: Generating Mermaid diagram from {f} failed')

View File

@@ -71,20 +71,21 @@ with open(r'tests/test_cases.yaml') as f:
config_dict = yaml.full_load(config)
tc.write("## Generated PlantUML diagrams\n")
for diagram_name, _ in config_dict['diagrams'].items():
copyfile(f'debug/tests/diagrams/puml/{diagram_name}.svg',
copyfile(f'debug/tests/diagrams/plantuml/{diagram_name}.svg',
f'docs/test_cases/{diagram_name}.svg')
tc.write(f'![{diagram_name}](./{diagram_name}.svg "{test_case["title"]}")\n')
tc.write("## Generated Mermaid diagrams\n")
for diagram_name, _ in config_dict['diagrams'].items():
copyfile(f'debug/tests/diagrams/mermaid/{diagram_name}.svg',
f'docs/test_cases/{diagram_name}_mmd.svg')
tc.write(f'![{diagram_name}](./{diagram_name}_mmd.svg "{test_case["title"]}")\n')
f'docs/test_cases/{diagram_name}_mermaid.svg')
tc.write(f'![{diagram_name}](./{diagram_name}_mermaid.svg "{test_case["title"]}")\n')
tc.write("## Generated JSON models\n")
for diagram_name, _ in config_dict['diagrams'].items():
if os.path.exists(f'debug/tests/puml/{diagram_name}.json'):
with open(f'debug/tests/puml/{diagram_name}.json') as f:
jd = f'debug/tests/diagrams/{diagram_name}.json'
if os.path.exists(jd):
with open(jd) as f:
contents = f.read()
tc.write("```json\n")
tc.write(contents)