render static method
Renders a Pug template string with optional data and options.
template is the Pug template source code.
data is a Map containing template variables (optional).
options is a Map containing Pug options (optional).
Returns the rendered HTML as a String.
Throws PugServerException for Pug compilation/rendering errors.
Example:
final html = await PugServer.render(
'h1= title\np Welcome to #{name}!',
{'title': 'My Site', 'name': 'Dart'}
);
Implementation
static Future<String> render(
String template, [
Map<String, dynamic>? data,
Map<String, dynamic>? options,
]) async {
await _ensureServerRunning();
final request = {
'action': 'render',
'template': template,
'data': data,
'options': options,
};
final response = await _sendRequest(request);
if (response['success'] == true) {
return response['result'] as String;
} else {
throw PugServerException('Pug render error: ${response['error']}');
}
}