Skip to content

Commit

Permalink
Make Surface 0.9 compatible with phoenix deps updated minor versions (#…
Browse files Browse the repository at this point in the history
…745)

Improves compatibility with minor dependency versions used by surface v0.9.4, this will improve the upgrade (mix deps.update --all) of apps that depend on this version.

* Compatibility with phoenix_live_view "~> 0.18.18"
* Compatibility with phoenix "~> 1.6.16"
* Compatibility with phoenix_html "~> 3.3.1"
---------

Co-authored-by: Marlus Saraiva <[email protected]>
Co-authored-by: Frank Dugan III <[email protected]>
Co-authored-by: Doug W <[email protected]>
  • Loading branch information
4 people authored Apr 9, 2024
1 parent 37bd0bb commit 3fb33c2
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 62 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
push:
branches:
- main
- v0.11
- v0.9

jobs:
mix_test:
Expand All @@ -14,8 +16,6 @@ jobs:
fail-fast: false
matrix:
include:
- elixir: 1.12.3
otp: 24.0
- elixir: 1.13.4
otp: 24.0
- elixir: 1.13.4
Expand Down
4 changes: 2 additions & 2 deletions lib/mix/tasks/surface/surface.init/ex_patcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ defmodule Mix.Tasks.Surface.Init.ExPatcher do
|> Z.node()
|> Sourceror.to_string()

{{:., _, _}, _} ->
%Sourceror.Zipper{node: {:., _, _}} ->
# We can't get the range of the dot call in a qualified call like
# `foo.bar()`, so we apply the patch to the parent. We get into this
# situation when the qualified call has no arguments: the first child
Expand All @@ -344,7 +344,7 @@ defmodule Mix.Tasks.Surface.Init.ExPatcher do
# impossible to generate a patch for the child call alone.
append_child_patch(zipper, string)

last_child_zipper ->
%Sourceror.Zipper{} = last_child_zipper ->
append_child_patch(last_child_zipper, string)
end
end)
Expand Down
8 changes: 4 additions & 4 deletions lib/mix/tasks/surface/surface.init/ex_patcher_move.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ defmodule Mix.Tasks.Surface.Init.ExPatcher.Move do
def find_child(zipper, predicate) do
zipper
|> case do
{{name, _, _}, _} when name != :__block__ ->
%Sourceror.Zipper{node: {name, _, _}} when name != :__block__ ->
zipper

_ ->
%Sourceror.Zipper{} ->
Z.down(zipper)
end
|> return_match_or_move_right(predicate)
Expand Down Expand Up @@ -210,10 +210,10 @@ defmodule Mix.Tasks.Surface.Init.ExPatcher.Move do

defp normalize_opts(zipper) do
case zipper do
{[{{:__block__, _, _}, _} | _], _} ->
%Sourceror.Zipper{node: [{{:__block__, _, _}, _} | _]} ->
zipper

_ ->
%Sourceror.Zipper{} ->
Z.down(zipper)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ defmodule Mix.Tasks.Surface.Init.FilePatchers.MixExs do
:maybe_already_patched
)
|> find_code(~S|defp elixirc_paths(_), do: ["lib"]|)
|> replace(&"defp elixirc_paths(#{env}), do: #{body}\n #{&1}")
|> replace(&"defp elixirc_paths(#{env}), do: #{body}\n#{&1}")
end

def update_elixirc_paths_entry(code, env, update_fun, already_patched_text) do
Expand Down
20 changes: 10 additions & 10 deletions lib/surface/compiler/eex_engine.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ defmodule Surface.Compiler.EExEngine do
ast = state.engine.handle_body(buffer, root: true)

quote do
require Phoenix.LiveView.HTMLEngine
require Phoenix.LiveView.TagEngine
unquote(ast)
end
end
Expand Down Expand Up @@ -265,7 +265,7 @@ defmodule Surface.Compiler.EExEngine do
static_props_map = {:%{}, [], slot_props ++ static_props}

