0.6.0
C++ to UML diagram generator based on Clang
Loading...
Searching...
No Matches
jinja_context.cc
Go to the documentation of this file.
1/**
2 * @file src/class_diagram/model/jinja_context.cc
3 *
4 * Copyright (c) 2021-2025 Bartek Kryza <bkryza@gmail.com>
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#include "jinja_context.h"
20
22
24
26
27using namespace clanguml::common::model;
28
29void to_json(inja::json &ctx,
31{
32 to_json(ctx, d.as<decorated_element>());
33
34 ctx["element"]["name"] = display_name_adapter(d.get()).name();
35 ctx["element"]["type"] = display_name_adapter(d.get()).type();
36 ctx["element"]["access"] = to_string(d.get().access());
37
38 if (d.diagram_context().contains("git")) {
39 ctx["git"] = d.diagram_context()["git"];
40 }
41
42 if (d.diagram_context().contains("user_data")) {
43 ctx["user_data"] = d.diagram_context()["user_data"];
44 }
45
46 to_json(ctx, d.as<source_location>());
47}
48
50 inja::json &ctx, const diagram_context<class_diagram::model::diagram> &d)
51{
52 using namespace class_diagram::model;
53
54 ctx["name"] = d.get().name();
55 ctx["type"] = "class";
56
57 inja::json::array_t elements{};
58
59 d.get().view<class_>().for_each([&](auto &&e) mutable {
60 elements.emplace_back(diagram_context<element>(e));
61 });
62
63 d.get().view<enum_>().for_each([&](auto &&e) mutable {
64 elements.emplace_back(diagram_context<element>(e));
65 });
66
67 d.get().view<concept_>().for_each([&](auto &&e) mutable {
68 elements.emplace_back(diagram_context<element>(e));
69 });
70
71 d.get().view<objc_interface>().for_each([&](auto &&e) mutable {
72 elements.emplace_back(diagram_context<element>(e));
73 });
74
75 ctx["elements"] = elements;
76}
77} // namespace clanguml::common::jinja