1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185 | #pragma once
#include "doxide.hpp"
#include "Entity.hpp"
/**
* Markdown generator.
*
* @ingroup developer
*/
class MarkdownGenerator {
public:
/**
* Constructor.
*
* @param output Output directory.
*/
MarkdownGenerator(const std::filesystem::path& output);
/**
* Generate documentation.
*
* @param root Root entity.
*/
void generate(const Entity& root);
/**
* Generate coverage.
*
* @param root Root entity.
*/
void coverage(const Entity& root);
/**
* Clean up after generation, removing files from old runs. Traverses the
* output directory, removing any Markdown files with 'generator: doxide' in
* their YAML frontmatter that were not generated by previous calls of
* `generate()`.
*/
void clean();
private:
/**
* Recursively generate documentation.
*
* @param output Output directory.
* @param entity Entity for which to generate documentation.
*/
void generate(const std::filesystem::path& output, const Entity& entity);
/**
* Recursively generate coverage.
*
* @param output Output directory.
* @param entity Entity for which to generate coverage.
*/
void coverage(const std::filesystem::path& output, const Entity& entity);
/**
* Recursively generate coverage table data.
*
* @param entity Entity for which to generate coverage.
* @param root Root entity for the current page. This is used to determine
* which are rows should be visible initially.
* @param out Output stream.
*/
static void coverage_data(const Entity& entity, const Entity& root,
std::ofstream& out);
/**
* Recursively generate coverage table footer.
*
* @param entity Entity for which to generate coverage.
* @param root Root entity for the current page. This is used to determine
* which are rows should be visible initially.
* @param out Output stream.
*/
static void coverage_foot(const Entity& entity, const Entity& root,
std::ofstream& out);
/**
* Produce sunburst chart of code coverage for entity.
*
* @param entity Entity for which to generate sunburst.
* @param root Root entity for the current page. This is used to determine
* paths relative to the root.
* @param out Output stream.
*/
static void sunburst(const Entity& entity, const Entity& root,
std::ofstream& out);
/**
* Produce data for sunburst chart of code coverage for entity.
*
* @param entity Entity for which to generate sunburst.
* @param root Root entity for the current page. This is used to determine
* paths relative to the root.
* @param out Output stream.
*/
static void sunburst_data(const Entity& entity, const Entity& root,
std::ofstream& out);
/**
* Produce a relative path.
*/
static std::string relative(const std::filesystem::path& path,
const std::filesystem::path& base);
/**
* Can the file be written? To be overwritten, the file must either not
* exist, or exists but has 'generator: doxide' in its YAML frontmatter.
*/
static bool can_write(const std::filesystem::path& path);
/**
* Produce the YAML frontmatter for an entity.
*/
static std::string frontmatter(const Entity& entity);
/**
* Produce title for an entity.
*/
static std::string title(const Entity& entity);
/**
* Produce brief description for an entity.
*/
static std::string brief(const Entity& entity);
/**
* Reduce to a single line.
*/
static std::string line(const std::string& str);
/**
* Indent lines.
*/
static std::string indent(const std::string& str);
/**
* Sanitize for a string, escaping double quotes and backslashes.
*/
static std::string stringify(const std::string& str);
/**
* Sanitize for HTML, replacing special characters with entities. Also
* replaces some characters that might trigger Markdown formatting.
*/
static std::string htmlize(const std::string& str);
/**
* Sanitize for a file name or internal anchor.
*/
static std::string sanitize(const std::string& str);
/**
* Lookup color for given percentage.
*/
static const std::string& color(const double percent);
/**
* Lookup icon for given percentage.
*/
static const std::string& icon(const double percent);
/**
* Convert a list of entities to a list of pointers to entities, optionally
* sorting by name.
*
* @param entities List of entities.
* @param sort Sort by name?
*/
static std::list<const Entity*> view(const std::list<Entity>& entities,
const bool sort);
/**
* Output directory.
*/
std::filesystem::path output;
/**
* Set of files generated during the last call to generate().
*/
std::unordered_set<std::filesystem::path> files;
};
|