Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/yorickpeterse/inko-builder

An Inko library for generating XML and HTML
https://github.com/yorickpeterse/inko-builder

html inko xml

Last synced: 18 days ago
JSON representation

An Inko library for generating XML and HTML

Awesome Lists containing this project

README

        

# Builder

Builder allows generating of XML and HTML using an Inko DSL, without the need
for a template engine of sorts. It's inspired by the [Ruby "Builder"
project](https://github.com/tenderlove/builder), which does the same but in
Ruby.

# Requirements

- Inko 0.15.0 or newer

# Installation

```bash
inko pkg add github.com/yorickpeterse/inko-builder 0.13.0
inko pkg sync
```

# Examples

Generating a simple XML document:

```inko
import builder.xml (Document)
import std.stdio (STDOUT)

class async Main {
fn async main {
let out = STDOUT.new
let doc = Document.with(fn (doc) {
doc.element('person').with(fn (person) {
person.element('name').text('Alice')
person.element('city').text('Foo Town')
})
})

out.print(doc.to_pretty_string)
}
}
```

This produces the following XML:

```xml

Alice
Foo Town

```

Generating a simple HTML document:

```inko
import builder.html (Document)
import std.stdio (STDOUT)

class async Main {
fn async main {
let out = STDOUT.new
let doc = Document.html('en', fn (html) {
html.head.with(fn (head) { head.title.text('My website') })

html.body.with(fn (body) { body.p.text('Hello!') })
})

out.print(doc.to_pretty_string)
}
}
```

This produces the following HTML:

```html


My website


Hello!


```

For more information, refer to the [API
documentation](https://yorickpeterse.github.io/inko-builder/).

# License

All source code in this repository is licensed under the Mozilla Public License
version 2.0, unless stated otherwise. A copy of this license can be found in the
file "LICENSE".