Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support sigils for inline heex with liveview #169

Open
tomfarm opened this issue Dec 17, 2021 · 2 comments
Open

Support sigils for inline heex with liveview #169

tomfarm opened this issue Dec 17, 2021 · 2 comments

Comments

@tomfarm
Copy link

tomfarm commented Dec 17, 2021

After #166 has been merged, maybe the next step to support phoenix heex templates could be to
introduce a sigil for slime-heex.

Currently there are only ~L and ~l (as far as I know) and both render as plain text when used inside the liveview render(assigns) function, but it may be that I'm missing something there.

defmodule InlineSlimeLive do
  use TestWeb, :live_view

  def mount(_params, _session, socket) do
    {:ok, socket}
  end

 def render(assigns) do
  ~M"""
  h1 hello
  """
end

It would be nice though if Elixir supported sigils with multiple characters, ~S is already in use and we are running out of characters 😄 And getting syntax highlighting to work would be nice too … 🤔

At them moment, I'm using the following code. It works, but I not sure if this supports liveview 100% doing it's diffing magic

defmodule SlimeSigils do
  defmacro sigil_M({:<<>>, meta, [expr]}, []) do
    options = [
      engine: Phoenix.LiveView.HTMLEngine,
      file: __CALLER__.file,
      line: __CALLER__.line + 1,
      module: __CALLER__.module,
      indentation: meta[:indentation] || 0
    ]

    Slime.Renderer.precompile_heex(expr)
    |> EEx.compile_string(options)
  end
end

Importing it in the matching functions/macros in the TestWeb module

  def live_view do
    quote do
      use Phoenix.LiveView,
        layout: {BunWeb.LayoutView, "live.html"}

      import SlimeSigils

      unquote(view_helpers())
    end
  end
  def live_component do
    quote do
      use Phoenix.LiveComponent
      import SlimeSigils

      unquote(view_helpers())
    end
  end
@tnt
Copy link

tnt commented Dec 1, 2022

Really sad that there seems to have happened nothing for almost a year now.

My Christmas wishes (for 2022):

  • Phoenix 1.7.0 final
  • New slime release fully compatible with Phoenix 1.7

Okay, I could have announced it a bit earlier. My fault.

@bonf
Copy link

bonf commented Mar 21, 2023

We have a working branch, compatible with Phoenix 1.7

{:phoenix_slime, git: "https://github.com/populimited/phoenix_slime.git", branch: "master"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants