@@ -38,18 +38,18 @@ loadPartials(
38
38
{
39
39
return ;
40
40
}
41
- forEachFile (partialsPath, true ,
42
- [&](std::string_view pathName) -> Error
41
+ auto exp = forEachFile (partialsPath, true ,
42
+ [&](std::string_view pathName) -> Expected< void >
43
43
{
44
44
// Skip directories
45
- MRDOCS_CHECK_OR (!files::isDirectory (pathName), Error::success () );
45
+ MRDOCS_CHECK_OR (!files::isDirectory (pathName), {} );
46
46
47
47
// Get template relative path
48
48
std::filesystem::path relPath = pathName;
49
49
relPath = relPath.lexically_relative (partialsPath);
50
50
51
51
// Skip non-handlebars files
52
- MRDOCS_CHECK_OR (relPath.extension () == " .hbs" , Error::success () );
52
+ MRDOCS_CHECK_OR (relPath.extension () == " .hbs" , {} );
53
53
54
54
// Remove any file extensions
55
55
while (relPath.has_extension ())
@@ -58,13 +58,16 @@ loadPartials(
58
58
}
59
59
60
60
// Load partial contents
61
- auto text = files::getFileText (pathName);
62
- MRDOCS_CHECK_OR (text, text.error ());
61
+ MRDOCS_TRY (std::string text, files::getFileText (pathName));
63
62
64
63
// Register partial
65
- hbs.registerPartial (relPath.generic_string (), *text);
66
- return Error::success ();
67
- }).maybeThrow ();
64
+ hbs.registerPartial (relPath.generic_string (), text);
65
+ return {};
66
+ });
67
+ if (!exp )
68
+ {
69
+ exp .error ().Throw ();
70
+ }
68
71
}
69
72
}
70
73
@@ -81,7 +84,7 @@ Builder(
81
84
82
85
// Load JavaScript helpers
83
86
std::string helpersPath = templatesDir (" helpers" );
84
- forEachFile (helpersPath, true ,
87
+ auto exp = forEachFile (helpersPath, true ,
85
88
[&](std::string_view pathName)-> Expected<void >
86
89
{
87
90
// Register JS helper function in the global object
@@ -92,7 +95,11 @@ Builder(
92
95
MRDOCS_TRY (auto script, files::getFileText (pathName));
93
96
MRDOCS_TRY (js::registerHelper (hbs_, name, ctx_, script));
94
97
return {};
95
- }).maybeThrow ();
98
+ });
99
+ if (!exp )
100
+ {
101
+ exp .error ().Throw ();
102
+ }
96
103
97
104
hbs_.registerHelper (" primary_location" ,
98
105
dom::makeInvocable ([](dom::Value const & v) ->
@@ -260,19 +267,17 @@ operator()(OverloadSet const& OS)
260
267
261
268
Expected<void >
262
269
Builder::
263
- renderWrapped (std::ostream& os, std::function<Error()> contentsCb)
270
+ renderWrapped (
271
+ std::ostream& os,
272
+ std::function<Expected<void >()> contentsCb)
264
273
{
265
274
auto const wrapperFile = fmt::format (
266
275
" wrapper.{}.hbs" , domCorpus.fileExtension );
267
276
dom::Object ctx;
268
277
ctx.set (" contents" , dom::makeInvocable ([&](
269
278
dom::Value const & options) -> Expected<dom::Value>
270
279
{
271
- Error e = contentsCb ();
272
- if (e.failed ())
273
- {
274
- return Unexpected (e);
275
- }
280
+ MRDOCS_TRY (contentsCb ());
276
281
return {};
277
282
}));
278
283
0 commit comments