Skip to content

Commit 5f9e5a1

Browse files
committed
refactor(HandlebarsGenerator): remove unused options
1 parent 5209438 commit 5f9e5a1

8 files changed

+49
-113
lines changed

docs/mrdocs.schema.json

+6
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@
168168
"title": "Include files to extract",
169169
"type": "object"
170170
},
171+
"legible-names": {
172+
"default": true,
173+
"description": "Use legible names for ids in the documentation. When set to true, MrDocs uses legible names for symbols in the documentation. These are symbols that are legible but still safe for URLs. When the option is set to false, MrDocs uses a hash of the symbol ID.",
174+
"title": "Use legible names",
175+
"type": "boolean"
176+
},
171177
"multipage": {
172178
"default": true,
173179
"description": "Generates a multipage documentation. The output directory must be a directory. This option acts as a hint to the generator to create a multipage documentation. Whether the hint is followed or not depends on the generator.",

src/lib/Gen/hbs/Builder.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,10 @@ std::string
170170
Builder::
171171
getRelPrefix(std::size_t depth)
172172
{
173+
Config const& config = domCorpus->config;
174+
173175
std::string rel_prefix;
174-
if(! depth || ! domCorpus.options.legible_names ||
176+
if(! depth || ! config->legibleNames ||
175177
! domCorpus->config->multipage)
176178
return rel_prefix;
177179
--depth;
@@ -208,6 +210,7 @@ createContext(
208210
const Info& Parent = domCorpus->get(OS.Parent);
209211
props.emplace_back("relfileprefix",
210212
getRelPrefix(Parent.Namespace.size() + 1));
213+
props.emplace_back("config", domCorpus->config.object());
211214
props.emplace_back("sectionref",
212215
domCorpus.names_.getQualified(OS, '-'));
213216
return dom::Object(std::move(props));
@@ -232,6 +235,7 @@ operator()(OverloadSet const& OS)
232235
createContext(OS));
233236
}
234237

238+
// Define Builder::operator() for each Info type
235239
#define DEFINE(T) template Expected<std::string> \
236240
Builder::operator()<T>(T const&)
237241

src/lib/Gen/hbs/Builder.hpp

+28-17
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#ifndef MRDOCS_LIB_GEN_HBS_BUILDER_HPP
1313
#define MRDOCS_LIB_GEN_HBS_BUILDER_HPP
1414

15-
#include "Options.hpp"
1615
#include "HandlebarsCorpus.hpp"
1716
#include "lib/Support/Radix.hpp"
1817
#include <mrdocs/Metadata/DomCorpus.hpp>
@@ -25,7 +24,7 @@ namespace clang {
2524
namespace mrdocs {
2625
namespace hbs {
2726

28-
/** Builds reference output.
27+
/** Builds reference output as a string for any Info type
2928
3029
This contains all the state information
3130
for a single thread to generate output.
@@ -35,24 +34,25 @@ class Builder
3534
js::Context ctx_;
3635
Handlebars hbs_;
3736

38-
std::string getRelPrefix(std::size_t depth);
37+
std::string
38+
getRelPrefix(std::size_t depth);
3939

4040
public:
4141
HandlebarsCorpus const& domCorpus;
4242

4343
explicit
44-
Builder(
45-
HandlebarsCorpus const& corpus);
44+
Builder(HandlebarsCorpus const& corpus);
4645

47-
dom::Value createContext(Info const& I);
48-
dom::Value createContext(OverloadSet const& OS);
46+
/** Render the contents for a symbol.
47+
*/
48+
template<class T>
49+
Expected<std::string>
50+
operator()(T const&);
4951

50-
/** Render a Handlebars template from the templates directory.
52+
/** Render the contents for an overload set.
5153
*/
5254
Expected<std::string>
53-
callTemplate(
54-
std::string_view name,
55-
dom::Value const& context);
55+
operator()(OverloadSet const&);
5656

5757
/** Render the header for a single page.
5858
*/
@@ -64,16 +64,27 @@ class Builder
6464
Expected<std::string>
6565
renderSinglePageFooter();
6666

67-
/** Render the contents for a symbol.
67+
private:
68+
/** Create a handlebars context with the symbol and helper information.
69+
70+
The helper information includes all information from the
71+
config file, plus the symbol information.
72+
73+
It also includes a sectionref helper that describes
74+
the section where the symbol is located.
6875
*/
69-
template<class T>
70-
Expected<std::string>
71-
operator()(T const&);
76+
dom::Value createContext(Info const& I);
7277

73-
/** Render the contents for an overload set.
78+
/// @copydoc createContext(Info const&)
79+
dom::Value createContext(OverloadSet const& OS);
80+
81+
/** Render a Handlebars template from the templates directory.
7482
*/
7583
Expected<std::string>
76-
operator()(OverloadSet const&);
84+
callTemplate(
85+
std::string_view name,
86+
dom::Value const& context);
87+
7788
};
7889

7990
} // hbs

src/lib/Gen/hbs/HandlebarsCorpus.hpp

+3-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#include <mrdocs/Platform.hpp>
1616
#include "lib/Support/LegibleNames.hpp"
17-
#include "Options.hpp"
1817
#include <mrdocs/Metadata/DomCorpus.hpp>
1918
#include <optional>
2019

@@ -32,9 +31,6 @@ namespace hbs {
3231
class HandlebarsCorpus : public DomCorpus
3332
{
3433
public:
35-
/** Options for the Handlebars corpus. */
36-
Options options;
37-
3834
/** Legible names for the Handlebars corpus. */
3935
LegibleNames names_;
4036

@@ -49,16 +45,15 @@ class HandlebarsCorpus : public DomCorpus
4945
Initializes the HandlebarsCorpus with the given corpus and options.
5046
5147
@param corpus The base corpus.
52-
@param opts Options for the Handlebars corpus.
48+
@param fileExtension The file extension for the generated files.
49+
@param toStringFn The function to convert a Javadoc node to a string.
5350
*/
5451
HandlebarsCorpus(
5552
Corpus const& corpus,
56-
Options&& opts,
5753
std::string_view fileExtension,
5854
std::function<std::string(HandlebarsCorpus const&, doc::Node const&)> toStringFn)
5955
: DomCorpus(corpus)
60-
, options(std::move(opts))
61-
, names_(corpus, options.legible_names)
56+
, names_(corpus, corpus.config->legibleNames)
6257
, fileExtension(fileExtension)
6358
, toStringFn(std::move(toStringFn))
6459
{

src/lib/Gen/hbs/HandlebarsGenerator.cpp

-33
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "HandlebarsGenerator.hpp"
1414
#include "HandlebarsCorpus.hpp"
1515
#include "Builder.hpp"
16-
#include "Options.hpp"
1716
#include "MultiPageVisitor.hpp"
1817
#include "SinglePageVisitor.hpp"
1918
#include <mrdocs/Support/Path.hpp>
@@ -43,45 +42,13 @@ createExecutors(
4342
return group;
4443
}
4544

46-
/** Return loaded Options from a configuration.
47-
*/
48-
Options
49-
loadOptions(
50-
std::string_view fileExtension,
51-
Config const& config)
52-
{
53-
Options opt;
54-
dom::Value domOpts = config.object().get("generator").get(fileExtension);
55-
if (domOpts.get("legible-names").isBoolean())
56-
{
57-
opt.legible_names = domOpts.get("legible-names").getBool();
58-
}
59-
if (domOpts.get("template-dir").isString())
60-
{
61-
opt.template_dir = domOpts.get("template-dir").getString();
62-
opt.template_dir = files::makeAbsolute(
63-
opt.template_dir,
64-
config->configDir);
65-
}
66-
else
67-
{
68-
opt.template_dir = files::appendPath(
69-
config->addons,
70-
"generator",
71-
fileExtension);
72-
}
73-
return opt;
74-
}
75-
7645
HandlebarsCorpus
7746
createDomCorpus(
7847
HandlebarsGenerator const& gen,
7948
Corpus const& corpus)
8049
{
81-
auto options = loadOptions(gen.fileExtension(), corpus.config);
8250
return {
8351
corpus,
84-
std::move(options),
8552
gen.fileExtension(),
8653
[&gen](HandlebarsCorpus const& c, doc::Node const& n) {
8754
return gen.toString(c, n);

src/lib/Gen/hbs/HandlebarsGenerator.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <mrdocs/Platform.hpp>
1616
#include <mrdocs/Generator.hpp>
1717
#include <mrdocs/Metadata/DomCorpus.hpp>
18-
#include <lib/Gen/hbs/Options.hpp>
1918
#include <lib/Gen/hbs/HandlebarsCorpus.hpp>
2019
#include <utility>
2120

src/lib/Gen/hbs/Options.hpp

-53
This file was deleted.

src/lib/Lib/ConfigOptions.json

+7
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@
147147
"type": "path",
148148
"default": "<mrdocs-root>/share/mrdocs/addons",
149149
"relativeto": "<config-dir>"
150+
},
151+
{
152+
"name": "legible-names",
153+
"brief": "Use legible names",
154+
"details": "Use legible names for ids in the documentation. When set to true, MrDocs uses legible names for symbols in the documentation. These are symbols that are legible but still safe for URLs. When the option is set to false, MrDocs uses a hash of the symbol ID.",
155+
"type": "bool",
156+
"default": true
150157
}
151158
]
152159
},

0 commit comments

Comments
 (0)