Changed view engine to use Map<String, dynamic>
This commit is contained in:
parent
696fb8dd81
commit
b326e6c547
3 changed files with 10 additions and 6 deletions
|
@ -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<String, dynamic>`.
|
||||
|
||||
# 1.1.5+1
|
||||
* Patched annoying error that prevented MapServices from working,
|
||||
|
|
|
@ -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<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.
|
||||
class AngelBase extends Routable {
|
||||
static ViewGenerator noViewEngineConfigured = (String view, [Map data]) =>
|
||||
new Future<String>.value("No view engine has been configured yet.");
|
||||
static ViewGenerator noViewEngineConfigured =
|
||||
(String view, [Map data]) => 'No view engine has been configured yet.';
|
||||
|
||||
Container _container;
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ abstract class ResponseContext implements StreamSink<List<int>>, 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<String, dynamic> renderParams = {};
|
||||
|
||||
/// Points to the [RequestContext] corresponding to this response.
|
||||
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.
|
||||
Future render(String view, [Map data]) {
|
||||
Future render(String view, [Map<String, dynamic> data]) {
|
||||
if (!isOpen) throw closed();
|
||||
return app
|
||||
.viewGenerator(view, new Map.from(renderParams)..addAll(data ?? {}))
|
||||
.viewGenerator(view, new Map<String, dynamic>.from(renderParams)..addAll(data ?? <String, dynamic>{}))
|
||||
.then((content) {
|
||||
write(content);
|
||||
headers['content-type'] = 'text/html';
|
||||
|
|
Loading…
Reference in a new issue