Skip to content

Commit 9bbbefa

Browse files
committed
refactor: build generators from data (don't use subclasses)
This moves `id`, `fileExtension`, and `displayName` from per-subclass virtual overrides to base-class members set through the constructor. That's a prerequisite for letting users add a Handlebars-based generator without writing C++.
1 parent 7cd6618 commit 9bbbefa

4 files changed

Lines changed: 16 additions & 38 deletions

File tree

src/lib/Gen/adoc/AdocGenerator.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,17 @@
1111

1212
#include "AdocGenerator.hpp"
1313
#include "AdocEscape.hpp"
14-
#include <mrdocs/Support/Handlebars.hpp>
14+
#include <memory>
1515

1616
namespace mrdocs {
1717
namespace adoc {
1818

19+
AdocGenerator::
20+
AdocGenerator()
21+
: HandlebarsGenerator("adoc", "adoc", "Asciidoc")
22+
{
23+
}
24+
1925
void
2026
AdocGenerator::
2127
escape(OutputRef& os, std::string_view const str) const

src/lib/Gen/adoc/AdocGenerator.hpp

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,15 @@
1313
#ifndef MRDOCS_LIB_GEN_ADOC_ADOCGENERATOR_HPP
1414
#define MRDOCS_LIB_GEN_ADOC_ADOCGENERATOR_HPP
1515

16-
#include <mrdocs/Platform.hpp>
1716
#include <lib/Gen/hbs/HandlebarsGenerator.hpp>
18-
#include <mrdocs/Generator.hpp>
1917

2018
namespace mrdocs::adoc {
2119

2220
class AdocGenerator final
2321
: public hbs::HandlebarsGenerator
2422
{
2523
public:
26-
std::string_view
27-
id() const noexcept override
28-
{
29-
return "adoc";
30-
}
31-
32-
std::string_view
33-
fileExtension() const noexcept override
34-
{
35-
return "adoc";
36-
}
37-
38-
39-
std::string_view
40-
displayName() const noexcept override
41-
{
42-
return "Asciidoc";
43-
}
24+
AdocGenerator();
4425

4526
void
4627
escape(OutputRef& os, std::string_view str) const override;

src/lib/Gen/html/HTMLGenerator.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,17 @@
1111

1212
#include "HTMLGenerator.hpp"
1313
#include <mrdocs/Support/Handlebars.hpp>
14+
#include <memory>
1415

1516
namespace mrdocs {
1617
namespace html {
1718

19+
HTMLGenerator::
20+
HTMLGenerator()
21+
: HandlebarsGenerator("html", "html", "HTML")
22+
{
23+
}
24+
1825
void
1926
HTMLGenerator::
2027
escape(OutputRef& os, std::string_view str) const

src/lib/Gen/html/HTMLGenerator.hpp

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,7 @@ class HTMLGenerator final
2323
: public hbs::HandlebarsGenerator
2424
{
2525
public:
26-
std::string_view
27-
id() const noexcept override
28-
{
29-
return "html";
30-
}
31-
32-
std::string_view
33-
fileExtension() const noexcept override
34-
{
35-
return "html";
36-
}
37-
38-
std::string_view
39-
displayName() const noexcept override
40-
{
41-
return "HTML";
42-
}
26+
HTMLGenerator();
4327

4428
void
4529
escape(OutputRef& os, std::string_view str) const override;

0 commit comments

Comments
 (0)