Updated angel3_html

This commit is contained in:
thomashii 2021-09-11 12:03:14 +08:00
parent d528e5d2a4
commit d09d08caad
10 changed files with 73 additions and 134 deletions

View file

@ -1,58 +0,0 @@
# See https://www.dartlang.org/tools/private-files.html
# Files and directories created by pub
.packages
.pub/
build/
# If you're building an application, you may want to check-in your pubspec.lock
pubspec.lock
# Directory created by dartdoc
# If you don't generate documentation locally you can remove this line.
doc/api/
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
# Mongo Explorer plugin:
.idea/**/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
.dart_tool

View file

@ -1,5 +1,9 @@
# 3.0.0 # Change Log
## 3.0.0
* Migrated to support Dart SDK 2.12.x NNBD * Migrated to support Dart SDK 2.12.x NNBD
# 2.0.0 ## 2.0.0
* Angel 2 + Dart 2 updates. * Angel 2 + Dart 2 updates.

View file

@ -1,21 +1,29 @@
MIT License BSD 3-Clause License
Copyright (c) 2017 Tobe O Copyright (c) 2021, dukefirehawk.com
All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy Redistribution and use in source and binary forms, with or without
of this software and associated documentation files (the "Software"), to deal modification, are permitted provided that the following conditions are met:
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 1. Redistributions of source code must retain the above copyright notice, this
copies or substantial portions of the Software. list of conditions and the following disclaimer.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2. Redistributions in binary form must reproduce the above copyright notice,
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, this list of conditions and the following disclaimer in the documentation
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE and/or other materials provided with the distribution.
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 3. Neither the name of the copyright holder nor the names of its
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE contributors may be used to endorse or promote products derived from
SOFTWARE. this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View file

