@@ -143,6 +143,29 @@ Builder(
143
143
helpers::registerAntoraHelpers (hbs_);
144
144
helpers::registerLogicalHelpers (hbs_);
145
145
helpers::registerContainerHelpers (hbs_);
146
+
147
+ // load templates
148
+ exp = forEachFile (layoutDir (), false ,
149
+ [&](std::string_view pathName) -> Expected<void >
150
+ {
151
+ // Get template relative path
152
+ std::filesystem::path relPath = pathName;
153
+ relPath = relPath.lexically_relative (layoutDir ());
154
+
155
+ // Skip non-handlebars files
156
+ MRDOCS_CHECK_OR (relPath.extension () == " .hbs" , {});
157
+
158
+ // Load template contents
159
+ MRDOCS_TRY (std::string text, files::getFileText (pathName));
160
+
161
+ // Register template
162
+ this ->templates_ .emplace (relPath.generic_string (), text);
163
+ return {};
164
+ });
165
+ if (!exp )
166
+ {
167
+ exp .error ().Throw ();
168
+ }
146
169
}
147
170
148
171
// ------------------------------------------------
@@ -154,8 +177,9 @@ callTemplate(
154
177
std::string_view name,
155
178
dom::Value const & context)
156
179
{
157
- auto pathName = files::appendPath (layoutDir (), name);
158
- MRDOCS_TRY (auto fileText, files::getFileText (pathName));
180
+ auto it = templates_.find (name);
181
+ MRDOCS_CHECK (it != templates_.end (), formatError (" Template {} not found" , name));
182
+ std::string_view fileText = it->second ;
159
183
HandlebarsOptions options;
160
184
options.escapeFunction = escapeFn_;
161
185
OutputRef out (os);
0 commit comments