platform/lib/angel_mustache.dart
regiostech 2be4f7c77b Done
2016-04-21 22:22:33 -04:00

19 lines
No EOL
673 B
Dart

library angel_mustache;
import 'dart:io';
import 'package:angel_framework/angel_framework.dart';
import 'package:mustache4dart/mustache4dart.dart' show render;
mustache(Directory viewsDirectory, {String fileExtension: '.mustache'}) {
return (Angel app) {
app.viewGenerator = (String name, [Map data]) async {
String viewPath = name + fileExtension;
File viewFile = new File.fromUri(
viewsDirectory.absolute.uri.resolve(viewPath));
if (await viewFile.exists()) {
return render(await viewFile.readAsString(), data ?? {});
} else throw new FileSystemException(
'View "$name" was not found.', viewPath);
};
};
}