defmodule PhoenixSlime do @doc """ Provides the `~l` sigil with HTML safe Slime syntax inside source files. Raises on attempts to use `\#{}`. Use `~L` to allow templating with `\#{}`. iex> import PhoenixSlime iex> assigns = %{w: "world"} iex> ~l"\"" ...> p = "hello " <> @w ...> "\"" {:safe, [[["" | "

"] | "hello world"] | "

"]} """ defmacro sigil_l(expr, opts) do handle_sigil(expr, opts, __CALLER__.line) end @doc """ Provides the `~L` sigil with HTML safe Slime syntax inside source files. iex> import PhoenixSlime iex> ~L"\"" ...> p hello \#{"world"} ...> "\"" {:safe, [[["" | "

hello "] | "world" ] | "

"]} """ defmacro sigil_L(expr, opts) do handle_sigil(expr, opts, __CALLER__.line) end defp handle_sigil({:<<>>, _, [expr]}, [], line) do expr |> Slime.Renderer.precompile() |> EEx.compile_string(engine: Phoenix.HTML.Engine, line: line + 1) end defp handle_sigil(_, _, _) do raise ArgumentError, ~S(Templating is not allowed with #{} in ~l sigil.) <> ~S( Remove the #{}, use = to insert values, or ) <> ~S(use ~L to template with #{}.) end end