quote do
Phoenix.LiveView.HTMLEngine.component(
Phoenix.LiveView.TagEngine.component(
&apply(unquote(module_expr), unquote(fun_expr), [&1]),
Map.merge(
Surface.build_dynamic_assigns(
Expand Down Expand Up @@ -296,7 +296,7 @@ defmodule Surface.Compiler.EExEngine do
static_props_map = {:%{}, [], slot_props ++ static_props}

quote do
Phoenix.LiveView.HTMLEngine.component(
Phoenix.LiveView.TagEngine.component(
&(unquote(Macro.var(fun, __MODULE__)) / 1),
Map.merge(
Surface.build_assigns(
Expand Down Expand Up @@ -332,7 +332,7 @@ defmodule Surface.Compiler.EExEngine do
module_for_build_assigns = if fun == :render, do: module

quote do
Phoenix.LiveView.HTMLEngine.component(
Phoenix.LiveView.TagEngine.component(
&(unquote(module).unquote(fun) / 1),
Map.merge(
Surface.build_assigns(
Expand Down Expand Up @@ -363,7 +363,7 @@ defmodule Surface.Compiler.EExEngine do
static_props_map = {:%{}, [], static_props ++ slot_props}

quote do
Phoenix.LiveView.HTMLEngine.component(
Phoenix.LiveView.TagEngine.component(
&unquote(module).render/1,
Map.merge(
Surface.build_assigns(
Expand Down Expand Up @@ -394,7 +394,7 @@ defmodule Surface.Compiler.EExEngine do
static_props_map = {:%{}, [], slot_props ++ static_props}

quote do
Phoenix.LiveView.HTMLEngine.component(
Phoenix.LiveView.TagEngine.component(
&unquote(module).render/1,
Map.merge(
Surface.build_assigns(
Expand Down Expand Up @@ -425,7 +425,7 @@ defmodule Surface.Compiler.EExEngine do
static_props_map = {:%{}, [], [{:module, module} | slot_props] ++ static_props}

quote do
Phoenix.LiveView.HTMLEngine.component(
Phoenix.LiveView.TagEngine.component(
&Phoenix.Component.live_component/1,
Map.merge(
Surface.build_assigns(
Expand Down Expand Up @@ -460,7 +460,7 @@ defmodule Surface.Compiler.EExEngine do
static_props_map = {:%{}, [], [{:module, module_expr} | slot_props] ++ static_props}

quote do
Phoenix.LiveView.HTMLEngine.component(
Phoenix.LiveView.TagEngine.component(
&Phoenix.Component.live_component/1,
Map.merge(
Surface.build_dynamic_assigns(
Expand Down Expand Up @@ -554,7 +554,7 @@ defmodule Surface.Compiler.EExEngine do

inner_block =
quote do
Phoenix.LiveView.HTMLEngine.inner_block(unquote(slot_name), do: unquote(block))
Phoenix.LiveView.TagEngine.inner_block(unquote(slot_name), do: unquote(block))
end

props = [__slot__: slot_name, inner_block: inner_block] ++ props
Expand Down Expand Up @@ -645,7 +645,7 @@ defmodule Surface.Compiler.EExEngine do

ast =
quote do
Phoenix.LiveView.HTMLEngine.inner_block(unquote(name), do: unquote(block))
Phoenix.LiveView.TagEngine.inner_block(unquote(name), do: unquote(block))
end

props = [__slot__: name, inner_block: ast] ++ props
Expand Down
12 changes: 5 additions & 7 deletions lib/surface/components/form/inputs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ defmodule Surface.Components.Form.Inputs do
alias Surface.Components.Form
alias Surface.Components.Form.Field

import Phoenix.HTML.Form

@doc """
The parent form.
Expand All @@ -26,9 +24,9 @@ defmodule Surface.Components.Form.Inputs do
prop for, :any, from_context: {Field, :field}

@doc """
Extra options for `inputs_for/3`.
Extra options for `inputs_for/1`.
See `Phoenix.HTML.Form.html.inputs_for/4` for the available options.
See `Phoenix.Component.inputs_for/1` for the available options.
"""
prop opts, :keyword, default: []

Expand All @@ -39,9 +37,9 @@ defmodule Surface.Components.Form.Inputs do

def render(assigns) do
~F"""
{#for {f, index} <- Enum.with_index(inputs_for(@form, @for || @field, @opts))}
<#slot {@default, form: f, index: index} context_put={Form, form: f}/>
{/for}
<.inputs_for :let={nested_form} field={@form[@for || @field]} {...@opts}>
<#slot {@default, form: nested_form, index: nested_form.index } context_put={Form, form: nested_form} />
</.inputs_for>
"""
end
end
4 changes: 2 additions & 2 deletions lib/surface/live_view_test.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule Surface.LiveViewTest do
import Phoenix.LiveView.Helpers, only: [live_component: 2, live_component: 3]
import Surface, only: [sigil_F: 2]
import Surface.LiveViewTest
require Phoenix.LiveView.HTMLEngine
require Phoenix.LiveView.TagEngine
end
end

Expand Down Expand Up @@ -61,7 +61,7 @@ defmodule Surface.LiveViewTest do
quote do
%{
__slot__: :inner_block,
inner_block: Phoenix.LiveView.HTMLEngine.inner_block(:inner_block, do: unquote(clauses))
inner_block: Phoenix.LiveView.TagEngine.inner_block(:inner_block, do: unquote(clauses))
}
end

Expand Down
10 changes: 6 additions & 4 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Surface.MixProject do
[
app: :surface,
version: @version,
elixir: "~> 1.12",
elixir: "~> 1.13",
description: "A component based library for Phoenix LiveView",
elixirc_paths: elixirc_paths(Mix.env()),
compilers: Mix.compilers(),
Expand All @@ -33,12 +33,14 @@ defmodule Surface.MixProject do
defp deps do
[
{:jason, "~> 1.0"},
{:phoenix_live_view, "~> 0.18.14"},
{:phoenix_live_view, "~> 0.18.18"},
{:phoenix, "~> 1.6.16"},
{:phoenix_html, "~> 3.3.1"},
{:floki, "~> 0.25.0", only: :test},
{:phoenix_ecto, "~> 4.0", only: :test},
{:sourceror, "~> 0.11"},
{:sourceror, "~> 1.0.0"},
{:ecto, "~> 3.4.2", only: :test},
{:phx_new, "~> 1.6.11", only: :test},
{:phx_new, "~> 1.6.16", only: :test},
{:ex_doc, ">= 0.28.5", only: :docs}
]
end
Expand Down
Loading

0 comments on commit 3fb33c2

Please sign in to comment.