Changed view engine to use Map<String, dynamic>

This commit is contained in:
Tobe O 2018-08-19 11:42:40 -04:00
parent 696fb8dd81
commit b326e6c547
3 changed files with 10 additions and 6 deletions

View file

@ -4,6 +4,7 @@
* Upgraded `package:file` to `5.0.0`. * Upgraded `package:file` to `5.0.0`.
* `ResponseContext.sendFile` now uses `package:file`. * `ResponseContext.sendFile` now uses `package:file`.
* Abandon `ContentType` in favor of `MediaType`. * Abandon `ContentType` in favor of `MediaType`.
* Changed view engine to use `Map<String, dynamic>`.
# 1.1.5+1 # 1.1.5+1
* Patched annoying error that prevented MapServices from working, * Patched annoying error that prevented MapServices from working,

View file

@ -1,16 +1,19 @@
library angel_framework.http.angel_base; library angel_framework.http.angel_base;
import 'dart:async'; import 'dart:async';
import 'package:angel_container/angel_container.dart'; import 'package:angel_container/angel_container.dart';
import 'routable.dart'; import 'routable.dart';
/// A function that asynchronously generates a view from the given path and data. /// A function that asynchronously generates a view from the given path and data.
typedef Future<String> ViewGenerator(String path, [Map data]); typedef FutureOr<String> ViewGenerator(String path,
[Map<String, dynamic> data]);
/// Base class for Angel servers. Do not bother extending this. /// Base class for Angel servers. Do not bother extending this.
class AngelBase extends Routable { class AngelBase extends Routable {
static ViewGenerator noViewEngineConfigured = (String view, [Map data]) => static ViewGenerator noViewEngineConfigured =
new Future<String>.value("No view engine has been configured yet."); (String view, [Map data]) => 'No view engine has been configured yet.';
Container _container; Container _container;

View file

@ -51,7 +51,7 @@ abstract class ResponseContext implements StreamSink<List<int>>, StringSink {
/// A [Map] of data to inject when `res.render` is called. /// A [Map] of data to inject when `res.render` is called.
/// ///
/// This can be used to reduce boilerplate when using templating engines. /// This can be used to reduce boilerplate when using templating engines.
final Map renderParams = {}; final Map<String, dynamic> renderParams = {};
/// Points to the [RequestContext] corresponding to this response. /// Points to the [RequestContext] corresponding to this response.
RequestContext get correspondingRequest; RequestContext get correspondingRequest;
@ -181,10 +181,10 @@ abstract class ResponseContext implements StreamSink<List<int>>, StringSink {
} }
/// Renders a view to the response stream, and closes the response. /// Renders a view to the response stream, and closes the response.
Future render(String view, [Map data]) { Future render(String view, [Map<String, dynamic> data]) {
if (!isOpen) throw closed(); if (!isOpen) throw closed();
return app return app
.viewGenerator(view, new Map.from(renderParams)..addAll(data ?? {})) .viewGenerator(view, new Map<String, dynamic>.from(renderParams)..addAll(data ?? <String, dynamic>{}))
.then((content) { .then((content) {
write(content); write(content);
headers['content-type'] = 'text/html'; headers['content-type'] = 'text/html';