compileFile static method
Compiles and renders a Pug template file in one step.
file is the File object pointing to the Pug template file.
data is a Map containing template variables (optional).
options is a Map containing Pug compilation options (optional).
Returns the rendered HTML as a String.
Throws FileSystemException if the template file is not found. Throws PugServerException for Pug compilation/rendering errors.
Example:
final templateFile = File('templates/layout.pug');
final html = await PugServer.compileFile(
templateFile,
{'title': 'My Page', 'content': 'Hello World'}
);
Implementation
static Future<String> compileFile(
File file, [
Map<String, dynamic>? data,
Map<String, dynamic>? options,
]) async {
await _ensureServerRunning();
final request = {
'action': 'compileFile',
'filename': file.absolute.path,
'data': data,
'options': options,
};
final response = await _sendRequest(request);
if (response['success'] == true) {
return response['result'] as String;
} else {
_throwAppropriateException(response, file.path);
}
}