@ -1,16 +1,17 @@
# html # Angel3 HTML
[![Pub](https://img.shields.io/pub/v/angel_html.svg)](https://pub.dartlang.org/packages/angel_html)
[![build status](https://travis-ci.org/angel-dart/html.svg)](https://travis-ci.org/angel-dart/html)
A plug-in that allows you to return html_builder AST's from request handlers, and have them sent as HTML automatically. [![version](https://img.shields.io/badge/pub-v3.0.0-brightgreen)](https://pub.dartlang.org/packages/angel3_html)
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
[`package:html_builder`](https://github.com/thosakwe/html_builder) is a simple virtual DOM library [![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/html/LICENSE)
(without diffing, you can find that
[here](https://github.com/thosakwe/html_builder_vdom)), with a handy Dart DSL that makes it easy to build HTML A plug-in that allows you to return `belatuk_html_builder` AST's from request handlers, and have them sent as HTML automatically.
AST's:
[`package:belatuk_html_builder`](https://pub.dev/packages/belatuk_html_builder) is a simple virtual DOM library with a handy Dart DSL that makes it easy to build HTML AST's:
```dart ```dart
import 'package:html_builder/elements.dart'; import 'package:belatuk_html_builder/elements.dart';
Node myDom = html(lang: 'en', c: [ Node myDom = html(lang: 'en', c: [
head(c: [ head(c: [
@ -28,19 +29,21 @@ Node myDom = html(lang: 'en', c: [
``` ```
This plug-in means that you can now `return` these AST's, and Angel will automatically send them to This plug-in means that you can now `return` these AST's, and Angel will automatically send them to
clients. Ultimately, the implication is that you can use `html_builder` as a substitute for a clients. Ultimately, the implication is that you can use `belatuk_html_builder` as a substitute for a
templating system within Dart. With [hot reloading](https://github.com/angel-dart/hot), you won't templating system within Dart. With [hot reloading](https://pub.dev/packages/angel3_hot), you won't
even need to reload your server (as it should be). even need to reload your server (as it should be).
# Installation ## Installation
In your `pubspec.yaml`: In your `pubspec.yaml`:
```yaml ```yaml
dependencies: dependencies:
angel_html: ^1.0.0 angel3_html: ^3.0.0
``` ```
# Usage ## Usage
The `renderHtml` function does all the magic for you. The `renderHtml` function does all the magic for you.
```dart ```dart

View file

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

View file

@ -1,7 +1,7 @@
import 'package:angel_framework/angel_framework.dart'; import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel_framework/http.dart'; import 'package:angel3_framework/http.dart';
import 'package:angel_html/angel_html.dart'; import 'package:angel3_html/angel3_html.dart';
import 'package:html_builder/elements.dart'; import 'package:belatuk_html_builder/elements.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
void main() async { void main() async {

View file

@ -1,13 +1,14 @@
import 'dart:async'; import 'dart:async';
import 'package:angel_framework/angel_framework.dart'; import 'package:angel3_framework/angel3_framework.dart';
import 'package:html_builder/html_builder.dart'; import 'package:belatuk_html_builder/belatuk_html_builder.dart';
/// Returns a [RequestMiddleware] that allows you to return `html_builder` [Node]s as responses. /// Returns a [RequestMiddleware] that allows you to return `html_builder` [Node]s as responses.
/// ///
/// You can provide a custom [renderer]. The default renders minified HTML5 pages. /// You can provide a custom [renderer]. The default renders minified HTML5 pages.
/// ///
/// Set [enforceAcceptHeader] to `true` to throw a `406 Not Acceptable` if the client doesn't accept HTML responses. /// Set [enforceAcceptHeader] to `true` to throw a `406 Not Acceptable` if the client doesn't accept HTML responses.
RequestHandler renderHtml({StringRenderer? renderer, bool? enforceAcceptHeader}) { RequestHandler renderHtml(
{StringRenderer? renderer, bool? enforceAcceptHeader}) {
renderer ??= StringRenderer(pretty: false, html5: true); renderer ??= StringRenderer(pretty: false, html5: true);
return (RequestContext req, ResponseContext res) { return (RequestContext req, ResponseContext res) {
@ -15,7 +16,7 @@ RequestHandler renderHtml({StringRenderer? renderer, bool? enforceAcceptHeader})
res.serializer = (data) { res.serializer = (data) {
if (data is! Node) { if (data is! Node) {
return oldSerializer!(data); return oldSerializer(data);
} else { } else {
if (enforceAcceptHeader == true && !req.accepts('text/html')) { if (enforceAcceptHeader == true && !req.accepts('text/html')) {
throw AngelHttpException.notAcceptable(); throw AngelHttpException.notAcceptable();

View file

@ -1,28 +1,16 @@
name: angel_html name: angel3_html
version: 3.0.0 version: 3.0.0
description: Support for rendering html_builder AST's as responses in Angel. description: Support for rendering html_builder AST's as responses in Angel.
homepage: https://github.com/angel-dart/html_builder homepage: https://angel3-framework.web.app/
publish_to: none repository: https://github.com/dukefirehawk/angel/tree/angel3/packages/html_builder
environment: environment:
sdk: '>=2.12.0 <3.0.0' sdk: '>=2.12.0 <3.0.0'
dependencies: dependencies:
angel_framework: angel3_framework: ^4.0.0
git: belatuk_html_builder: ^3.0.0
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x_nnbd
path: packages/framework
html_builder:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x_nnbd
path: packages/html_builder
dev_dependencies: dev_dependencies:
angel_test: angel3_test: ^4.0.0
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x_nnbd
path: packages/test
html: ^0.15.0 html: ^0.15.0
logging: ^1.0.1 logging: ^1.0.1
test: ^1.17.0 test: ^1.17.0
pedantic: ^1.11.0 lints: ^1.0.0

View file

@ -1,8 +1,8 @@
import 'package:angel_framework/angel_framework.dart'; import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel_html/angel_html.dart'; import 'package:angel3_html/angel3_html.dart';
import 'package:angel_test/angel_test.dart'; import 'package:angel3_test/angel3_test.dart';
import 'package:html_builder/elements.dart'; import 'package:belatuk_html_builder/elements.dart';
import 'package:html_builder/html_builder.dart'; import 'package:belatuk_html_builder/belatuk_html_builder.dart';
import 'package:test/test.dart'; import 'package:test/test.dart';
void main() { void main() {

View file

@ -1,5 +1 @@
include: package:pedantic/analysis_options.yaml include: package:lints/recommended.yaml
analyzer:
strong-mode:
implicit-casts: false