Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/shootingfly/water

A library for writing HTML in plain Crystal.
https://github.com/shootingfly/water

Last synced: 15 days ago
JSON representation

A library for writing HTML in plain Crystal.

Awesome Lists containing this project

README

        

# Water : HTML in plain Crystal

[![Crystal CI](https://github.com/shootingfly/water/actions/workflows/crystal.yml/badge.svg)](https://github.com/shootingfly/water/actions/workflows/crystal.yml)
[![GitHub release](https://img.shields.io/github/release/shootingfly/water.svg)](https://github.com/shootingfly/water/releases)

A library for writing HTML in plain Crystal.

## Installation

1. Add the dependency to your `shard.yml`:

```yaml
dependencies:
water:
github: shootingfly/water
```

2. Run `shards install`

## Usage

```crystal
require "water"

class Water
def_custom_tag hello_world
end

page = Water.new do
doctype
html {
head {
meta %|name="viewport" content="width=device-width,initial-scale=1.0"|
title "This is a tile"
style %q{
h1 {
color: red;
}

p {
color: green;
}
}
script %q{
alert("Hello");
system.logger("\n");
}
link %|rel="stylesheet" media="screen"|
}
body {
h1 %|class="Hello"|, "This is a water file"
h2 "This is blue"
input %|type="checkbox" checked=false|
input %|type="checkbox" checked=true|
input %|type="checkbox" checked="checked"|
span %|id="some-id" class="classname"| {
div %|id="Hello" class="world world2"| {
some_var = "hello world haha"
span %|data-some-var="some_var" two-attr="fun"| {
text "and a hello"
}
span %|class="deep_nested"|, "text inside of <p&gt"
text <<-HTML
#{Process.pid}
text node
other text node
HTML
}
}
div %|class="row"| {
div %|class="col-md-9"| {
users = [1, 2]
users.each_with_index do |index|
h2 %|class="right_#{index}"| {
div {
span "Hello"
}
}
end
}
}
br
text " " * 4
hello_world "Hello"
span Process.pid
}
}
end
puts page
```

```HTML



This is a tile

h1 {
color: red;
}

p {
color: green;
}


alert("Hello");
system.logger("\n");




This is a water file


This is blue








and a hello

text inside of &lt;p&gt
14674
text node
other text node






Hello




Hello






    
Hello
14674

```

## Note
Because `p` and `select` are used by Crystal. tag `p` is renamed to `para`, tag `select` is renamed to `select_tag`.

## Contributing

1. Fork it ()
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

## Contributors

- [Shootingfly](https://github.com/shootingfly) - creator and maintainer