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 for inline LiveView templates #184

Open
egze opened this issue Mar 10, 2020 · 6 comments
Open

Support for inline LiveView templates #184

egze opened this issue Mar 10, 2020 · 6 comments

Comments

@egze
Copy link

egze commented Mar 10, 2020

What is the right place to add support for inline templates?

Here is an example:

defmodule AppWeb.ThermostatLive do
  use Phoenix.LiveView

  def render(assigns) do
    ~L"""
    <div class="widget">
      Current temperature: <string><%= @temperature %></strong>
    </div>
    """
  end

  def mount(_params, %{"current_user_id" => user_id}, socket) do
    temperature = Thermostat.get_user_reading(user_id)
    {:ok, assign(socket, :temperature, temperature)}
  end
end

Ideally I would like the part inside the sigil to be highlighted as eex html template.

@josevalim
Copy link
Contributor

This is certainly the repo but I am not quite sure how to implement it. Perhaps look at how other languages do something similar. I think Ruby for example does <<-SQL and so on. A PR is welcome!

@egze
Copy link
Author

egze commented Mar 10, 2020

Cool, I'll look into it. Thanks

@ericsongray
Copy link

ericsongray commented May 25, 2020

Did you figure it out? VS Code is the only editor I know of that currently does it.

@egze
Copy link
Author

egze commented May 25, 2020

I started and made this https://gist.github.com/egze/07721af578b18d349f0e8571f115d6aa

But it is buggy. Doesn't highlight properly stuff like <p><%= @something %></p>, so a mix of html and elixir code. After some trial and error - I gave up. The development process of making a Syntax highlighter in TextMate is insanely wonky, with not a lot of documentation.

Maybe there is a good tool where you can load existing syntax rules and then see the effect, as you make changes? I found https://eeyo.io/iro/ but also couldn't figure out how to import existing Elixir rules. If this is even possible.

@ericsongray
Copy link

I prefer Sublime over VS code and Atom but I agree extending syntax highlighting is a real pain. I think @josevalim and @ankopainting had the right idea but I don't have the know how to implement it. Thanks for your effort.

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

4 participants