Skip to content

Commit 9a78244

Browse files
authored
[WIP] Crude changes to support liveview 1.x (#59)
Requires phoenix 1.7.10 and liveview 1.x. - sigil_e is deprecated - Module.eval_quoted is deprecated
1 parent 3c6fe53 commit 9a78244

4 files changed

Lines changed: 19 additions & 27 deletions

File tree

lib/desktop/endpoint.ex

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,9 @@ defmodule Desktop.Endpoint do
1717
end
1818
end
1919

20-
if Version.match?(:phoenix |> Application.spec(:vsn) |> List.to_string(), "~> 1.7.10") do
21-
def get_dynamic_port(scheme) do
22-
{:ok, {_ip, port}} = server_info(scheme)
23-
port
24-
end
25-
else
26-
# Supports only cowboy adapter for phoenix
27-
def get_dynamic_port(scheme) do
28-
ref = Module.safe_concat(__MODULE__, scheme |> Atom.to_string() |> String.upcase())
29-
:ranch.get_port(ref)
30-
end
20+
def get_dynamic_port(scheme) do
21+
{:ok, {_ip, port}} = server_info(scheme)
22+
port
3123
end
3224
end
3325
end

lib/desktop/menu.ex

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ defmodule Desktop.Menu do
2828
2929
@impl true
3030
def render(assigns) do
31-
~E\"""
31+
~H\"""
3232
<menubar>
33-
<menu label="<%= gettext "File" %>">
34-
<item onclick="open"><%= gettext "Open" %></item>
33+
<menu label={gettext "File"}>
34+
<item onclick="open">{gettext "Open"}</item>
3535
<hr/>
36-
<item onclick="quit"><%= gettext "Quit" %></item>
36+
<item onclick="quit">{gettext "Quit"}</item>
3737
</menu>
38-
<menu label="<%= gettext "Items" %>">
38+
<menu label={gettext "Items"}>
3939
<%= for item <- @items do %>
40-
<item><%= item.name %></item>
40+
<item>{item.name}</item>
4141
<% end %>
4242
</menu>
43-
<menu label="<%= gettext "Help" %>">
44-
<item onclick="help"><%= gettext "Show Documentation" %></item>
45-
<item onclick="about"><%= gettext "About" %></item>
43+
<menu label={gettext "Help"}>
44+
<item onclick="help">{gettext "Show Documentation"}</item>
45+
<item onclick="about">{gettext "About"}</item>
4646
</menu>
4747
</menubar>
4848
\"""
@@ -143,7 +143,6 @@ defmodule Desktop.Menu do
143143
quote do
144144
@behaviour Desktop.Menu
145145
import Desktop.Menu, only: [assign: 2, assign: 3, assign_new: 3, connected?: 1]
146-
import Phoenix.HTML, only: [sigil_e: 2, sigil_E: 2]
147146
import Phoenix.LiveView.Helpers, only: [sigil_L: 2, sigil_H: 2]
148147
alias Desktop.Menu
149148

@@ -153,7 +152,6 @@ defmodule Desktop.Menu do
153152
quote do
154153
@behaviour Desktop.Menu
155154
import Desktop.Menu, only: [assign: 2, assign: 3, assign_new: 3, connected?: 1]
156-
import Phoenix.HTML, only: [sigil_e: 2, sigil_E: 2]
157155
import Phoenix.LiveView.Helpers, only: [sigil_L: 2]
158156
import Phoenix.Component, only: [sigil_H: 2]
159157
alias Desktop.Menu

lib/desktop/wx.ex

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# TODO: less stringy metaprogramming
12
defmodule Desktop.Wx do
23
@moduledoc """
34
Elixir version of the constants found in the wx.hrl file, reduced to what is needed in this sample only.
@@ -25,11 +26,12 @@ defmodule Desktop.Wx do
2526
)
2627

2728
for wx_constant <- @constants do
28-
Module.eval_quoted(
29-
__MODULE__,
29+
Code.eval_quoted(
3030
Code.string_to_quoted("""
3131
def wx#{wx_constant}, do: :desktop_wx.get(:wx#{wx_constant})
32-
""")
32+
"""),
33+
[],
34+
module: __MODULE__
3335
)
3436
end
3537
end

mix.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ defmodule Desktop.MixProject do
8383
# {:ex_sni, path: "../ex_sni"},
8484

8585
# Phoenix & Plug
86-
{:phoenix, "> 1.0.0"},
87-
{:phoenix_live_view, "> 0.15.0"},
86+
{:phoenix, "> 1.7.10"},
87+
{:phoenix_live_view, "> 1.0.0"},
8888
{:plug, "> 1.0.0"},
8989
{:gettext, "> 0.10.0"}
9090
]

0 commit comments

Comments
 (0)