platform/packages/html_builder
2021-09-11 11:49:37 +08:00
..
example Updated HTML_Builder 2021-06-22 17:35:08 +08:00
lib Deprecated html_builder 2021-09-11 11:49:37 +08:00
test Publish html_builder 2021-05-15 19:47:48 +08:00
.gitignore Updated authors and license 2021-05-15 16:48:20 +08:00
analysis_options.yaml Publish html_builder 2.0.1 2021-05-15 22:12:07 +08:00
AUTHORS.md Updated authors and license 2021-05-15 16:48:20 +08:00
CHANGELOG.md Deprecated html_builder 2021-09-11 11:49:37 +08:00
LICENSE Deprecated html_builder 2021-09-11 11:49:37 +08:00
pubspec.yaml Deprecated html_builder 2021-09-11 11:49:37 +08:00
README.md Deprecated html_builder 2021-09-11 11:49:37 +08:00

Angel3 Html Builder

version Null Safety Gitter

License

DEPRECATED: Replaced by belatuk_html_builder package

Build HTML AST's and render them to HTML.

This can be used as an internal DSL, i.e. for a templating engine.

Installation

In your pubspec.yaml:

dependencies:
  angel3_html_builder: ^2.0.0

Usage

import 'package:angel3_html_builder/angel3_html_builder.dart';

void main() {
    // Akin to React.createElement(...);
    var $el = h('my-element', p: {}, c: []);

    // Attributes can be plain Strings.
    h('foo', p: {
        'bar': 'baz'
    });

    // Null attributes do not appear.
    h('foo', p: {
        'does-not-appear': null
    });

    // If an attribute is a bool, then it will only appear if its value is true.
    h('foo', p: {
        'appears': true,
        'does-not-appear': false
    });

    // Or, a String or Map.
    h('foo', p: {
        'style': 'background-color: white; color: red;'
    });

    h('foo', p: {
        'style': {
            'background-color': 'white',
            'color': 'red'
        }
    });

    // Or, a String or Iterable.
    h('foo', p: {
        'class': 'a b'
    });

    h('foo', p: {
        'class': ['a', 'b']
    });
}

Standard HTML5 elements:

import 'package:angel3_html_builder/elements.dart';

void main() {
    var $dom = html(lang: 'en', c: [
        head(c: [
            title(c: [text('Hello, world!')])
        ]),
        body(c: [
            h1(c: [text('Hello, world!')]),
            p(c: [text('Ok')])
        ])
    ]);
}

Rendering to HTML:

String html = StringRenderer().render($dom);

Example with the Angel server-side framework, which has dedicated html_builder support:

import 'dart:io';
import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel3_html_builder/elements.dart';

configureViews(Angel app) async {
    app.get('/foo/:id', (req, res) async {
        var foo = await app.service('foo').read(req.params['id']);
        return html(c: [
            head(c: [
                title(c: [text(foo.name)])
            ]),
            body(c: [
                h1(c: [text(foo.name)])
            ])
        ]);
    });
}