Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/crystal-lang/html_builder
DSL for creating HTML
https://github.com/crystal-lang/html_builder
Last synced: 25 days ago
JSON representation
DSL for creating HTML
- Host: GitHub
- URL: https://github.com/crystal-lang/html_builder
- Owner: crystal-lang
- License: mit
- Created: 2015-12-05T19:30:06.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-09-24T19:40:43.000Z (3 months ago)
- Last Synced: 2024-11-09T17:42:30.668Z (about 1 month ago)
- Language: Crystal
- Size: 26.4 KB
- Stars: 67
- Watchers: 15
- Forks: 17
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-crystal - html_builder - DSL for creating HTML (HTML Builders)
- awesome-crystal - html_builder - DSL for creating HTML (Misc)
README
# html_builder [![Build Status](https://travis-ci.org/crystal-lang/html_builder.svg)](https://travis-ci.org/crystal-lang/html_builder)
DSL for creating HTML programatically (extracted from Crystal's standard library).
## Installation
Add this to your application's `shard.yml`:
```yaml
dependencies:
html_builder:
github: crystal-lang/html_builder
```## Usage
#### Basic usage
```crystal
require "html_builder"html = HTML.build do
a(href: "http://crystal-lang.org") do
text "crystal is awesome"
end
endputs html
```**Output** (this output is formatted for better display):
```html
crystal is awesome
```#### Full HTML5 page
```crystal
html = HTML.build do
doctype
html(lang: "pt-BR") do
head do
title { text "Crystal Programming Language" }meta(charset: "UTF-8")
end
body do
a(href: "http://crystal-lang.org") { text "Crystal rocks!" }
form(method: "POST") do
input(name: "name")
end
end
end
endputs html
```**Output** :
```html
Crystal Programming Language
```
#### Custom tags
```crystal
html = HTML.build do
tag("v-button", to: "home") { text "Home" }
endputs html
```**Output**:
```htmlHome
```
#### Safety
HTML::Builder escapes attribute values:
```crystal
html = HTML.build do
a(href: "<>") { }
endputs html
```And escapes text:
```crystal
html = HTML.build do
a { text "<>" }
endputs html
```**Output**:
```html
<>
```
## Contributing1. Fork it ( https://github.com/crystal-lang/html_builder/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request