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

Phoenix 1.5 does not render innermost .slimleex template #82

Open
CatsOnFilm opened this issue Apr 23, 2020 · 6 comments
Open

Phoenix 1.5 does not render innermost .slimleex template #82

CatsOnFilm opened this issue Apr 23, 2020 · 6 comments

Comments

@CatsOnFilm
Copy link

CatsOnFilm commented Apr 23, 2020

With Phoenix 1.5.0 release, the generated app offers default configuration in scaffold for live_view. A default phoenix app with the --live flag now generates a different layout set than the current (at the time of this issue, v 0.13.1) phoenix_slime. Phoenix now uses a root, app, and live layout templates.
After manually converting over the generated layout files, and proving those to be functional, converting the inner generated content (App.PageLive.html.leex) results in an error. Build prior to transforming template to slimleex gets re-used, so have to delete build file and rebuild to produce the error, otherwise appears to fail silently.

render/1 was not implemented for PhxslimeWeb.PageLive.
Make sure to either explicitly define a render/1 clause with a LiveView template:

    def render(assigns) do
      ~L"""
      ...
      """
    end

Or create a file at "lib/phxslime_web/live/page_live.html.leex" with the LiveView template.

In the call to Phoenix.LiveView.renderer, the block generating the error:

defmodule Phoenix.LiveView.Renderer do
  @moduledoc false

  defmacro __before_compile__(env) do
    render? = Module.defines?(env.module, {:render, 1})
    template = template_path(env)

    case {render?, File.regular?(template)} do
      {true, true} ->
        IO.warn(
          "ignoring template #{inspect(template)} because the LiveView " <>
            "#{inspect(env.module)} defines a render/1 function",
          Macro.Env.stacktrace(env)
        )

        :ok

      {true, false} ->
        :ok

      {false, true} ->
        ast = Phoenix.LiveView.Engine.compile(template, template_filename(env))

        quote do
          @file unquote(template)
          @external_resource unquote(template)
          def render(var!(assigns)) do
            unquote(ast)
          end
        end

      {false, false} ->
        message = ~s'''
        render/1 was not implemented for #{inspect(env.module)}.
        Make sure to either explicitly define a render/1 clause with a LiveView template:
            def render(assigns) do
              ~L"""
              ...
              """
            end
        Or create a file at #{inspect(template)} with the LiveView template.
        '''

        IO.warn(message, Macro.Env.stacktrace(env))

        quote do
          def render(_assigns) do
            raise unquote(message)
          end
        end
    end
  end

In the {false, false} case, the view's render function is not defined and File.regular? returns false.

Elixir v 1.10.2; Phoenix v 1.5.0

Github Repo project: https://github.com/CatsOnFilm/phxslime

@mangr3n
Copy link

mangr3n commented Apr 27, 2020

I'm having the same issue. I want badly to use slim for my project, but if this isn't resolved, I'm dead in the water.

Where is the file extension resolution happening in the codebase? It seems I'd need slimleex to be looked up as an extension

@romenigld
Copy link

romenigld commented May 5, 2020

I'm having the same issue.
The file need to be what this extension(*.slimleex or just *.slime)?

@doomspork
Copy link
Member

Howdy! Does anyone have a small example project on GitHub we could try to reproduce this on to troubleshoot?

I haven’t gotten to upgrading all of my projects yet unfortunately.

@CatsOnFilm
Copy link
Author

Howdy! Does anyone have a small example project on GitHub we could try to reproduce this on to troubleshoot?

I haven’t gotten to upgrading all of my projects yet unfortunately.

The sample repo was included in the original issue posting.
Github Repo project: https://github.com/CatsOnFilm/phxslime

@mattdb
Copy link

mattdb commented Jul 13, 2020

I experienced this when the generated project used LiveView 0.12.0, but when I updated LiveView to 0.14.1, .slimleex files were found by template_path as expected.

@AnomalousBit
Copy link

Using the example repo (https://github.com/CatsOnFilm/phxslime) I can confirm @mattdb's solution of bumping to phoenix_live_view 0.14.1 (also requires a bump to phoenix_live_dashboard to at least 0.2.8) fixes the render/1 was not implemented... error on compile.

I've been using LiveView extensively on phoenix 1.5.3 / phoenix_live_view 0.14.7 / phoenix_slime 0.13.1 without any of the above issues around inner slimeleex templates not getting rendered. I think this is fixed, but please speak up if I'm wrong.

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

6 participants