htmleez 0.12.0 copy "htmleez: ^0.12.0" to clipboard
htmleez: ^0.12.0 copied to clipboard

HTML easy. A lightweight library for creating HTML programmatically in Dart.

htmleez

Htmleez #

Template-less. Type safe. Simple. Familiar. Pure Dart.

Install #

dart pub add htmleez

Quick Start #

import "package:htmleez/htmleez.dart";

void main() {
  print(HtmlRenderer().render(btn()));
}

HTML btn() => button([
    $type("button"),
    $class("btn btn-primary"),
    $onclick("console.log('Clicked')"),
    "Click me!".t
  ]);

Core Concepts #

  • Tags, Attributes and Events: simple way to mirror HTML elements in Dart.
const div = Tag("div");
const img = Tag("img", true); // renders a void tag <img />
/// Attributes always start with a "$" in order to differentiate them from Tags
const $id = Attribute("id");
const $onclick = RawAttribute("onclick"); // `RawAttribute` does not escape the value
  • Text & Raw:

    • Safe text: .t escapes HTML in text. div(["Hello".t]) -> <div>Hello</div>
    • Raw content: Raw() inserts unescaped content. script([Raw("alert("Hi")")]) -> <script>alert("Hi")</script>
  • Text Extensions: Quick markup helpers on strings

    • "Title".h1() -> <h1>Title</h1>
    • "Text".p("text-muted") -> <p class="text-muted">Text</p>
  • API:

    • <HTML>.add() to append children after creation.

For the full list of tags, attributes, events and extensions, see the API Reference.

2
likes
150
points
307
downloads

Publisher

verified publishernamzug.dev

Weekly Downloads

HTML easy. A lightweight library for creating HTML programmatically in Dart.

Repository (GitHub)
View/report issues

Topics

#html

Documentation

API reference

License

MIT (license)

Dependencies

collection

More

Packages that depend on htmleez