@@ -43,12 +43,6 @@ createExecutors(
43
43
return group;
44
44
}
45
45
46
- // ------------------------------------------------
47
- //
48
- // HandlebarsGenerator
49
- //
50
- // ------------------------------------------------
51
-
52
46
/* * Return loaded Options from a configuration.
53
47
*/
54
48
Options
@@ -79,6 +73,27 @@ loadOptions(
79
73
return opt;
80
74
}
81
75
76
+ HandlebarsCorpus
77
+ createDomCorpus (
78
+ HandlebarsGenerator const & gen,
79
+ Corpus const & corpus)
80
+ {
81
+ auto options = loadOptions (gen.fileExtension (), corpus.config );
82
+ return {
83
+ corpus,
84
+ std::move (options),
85
+ gen.fileExtension (),
86
+ [&gen](HandlebarsCorpus const & c, doc::Node const & n) {
87
+ return gen.toString (c, n);
88
+ }};
89
+ }
90
+
91
+ // ------------------------------------------------
92
+ //
93
+ // HandlebarsGenerator
94
+ //
95
+ // ------------------------------------------------
96
+
82
97
Error
83
98
HandlebarsGenerator::
84
99
build (
@@ -90,28 +105,18 @@ build(
90
105
return Generator::build (outputPath, corpus);
91
106
}
92
107
93
- Options options = loadOptions (fileExtension (), corpus.config );
94
- HandlebarsCorpus domCorpus (
95
- corpus,
96
- std::move (options),
97
- fileExtension (),
98
- [this ](HandlebarsCorpus const & c, doc::Node const & n) {
99
- return this ->toString (c, n);
100
- });
108
+ // Create corpus and executors
109
+ HandlebarsCorpus domCorpus = createDomCorpus (*this , corpus);
101
110
auto ex = createExecutors (domCorpus);
102
- if (!ex)
103
- {
104
- return ex.error ();
105
- }
111
+ MRDOCS_CHECK_OR (ex, ex.error ());
106
112
113
+ // Visit the corpus
107
114
MultiPageVisitor visitor (*ex, outputPath, corpus);
108
115
visitor (corpus.globalNamespace ());
109
116
117
+ // Wait for all executors to finish and check errors
110
118
auto errors = ex->wait ();
111
- if (!errors.empty ())
112
- {
113
- return Error (errors);
114
- }
119
+ MRDOCS_CHECK_OR (errors.empty (), errors);
115
120
return Error::success ();
116
121
}
117
122
@@ -121,47 +126,35 @@ buildOne(
121
126
std::ostream& os,
122
127
Corpus const & corpus) const
123
128
{
124
- auto options = loadOptions (fileExtension (), corpus.config );
125
-
126
- HandlebarsCorpus domCorpus (
127
- corpus,
128
- std::move (options),
129
- fileExtension (),
130
- [this ](HandlebarsCorpus const & c, doc::Node const & n) {
131
- return this ->toString (c, n);
132
- });
129
+ // Create corpus and executors
130
+ HandlebarsCorpus domCorpus = createDomCorpus (*this , corpus);
133
131
auto ex = createExecutors (domCorpus);
134
- if (!ex)
135
- {
136
- return ex.error ();
137
- }
132
+ MRDOCS_CHECK_OR (ex, ex.error ());
138
133
134
+ // Render the header
139
135
std::vector<Error> errors;
140
- ex->async (
141
- [&os](Builder& builder)
142
- {
143
- auto pageText = builder.renderSinglePageHeader ().value ();
144
- os.write (pageText.data (), pageText.size ());
145
- });
136
+ ex->async ([&os](Builder& builder) {
137
+ auto pageText = builder.renderSinglePageHeader ().value ();
138
+ os.write (pageText.data (), pageText.size ());
139
+ });
146
140
errors = ex->wait ();
147
- if (! errors.empty ())
148
- return {errors};
141
+ MRDOCS_CHECK_OR (errors.empty (), {errors});
149
142
143
+ // Visit the corpus
150
144
SinglePageVisitor visitor (*ex, corpus, os);
151
145
visitor (corpus.globalNamespace ());
146
+
147
+ // Wait for all executors to finish and check errors
152
148
errors = ex->wait ();
153
- if (! errors.empty ())
154
- return {errors};
149
+ MRDOCS_CHECK_OR (errors.empty (), errors);
155
150
156
- ex->async (
157
- [&os](Builder& builder)
158
- {
159
- auto pageText = builder.renderSinglePageFooter ().value ();
160
- os.write (pageText.data (), pageText.size ());
161
- });
151
+ // Render the footer
152
+ ex->async ([&os](Builder& builder) {
153
+ auto pageText = builder.renderSinglePageFooter ().value ();
154
+ os.write (pageText.data (), pageText.size ());
155
+ });
162
156
errors = ex->wait ();
163
- if (! errors.empty ())
164
- return {errors};
157
+ MRDOCS_CHECK_OR (errors.empty (), {errors});
165
158
166
159
return Error::success ();
167
160
}
0 commit comments