platform/packages/markdown/example/main.dart

49 lines
1.4 KiB
Dart
Raw Normal View History

2017-08-13 04:24:38 +00:00
import 'dart:async';
import 'dart:io';
2021-06-21 06:33:18 +00:00
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_framework/http.dart';
import 'package:angel3_markdown/angel3_markdown.dart';
2019-04-11 16:19:12 +00:00
import 'package:file/local.dart';
2017-08-13 04:24:38 +00:00
2021-06-20 12:37:20 +00:00
void main() async {
2017-08-13 04:24:38 +00:00
var app = await createServer();
var http = ProtevusHttp(app);
2019-04-11 16:19:12 +00:00
var server = await http.startServer(InternetAddress.loopbackIPv4, 3000);
2017-08-13 04:24:38 +00:00
print('Listening at http://${server.address.address}:${server.port}');
}
Future<Protevus> createServer() async {
2017-08-13 04:24:38 +00:00
// Create a new server, and install the Markdown renderer.
var app = Protevus();
2019-04-11 16:19:12 +00:00
var fs = LocalFileSystem();
2017-08-13 04:24:38 +00:00
await app
2019-04-11 16:19:12 +00:00
.configure(markdown(fs.directory('views'), template: (content, locals) {
2017-08-13 04:24:38 +00:00
return '''
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>${locals['title'] ?? 'Example Site'} - Example Site</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.13/semantic.min.css">
</head>
<body>
<div class="ui top fixed menu">
<a class="header item" href="/">
<i class="home icon"></i>
Home
</a>
</div>
<div class="ui container" style="margin-top: 5em;">
$content
</div>
</body>
</html>
''';
}));
// Compile a landing page
2019-04-11 16:19:12 +00:00
app.get('/', (req, res) => res.render('hello', {'title': 'Welcome'}));
2017-08-13 04:24:38 +00:00
return app;
}