From 0a7874acb13f4688e7c60a1b1c0ebf78217916c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20Caba=C3=A7o?= Date: Sat, 25 Nov 2023 17:32:43 +0000 Subject: [PATCH] update readme --- README.md | 32 +++++++++++++++++++++++++++++++- example/lib/example.ex | 13 ++++++++++++- example/static/root.html | 10 ---------- lib/francis_htmx.ex | 2 +- 4 files changed, 44 insertions(+), 13 deletions(-) delete mode 100644 example/static/root.html diff --git a/README.md b/README.md index e5dc173..defe3ff 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,33 @@ # FrancisHtmx -WIP \ No newline at end of file +Module to use HTMX with Francis + +```elixir +defmodule Example do + use Francis + import FrancisHtmx + + htmx(fn _conn -> + assigns = %{} + ~E""" + +
+

Color Swap Demo

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

"> + Color Swap Demo +

+ """ + end) +end +``` \ No newline at end of file diff --git a/example/lib/example.ex b/example/lib/example.ex index ff65cb3..656a619 100644 --- a/example/lib/example.ex +++ b/example/lib/example.ex @@ -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""" + +
+

Color Swap Demo

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

"> Color Swap Demo diff --git a/example/static/root.html b/example/static/root.html deleted file mode 100644 index cf7dfcb..0000000 --- a/example/static/root.html +++ /dev/null @@ -1,10 +0,0 @@ - -

-

Color Swap Demo

-

-
diff --git a/lib/francis_htmx.ex b/lib/francis_htmx.ex index 76031ad..12a1b97 100644 --- a/lib/francis_htmx.ex +++ b/lib/francis_htmx.ex @@ -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