1.0.0-rc.0

This commit is contained in:
Tobe O 2019-01-29 13:06:58 -05:00
parent 0dc2dfb287
commit 2a5abb684b
10 changed files with 181 additions and 7 deletions

10
.gitignore vendored
View file

@ -1,13 +1,11 @@
# See https://www.dartlang.org/guides/libraries/private-files
# Files and directories created by pub
.dart_tool/
.packages
.pub/
build/
# If you're building an application, you may want to check-in your pubspec.lock
# Remove the following pattern if you wish to check in your lock file
pubspec.lock
# Conventional directory for build outputs
build/
# Directory created by dartdoc
# If you don't generate documentation locally you can remove this line.
doc/api/

3
CHANGELOG.md Normal file
View file

@ -0,0 +1,3 @@
## 1.0.0
- Initial version, created by Stagehand

View file

@ -1,2 +1,45 @@
# angel_jinja
# jinja
Angel support for the Jinja2 templating engine, ported from Python to Dart.
[![Pub](https://img.shields.io/pub/v/angel_jinja.svg)](https://pub.dartlang.org/packages/angel_jinja)
# Example
```dart
import 'dart:io';
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_framework/http.dart';
import 'package:angel_jinja/angel_jinja.dart';
import 'package:path/path.dart' as p;
main() async {
var app = Angel();
var http = AngelHttp(app);
var viewsDir = p.join(
p.dirname(
p.fromUri(Platform.script),
),
'views',
);
// Enable Jinja2 views
await app.configure(jinja(path: viewsDir));
// Add routes.
// See: https://github.com/ykmnkmi/jinja.dart/blob/master/example/bin/server.dart
app
..get('/', (req, res) => res.render('index.html'))
..get('/hello', (req, res) => res.render('hello.html', {'name': 'user'}))
..get('/hello/:name', (req, res) => res.render('hello.html', req.params));
app.fallback((req, res) {
res
..statusCode = 404
..write('404 Not Found :(');
});
// Start the server
await http.startServer('127.0.0.1', 3000);
print('Listening at ${http.uri}');
}
```

4
analysis_options.yaml Normal file
View file

@ -0,0 +1,4 @@
include: package:pedantic/analysis_options.yaml
analyzer:
strong-mode:
implicit-casts: false

37
example/main.dart Normal file
View file

@ -0,0 +1,37 @@
import 'dart:io';
import 'package:angel_framework/angel_framework.dart';
import 'package:angel_framework/http.dart';
import 'package:angel_jinja/angel_jinja.dart';
import 'package:path/path.dart' as p;
main() async {
var app = Angel();
var http = AngelHttp(app);
var viewsDir = p.join(
p.dirname(
p.fromUri(Platform.script),
),
'views',
);
// Enable Jinja2 views
await app.configure(jinja(path: viewsDir));
// Add routes.
// See: https://github.com/ykmnkmi/jinja.dart/blob/master/example/bin/server.dart
app
..get('/', (req, res) => res.render('index.html'))
..get('/hello', (req, res) => res.render('hello.html', {'name': 'user'}))
..get('/hello/:name', (req, res) => res.render('hello.html', req.params));
app.fallback((req, res) {
res
..statusCode = 404
..write('404 Not Found :(');
});
// Start the server
await http.startServer('127.0.0.1', 3000);
print('Listening at ${http.uri}');
}

5
example/views/hello.html Normal file
View file

@ -0,0 +1,5 @@
{% extends "layout.html" %}
{% block title %}hello {{ name }}!{% endblock %}
{% block body %}
<p>hello {{ name }}!</p>
{% endblock %}

6
example/views/index.html Normal file
View file

@ -0,0 +1,6 @@
{% extends "layout.html" %}
{% block title %}Jinja.Dart!{% endblock %}
{% block body %}
<p>hello Jinja.Dart!</p>
<a href="/hello/Joe">hello Joe!</a>
{% endblock %}

10
example/views/layout.html Normal file
View file

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>{% block title %}{% endblock %}</title>
</head>
<body>
{% block body %}{% endblock %}
</body>
</html>

53
lib/angel_jinja.dart Normal file
View file

@ -0,0 +1,53 @@
import 'package:angel_framework/angel_framework.dart';
import 'package:jinja/jinja.dart';
/// Configures an Angel server to use Jinja2 to render templates.
///
/// By default, templates are loaded from the filesystem;
/// pass your own [createLoader] callback to override this.
///
/// All options other than [createLoader] are passed to either [FileSystemLoader]
/// or [Environment].
AngelConfigurer jinja({
Iterable<String> ext = const ['html'],
String path = 'lib/src/templates',
bool followLinks = true,
String stmtOpen = '{%',
String stmtClose = '%}',
String varOpen = '{{',
String varClose = '}}',
String commentOpen = '{#',
String commentClose = '#}',
defaultValue,
bool autoReload = true,
Map<String, Function> filters = const <String, Function>{},
Map<String, Function> tests = const <String, Function>{},
Loader Function() createLoader,
}) {
return (app) {
createLoader ??= () {
return FileSystemLoader(
ext: ext.toList(),
path: path,
followLinks: followLinks,
);
};
var env = Environment(
loader: createLoader(),
stmtOpen: stmtOpen,
stmtClose: stmtClose,
varOpen: varOpen,
varClose: varClose,
commentOpen: commentOpen,
commentClose: commentClose,
defaultValue: defaultValue,
autoReload: autoReload,
filters: filters,
tests: tests,
);
app.viewGenerator = (path, [values]) {
return env.getTemplate(path).render(values);
};
};
}

15
pubspec.yaml Normal file
View file

@ -0,0 +1,15 @@
name: angel_jinja
description: Angel support for the Jinja2 templating engine, ported from Python to Dart.
version: 1.0.0-rc.0
homepage: https://github.com/angel-dart/jinja
author: Tobe O <thosakwe@gmail.com>
environment:
sdk: '>=2.0.0-dev <3.0.0'
dependencies:
angel_framework: ^2.0.0-alpha
jinja: ^0.0.4
dev_dependencies:
angel_test: ^2.0.0
path: ^1.0.0
pedantic: ^1.0.0
test: ^1.0.0