import 'dart:convert'; import 'package:angel_framework/angel_framework.dart'; import 'package:code_buffer/code_buffer.dart'; import 'package:file/file.dart'; import 'package:jael/jael.dart'; import 'package:jael_preprocessor/jael_preprocessor.dart'; import 'package:symbol_table/symbol_table.dart'; AngelConfigurer jael(Directory viewsDirectory, {String fileExtension, CodeBuffer createBuffer()}) { fileExtension ??= '.jl'; createBuffer ??= () => new CodeBuffer(); return (Angel app) async { app.viewGenerator = (String name, [Map locals]) async { var file = viewsDirectory.childFile(name + fileExtension); var contents = await file.readAsString(); var errors = []; var doc = parseDocument(contents, sourceUrl: file.uri, onError: errors.add); var processed = doc; try { processed = await resolve(doc, viewsDirectory, onError: errors.add); } catch (_) { // Ignore these errors, so that we can show syntax errors. } var buf = createBuffer(); var scope = new SymbolTable(values: locals ?? {}); if (errors.isEmpty) { try { const Renderer().render(processed, buf, scope); return buf.toString(); } on JaelError catch (e) { errors.add(e); } } buf ..writeln('') ..writeln('') ..indent() ..writeln('') ..indent() ..writeln( '', ) ..writeln('${errors.length} Error(s)') ..outdent() ..writeln('') ..writeln('') ..writeln('

${errors.length} Error(s)

') ..writeln('') ..writeln('') ..writeln(''); return buf.toString(); }; }; }