Publish html_builder 2.0.1
This commit is contained in:
parent
37c586a7e5
commit
61bae79233
9 changed files with 529 additions and 516 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
# 2.0.1
|
||||||
|
* Added pedantic dart rules
|
||||||
|
|
||||||
# 2.0.0
|
# 2.0.0
|
||||||
* Migrated to work with Dart SDK 2.12.x NNBD
|
* Migrated to work with Dart SDK 2.12.x NNBD
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# angel3_html_builder
|
# angel3_html_builder
|
||||||
[![version](https://img.shields.io/badge/pub-v2.0.0-brightgreen)](https://pub.dartlang.org/packages/angel3_html_builder)
|
[![version](https://img.shields.io/badge/pub-v2.0.1-brightgreen)](https://pub.dartlang.org/packages/angel3_html_builder)
|
||||||
[![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
|
[![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)
|
[![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
include: package:pedantic/analysis_options.yaml
|
||||||
|
|
||||||
analyzer:
|
analyzer:
|
||||||
strong-mode:
|
strong-mode:
|
||||||
implicit-casts: false
|
implicit-casts: false
|
File diff suppressed because it is too large
Load diff
|
@ -3,7 +3,7 @@ import 'node_builder.dart';
|
||||||
|
|
||||||
/// Returns a function that rebuilds an arbitrary [Node] by applying the [transform] to it.
|
/// Returns a function that rebuilds an arbitrary [Node] by applying the [transform] to it.
|
||||||
Node Function(Node) rebuild(NodeBuilder Function(NodeBuilder) transform,
|
Node Function(Node) rebuild(NodeBuilder Function(NodeBuilder) transform,
|
||||||
{bool selfClosing: false}) {
|
{bool selfClosing = false}) {
|
||||||
return (node) =>
|
return (node) =>
|
||||||
transform(NodeBuilder.from(node)).build(selfClosing: selfClosing);
|
transform(NodeBuilder.from(node)).build(selfClosing: selfClosing);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ class Node {
|
||||||
|
|
||||||
Node._selfClosing(this.tagName,
|
Node._selfClosing(this.tagName,
|
||||||
[Map<String, dynamic> attributes = const {}]) {
|
[Map<String, dynamic> attributes = const {}]) {
|
||||||
this..attributes.addAll(attributes);
|
this.attributes.addAll(attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -35,7 +35,10 @@ class Node {
|
||||||
|
|
||||||
/// Represents a self-closing tag, i.e. `<br>`.
|
/// Represents a self-closing tag, i.e. `<br>`.
|
||||||
class SelfClosingNode extends Node {
|
class SelfClosingNode extends Node {
|
||||||
|
@override
|
||||||
final String tagName;
|
final String tagName;
|
||||||
|
|
||||||
|
@override
|
||||||
final Map<String, dynamic> attributes = {};
|
final Map<String, dynamic> attributes = {};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -8,7 +8,7 @@ class NodeBuilder {
|
||||||
Node? _existing;
|
Node? _existing;
|
||||||
|
|
||||||
NodeBuilder(this.tagName,
|
NodeBuilder(this.tagName,
|
||||||
{this.attributes: const {}, this.children: const []});
|
{this.attributes = const {}, this.children = const []});
|
||||||
|
|
||||||
/// Creates a [NodeBuilder] that just spits out an already-existing [Node].
|
/// Creates a [NodeBuilder] that just spits out an already-existing [Node].
|
||||||
factory NodeBuilder.existing(Node existingNode) =>
|
factory NodeBuilder.existing(Node existingNode) =>
|
||||||
|
@ -19,7 +19,7 @@ class NodeBuilder {
|
||||||
children: List<Node>.from(node.children));
|
children: List<Node>.from(node.children));
|
||||||
|
|
||||||
/// Builds the node.
|
/// Builds the node.
|
||||||
Node build({bool selfClosing: false}) =>
|
Node build({bool selfClosing = false}) =>
|
||||||
_existing ??
|
_existing ??
|
||||||
(selfClosing
|
(selfClosing
|
||||||
? SelfClosingNode(tagName, attributes)
|
? SelfClosingNode(tagName, attributes)
|
||||||
|
@ -85,9 +85,11 @@ class NodeBuilder {
|
||||||
var clazz = attributes['class'];
|
var clazz = attributes['class'];
|
||||||
var classes = <String>[];
|
var classes = <String>[];
|
||||||
|
|
||||||
if (clazz is String)
|
if (clazz is String) {
|
||||||
classes.addAll(clazz.split(' '));
|
classes.addAll(clazz.split(' '));
|
||||||
else if (clazz is Iterable) classes.addAll(clazz.map((s) => s.toString()));
|
} else if (clazz is Iterable) {
|
||||||
|
classes.addAll(clazz.map((s) => s.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
return setClasses(f(classes));
|
return setClasses(f(classes));
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,10 @@ abstract class StringRenderer implements Renderer<String> {
|
||||||
/// If [pretty] is `true` (default), then [whitespace] (default: `' '`) will be inserted between nodes.
|
/// If [pretty] is `true` (default), then [whitespace] (default: `' '`) will be inserted between nodes.
|
||||||
/// You can also provide a [doctype] (default: `html`).
|
/// You can also provide a [doctype] (default: `html`).
|
||||||
factory StringRenderer(
|
factory StringRenderer(
|
||||||
{bool html5: true,
|
{bool html5 = true,
|
||||||
bool pretty: true,
|
bool pretty = true,
|
||||||
String doctype: 'html',
|
String doctype = 'html',
|
||||||
String whitespace: ' '}) =>
|
String whitespace = ' '}) =>
|
||||||
pretty == true
|
pretty == true
|
||||||
? _PrettyStringRendererImpl(
|
? _PrettyStringRendererImpl(
|
||||||
html5: html5 != false, doctype: doctype, whitespace: whitespace)
|
html5: html5 != false, doctype: doctype, whitespace: whitespace)
|
||||||
|
@ -81,7 +81,9 @@ class _PrettyStringRendererImpl implements StringRenderer {
|
||||||
_PrettyStringRendererImpl({this.html5, this.whitespace, this.doctype});
|
_PrettyStringRendererImpl({this.html5, this.whitespace, this.doctype});
|
||||||
|
|
||||||
void _applyTabs(int tabs, StringBuffer buf) {
|
void _applyTabs(int tabs, StringBuffer buf) {
|
||||||
for (int i = 0; i < tabs; i++) buf.write(whitespace ?? ' ');
|
for (var i = 0; i < tabs; i++) {
|
||||||
|
buf.write(whitespace ?? ' ');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _renderInto(int tabs, Node node, StringBuffer buf) {
|
void _renderInto(int tabs, Node node, StringBuffer buf) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
name: angel3_html_builder
|
name: angel3_html_builder
|
||||||
description: Build HTML AST's and render them to HTML. This can be used as an internal DSL, i.e. for a templating engine.
|
description: Build HTML AST's and render them to HTML. This can be used as an internal DSL, i.e. for a templating engine.
|
||||||
version: 2.0.0
|
version: 2.0.1
|
||||||
homepage: https://github.com/dukefirehawk/angel/tree/angel3/packages/html_builder
|
homepage: 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'
|
||||||
|
@ -9,3 +9,4 @@ dependencies:
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
html: ^0.15.0
|
html: ^0.15.0
|
||||||
test: ^1.17.4
|
test: ^1.17.4
|
||||||
|
pedantic: ^1.11.0
|
Loading…
Reference in a new issue