compile static method
Compiles and renders a Pug template string in one step.
template is the Pug template source code.
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 PugServerException for Pug compilation/rendering errors.
Example:
final html = await PugServer.compile(
'h1= title\np= message',
{'title': 'Hello', 'message': 'World'}
);
Implementation
static Future<String> compile(
String template, [
Map<String, dynamic>? data,
Map<String, dynamic>? options,
]) async {
await _ensureServerRunning();
final request = {
'action': 'compile',
'template': template,
'data': data,
'options': options,
};
final response = await _sendRequest(request);
if (response['success'] == true) {
return response['result'] as String;
} else {
throw PugServerException('Pug compile error: ${response['error']}');
}
}