Skip to content

Commit

Permalink
Merge pull request #16 from stephannv/master
Browse files Browse the repository at this point in the history
  • Loading branch information
beta-ziliani authored Jun 3, 2023
2 parents f13e8ac + b5405e2 commit e3420f9
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 3 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: CI
on:
push:
pull_request:

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- name: Download source
uses: actions/checkout@v3

- name: Install Crystal
uses: crystal-lang/install-crystal@v1

- name: Run tests
run: crystal spec
30 changes: 30 additions & 0 deletions .github/workflows/weekly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Weekly CI
on:
schedule:
- cron: 0 0 * * 1 # At 00:00 on Monday

jobs:
tests:
strategy:
fail-fast: false
matrix:
include:
- {os: ubuntu-latest, crystal: latest}
- {os: ubuntu-latest, crystal: nightly}
- {os: macos-latest}
- {os: windows-latest}

name: Tests
runs-on: ${{matrix.os}}
steps:
- name: Download source
uses: actions/checkout@v3

- name: Install Crystal
uses: crystal-lang/install-crystal@v1
with:
crystal: ${{matrix.crystal}}
shards: false

- name: Run tests
run: crystal spec
1 change: 0 additions & 1 deletion .travis.yml

This file was deleted.

100 changes: 98 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies:
## Usage
#### Basic usage
```crystal
require "html_builder"

Expand All @@ -25,9 +25,105 @@ html = HTML.build do
end
end

puts html # => %(<a href="http://crystal-lang.org">crystal is awesome</a>)
puts html
```

**Output** (this output is formatted for better display):
```html
<a href="http://crystal-lang.org">
crystal is awesome
</a>
```


#### 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
end
puts html
```

**Output** :
```html
<!DOCTYPE html>

<html lang="pt-BR">
<head>
<title>Crystal Programming Language</title>

<meta charset="UTF-8">
</head>

<body>
<a href="http://crystal-lang.org">Crystal rocks!</a>
<form method="POST">
<input name="name">
</form>
</body>
</html>
```

#### Custom tags

```crystal
html = HTML.build do
tag("v-button", to: "home") { text "Home" }
end
puts html
```

**Output**:
```html
<v-button to="home">
Home
</v-button>
```

#### Safety

HTML::Builder escapes attribute values:
```crystal
html = HTML.build do
a(href: "<>") { }
end
puts html
```

**Output**:
```html
<a href="&lt;&gt;"></a>
```

And escapes text:
```crystal
html = HTML.build do
a { text "<>" }
end
puts html
```

**Output**:
```html
<a>&lt;&gt;</a>
```
## Contributing

1. Fork it ( https://github.com/crystal-lang/html_builder/fork )
Expand Down

0 comments on commit e3420f9

Please sign in to comment.