Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
filipecabaco committed Nov 25, 2023
1 parent d7300c2 commit 0a7874a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
# FrancisHtmx

WIP
Module to use HTMX with Francis

```elixir
defmodule Example do
use Francis
import FrancisHtmx

htmx(fn _conn ->
assigns = %{}
~E"""
<style>
.smooth { transition: all 1s ease-in; font-size: 8rem; }
</style>
<div hx-get="/colors" hx-trigger="every 1s">
<p id="color-demo" class="smooth">Color Swap Demo</p>
</div>
"""
end)

get("/colors", fn _ ->
new_color = 3 |> :crypto.strong_rand_bytes() |> Base.encode16() |> then(&"##{&1}")
assigns = %{new_color: new_color}

~E"""
<p id="color-demo" class="smooth" style="<%= "color:#{@new_color}"%>">
Color Swap Demo
</p>
"""
end)
end
```
13 changes: 12 additions & 1 deletion example/lib/example.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@ defmodule Example do
use Francis
import FrancisHtmx

htmx(fn _conn -> File.read!("static/root.html") end)
htmx(fn _conn ->
assigns = %{}
~E"""
<style>
.smooth { transition: all 1s ease-in; font-size: 8rem; }
</style>
<div hx-get="/colors" hx-trigger="every 1s">
<p id="color-demo" class="smooth">Color Swap Demo</p>
</div>
"""
end)

get("/colors", fn _ ->
new_color = 3 |> :crypto.strong_rand_bytes() |> Base.encode16() |> then(&"##{&1}")
assigns = %{new_color: new_color}

~E"""
<p id="color-demo" class="smooth" style="<%= "color:#{@new_color}"%>">
Color Swap Demo
Expand Down
10 changes: 0 additions & 10 deletions example/static/root.html

This file was deleted.

2 changes: 1 addition & 1 deletion lib/francis_htmx.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule FrancisHtmx do

defmacro sigil_E(content, _opts \\ []) do
unless Macro.Env.has_var?(__CALLER__, {:assigns, nil}) do
raise "~H requires a variable named \"assigns\" to exist and be set to a map"
raise "~E requires a variable named \"assigns\" to exist and be set to a map"
end

quote do
Expand Down

0 comments on commit 0a7874a

Please sign in to comment.