defmodule FrancisHtmx do @moduledoc """ Provides a macro to render htmx content by loading htmx.js. Also provides a sigil to render EEx content similar to ~H from Phoenix.LiveView Usage: ```elixir defmodule Example do use Francis import FrancisHtmx htmx(fn _conn -> assigns = %{} ~E\"\"\"
Color Swap Demo
"> Color Swap Demo
\"\"\" end) end ``` In this scenario we are loading serving an HTML that has the htmx.js library loaded and serves the root content given by htmx/1 """ @doc """ Renders htmx content by loading htmx.js and rendering binary content. """ @spec htmx((Plug.Conn.t() -> binary()), Keyword.t()) :: Macro.t() defmacro htmx(content, opts \\ []) do title = Keyword.get(opts, :title, "") head = Keyword.get(opts, :head, "") quote location: :keep do get("/", fn conn -> conn |> Plug.Conn.put_resp_content_type("text/html") |> Plug.Conn.send_resp(200, """ #{unquote(head)}