html-builder.cr v0.1.2
html-builder
Build HTML using a crystal DSL. The dsl strictly checks the attributes using the compiler at build time.
Installation
-
Add the dependency to your
shard.yml
:dependencies: html-builder: github: threez/html-builder.cr
-
Run
shards install
Usage
require "html-builder"
class Page
include HTML::Builder
def initialize(@io : IO)
end
def render
doctype
html lang: :en do
head do
meta name: :robots, content: :nofollow
title do
style { raw "h1 > span { font-size: 10px; }" }
end
end
body do
h1 style: {"font-family": "Helvetica"}, id: :title do
text "Hello > World"
end
para aria: {label: "Example"} do
a data: {sample: "foobar"}, on: {click: "event.preventDefault()"} { text "Click me!" }
end
end
end
end
end
# Then simply render the page
puts Page.new(STDOUT).render
Special attributes
There are a few special attributes:
:on
hash of event handlers:style
hash or string of style configuration:data
hash of data values:aria
hash of aria attributes
Special tags
para
instead ofp
select_tag
instead ofselect
Related projects
HTML to code
The converter of the lucky project can be used to handle most of the conversion.
Contributing
- Fork it (https://github.com/threez/html-builder.cr/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Vincent Landgraf - creator and maintainer
Repository
html-builder.cr
Owner
Statistic
- 0
- 0
- 0
- 0
- 1
- over 1 year ago
- April 29, 2023
License
MIT License
Links
Synced at
Thu, 07 Nov 2024 13:13:13 GMT
Languages