Skip to content

Commit

Permalink
HTML-15 Use unique class names for examples
Browse files Browse the repository at this point in the history
This makes it easier to paste all examples into one `crystal i` session.
  • Loading branch information
sbsoftware committed Aug 26, 2023
1 parent ef7e270 commit 1e87c65
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ end
```crystal
require "to_html"
class MyView
class StaticInstanceView
ToHtml.instance_template do
h1 { "Hello World!" }
p do
Expand All @@ -80,15 +80,15 @@ class MyView
end
end
puts MyView.new.to_html
puts StaticInstanceView.new.to_html
```

### Dynamic Instance Template

```crystal
require "to_html"
class MyView
class DynamicInstanceView
getter heading : String
def initialize(@heading); end
Expand All @@ -103,23 +103,23 @@ class MyView
end
end
puts MyView.new("Template!").to_html
puts DynamicInstanceView.new("Template!").to_html
```

### Class template

```crystal
require "to_html"
class MyView
class ClassView
ToHtml.class_template do
div do
p { "This needs no instance" }
end
end
end
puts MyView.to_html
puts ClassView.to_html
```

### Attributes
Expand All @@ -131,7 +131,7 @@ You can add attributes to your tags via named arguments to the calls.
```crystal
require "to_html"
class MyView
class NamedArgumentsView
ToHtml.instance_template do
div class: "my-div" do
form action: "https://www.example.com", method: "POST" do
Expand All @@ -144,7 +144,7 @@ class MyView
end
end
puts MyView.new.to_html
puts NamedArgumentsView.new.to_html
```

#### Object Interface
Expand All @@ -153,7 +153,7 @@ Another way to add attributes is via objects that implement `#to_tag_attrs`. The
This is still a bit experimental but the following example shows a few possible use cases, as well as the full potential of these macros.

```crystal
class MyView
class ObjectInterfaceView
ToHtml.instance_template do
div MyObject do
form MyResource do
Expand Down Expand Up @@ -193,7 +193,7 @@ end
# </form>
# <a href="/my_resource">MyResource</a>
# </div>
puts MyView.new.to_html
puts ObjectInterfaceView.new.to_html
```

### More
Expand Down

0 comments on commit 1e87c65

Please sign in to comment.