From c4e84490499d3240eb371412367bfb954fc8cf74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20Caba=C3=A7o?= Date: Thu, 16 Nov 2023 15:27:15 +0000 Subject: [PATCH] update example with static; htmx now uses function to load code easily --- example/lib/example.ex | 33 +++++++++------------------------ example/mix.exs | 2 +- example/static/root.html | 10 ++++++++++ lib/francis_htmx.ex | 7 +++---- lib/root.html | 0 5 files changed, 23 insertions(+), 29 deletions(-) create mode 100644 example/static/root.html delete mode 100644 lib/root.html diff --git a/example/lib/example.ex b/example/lib/example.ex index 10e1a1b..3812bc4 100644 --- a/example/lib/example.ex +++ b/example/lib/example.ex @@ -2,34 +2,19 @@ defmodule Example do use Francis import FrancisHtmx - htmx(""" - -
- Color Swap Demo -
- """) + htmx(fn _conn -> File.read!("static/root.html") end) get("/colors", fn _ -> - new_color = 3 |> :crypto.strong_rand_bytes() |> Base.encode16() |> then(&"##{&1}") + new_color = + 3 + |> :crypto.strong_rand_bytes() + |> Base.encode16() + |> then(&"##{&1}") + """ -
+

Color Swap Demo -

+

""" end) - end diff --git a/example/mix.exs b/example/mix.exs index 5b085d9..f6de08b 100644 --- a/example/mix.exs +++ b/example/mix.exs @@ -22,7 +22,7 @@ defmodule Example.MixProject do # Run "mix help deps" to learn about dependencies. defp deps do [ - {:francis_htmx, "~> 0.0.1"} + {:francis_htmx, path: "../"} ] end end diff --git a/example/static/root.html b/example/static/root.html new file mode 100644 index 0000000..cf7dfcb --- /dev/null +++ b/example/static/root.html @@ -0,0 +1,10 @@ + +
+

Color Swap Demo

+

+
diff --git a/lib/francis_htmx.ex b/lib/francis_htmx.ex index ced8e11..e83c0b0 100644 --- a/lib/francis_htmx.ex +++ b/lib/francis_htmx.ex @@ -4,14 +4,13 @@ defmodule FrancisHtmx do unmatched(fn _ -> "not found" end) end end - - defmacro htmx(content, opts \\ []) do + defmacro htmx(content, opts\\[]) do quote location: :keep do - get("/", fn _conn -> unquote(root(content, opts)) end) + get("/", fn conn -> root(unquote(content).(conn), unquote(opts)) end) end end - defp root(content, opts) do + def root(content, opts) when is_binary(content) do title = Keyword.get(opts, :title, "") """ diff --git a/lib/root.html b/lib/root.html deleted file mode 100644 index e69de29..0000000