diff --git a/packages/jinja/.gitignore b/packages/jinja/.gitignore new file mode 100644 index 00000000..50602ac6 --- /dev/null +++ b/packages/jinja/.gitignore @@ -0,0 +1,11 @@ +# Files and directories created by pub +.dart_tool/ +.packages +# 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 +doc/api/ diff --git a/packages/jinja/CHANGELOG.md b/packages/jinja/CHANGELOG.md new file mode 100644 index 00000000..687440ba --- /dev/null +++ b/packages/jinja/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +- Initial version, created by Stagehand diff --git a/packages/jinja/LICENSE b/packages/jinja/LICENSE new file mode 100644 index 00000000..8d171670 --- /dev/null +++ b/packages/jinja/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Tobe Osakwe + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/packages/jinja/README.md b/packages/jinja/README.md new file mode 100644 index 00000000..840574ba --- /dev/null +++ b/packages/jinja/README.md @@ -0,0 +1,45 @@ +# 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}'); +} +``` \ No newline at end of file diff --git a/packages/jinja/analysis_options.yaml b/packages/jinja/analysis_options.yaml new file mode 100644 index 00000000..c230cee7 --- /dev/null +++ b/packages/jinja/analysis_options.yaml @@ -0,0 +1,4 @@ +include: package:pedantic/analysis_options.yaml +analyzer: + strong-mode: + implicit-casts: false \ No newline at end of file diff --git a/packages/jinja/example/main.dart b/packages/jinja/example/main.dart new file mode 100644 index 00000000..b40937c0 --- /dev/null +++ b/packages/jinja/example/main.dart @@ -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}'); +} diff --git a/packages/jinja/example/views/hello.html b/packages/jinja/example/views/hello.html new file mode 100644 index 00000000..22d1c470 --- /dev/null +++ b/packages/jinja/example/views/hello.html @@ -0,0 +1,5 @@ +{% extends "layout.html" %} +{% block title %}hello {{ name }}!{% endblock %} +{% block body %} +
hello {{ name }}!
+{% endblock %} \ No newline at end of file diff --git a/packages/jinja/example/views/index.html b/packages/jinja/example/views/index.html new file mode 100644 index 00000000..cb403f32 --- /dev/null +++ b/packages/jinja/example/views/index.html @@ -0,0 +1,6 @@ +{% extends "layout.html" %} +{% block title %}Jinja.Dart!{% endblock %} +{% block body %} +hello Jinja.Dart!
+ hello Joe! +{% endblock %} \ No newline at end of file diff --git a/packages/jinja/example/views/layout.html b/packages/jinja/example/views/layout.html new file mode 100644 index 00000000..4f1f056e --- /dev/null +++ b/packages/jinja/example/views/layout.html @@ -0,0 +1,10 @@ + + + + +