renderFile static method

Future<String> renderFile(
  1. File file, [
  2. Map<String, dynamic>? data,
  3. Map<String, dynamic>? options
])

Renders a Pug template file with optional data and options.

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 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/index.pug');
final html = await PugServer.renderFile(
  templateFile,
  {'title': 'My Site', 'users': ['Alice', 'Bob']}
);

Implementation

static Future<String> renderFile(
  File file, [
  Map<String, dynamic>? data,
  Map<String, dynamic>? options,
]) async {
  await _ensureServerRunning();

  final request = {
    'action': 'renderFile',
    '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);
  }
}