diff --git a/CHANGELOG.md b/CHANGELOG.md index aa3ccbfc..dfdc50e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Upgraded `package:file` to `5.0.0`. * `ResponseContext.sendFile` now uses `package:file`. * Abandon `ContentType` in favor of `MediaType`. +* Changed view engine to use `Map`. # 1.1.5+1 * Patched annoying error that prevented MapServices from working, diff --git a/lib/src/core/angel_base.dart b/lib/src/core/angel_base.dart index 0d1f1745..a1d0cc37 100644 --- a/lib/src/core/angel_base.dart +++ b/lib/src/core/angel_base.dart @@ -1,16 +1,19 @@ library angel_framework.http.angel_base; import 'dart:async'; + import 'package:angel_container/angel_container.dart'; + import 'routable.dart'; /// A function that asynchronously generates a view from the given path and data. -typedef Future ViewGenerator(String path, [Map data]); +typedef FutureOr ViewGenerator(String path, + [Map data]); /// Base class for Angel servers. Do not bother extending this. class AngelBase extends Routable { - static ViewGenerator noViewEngineConfigured = (String view, [Map data]) => - new Future.value("No view engine has been configured yet."); + static ViewGenerator noViewEngineConfigured = + (String view, [Map data]) => 'No view engine has been configured yet.'; Container _container; diff --git a/lib/src/core/response_context.dart b/lib/src/core/response_context.dart index c4a6ed83..547fd51b 100644 --- a/lib/src/core/response_context.dart +++ b/lib/src/core/response_context.dart @@ -51,7 +51,7 @@ abstract class ResponseContext implements StreamSink>, StringSink { /// A [Map] of data to inject when `res.render` is called. /// /// This can be used to reduce boilerplate when using templating engines. - final Map renderParams = {}; + final Map renderParams = {}; /// Points to the [RequestContext] corresponding to this response. RequestContext get correspondingRequest; @@ -181,10 +181,10 @@ abstract class ResponseContext implements StreamSink>, StringSink { } /// Renders a view to the response stream, and closes the response. - Future render(String view, [Map data]) { + Future render(String view, [Map data]) { if (!isOpen) throw closed(); return app - .viewGenerator(view, new Map.from(renderParams)..addAll(data ?? {})) + .viewGenerator(view, new Map.from(renderParams)..addAll(data ?? {})) .then((content) { write(content); headers['content-type'] = 'text/html';