phoenix_slime
phoenix_slime copied to clipboard
Phoenix 1.5 does not render innermost .slimleex template
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
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
I'm having the same issue.
The file need to be what this extension(*.slimleex or just *.slime)?
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.
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
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.
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.