Skip to content

Commit fe23af7

Browse files
authored
improvement: install with daisyUI overrides if using daisyUI (#650)
1 parent 959c127 commit fe23af7

File tree

4 files changed

+40
-15
lines changed

4 files changed

+40
-15
lines changed

dev/dev_web/router.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ defmodule DevWeb.Router do
3535

3636
magic_sign_in_route(Example.Accounts.User, :magic_link,
3737
auth_routes_prefix: "/auth",
38-
overrides: [DevWeb.AuthOverrides, AshAuthentication.Phoenix.Overrides.Default]
38+
overrides: [DevWeb.AuthOverrides, AshAuthentication.Phoenix.Overrides.DaisyUI]
3939
)
4040

4141
sign_in_route(
4242
path: "/sign-in",
43-
overrides: [DevWeb.AuthOverrides, AshAuthentication.Phoenix.Overrides.Default],
43+
overrides: [DevWeb.AuthOverrides, AshAuthentication.Phoenix.Overrides.DaisyUI],
4444
auth_routes_prefix: "/auth"
4545
)
4646

dev/dev_web/templates/layout/root.html.heex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
<.live_title>
99
{assigns[:page_title] || "Dev"}
1010
</.live_title>
11-
<script defer src="https://cdn.tailwindcss.com">
11+
<link href="https://cdn.jsdelivr.net/npm/daisyui@5" rel="stylesheet" type="text/css" />
12+
<script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4">
1213
</script>
1314
<script type="module" crossorigin>
1415
import 'https://cdn.jsdelivr.net/gh/phoenixframework/[email protected]/priv/static/phoenix_html.js';

lib/mix/tasks/ash_authentication_phoenix.install.ex

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,13 @@ if Code.ensure_loaded?(Igniter) do
146146
with {_, _source, zipper} <- Igniter.Project.Module.find_module!(igniter, router),
147147
{:ok, zipper} <- Igniter.Code.Common.move_to_do_block(zipper),
148148
:error <- Igniter.Code.Module.move_to_use(zipper, AshAuthentication.Phoenix.Router) do
149+
override_module =
150+
if Igniter.exists?(igniter, "assets/vendor/daisyui.js") do
151+
AshAuthentication.Phoenix.Overrides.DaisyUI
152+
else
153+
AshAuthentication.Phoenix.Overrides.Default
154+
end
155+
149156
igniter
150157
|> use_authentication_phoenix_router(router)
151158
|> Igniter.Libs.Phoenix.append_to_pipeline(:browser, "plug :load_from_session",
@@ -165,22 +172,22 @@ if Code.ensure_loaded?(Igniter) do
165172
166173
# Remove these if you'd like to use your own authentication views
167174
sign_in_route register_path: "/register", reset_path: "/reset", auth_routes_prefix: "/auth", on_mount: [{#{inspect(web_module)}.LiveUserAuth, :live_no_user}],
168-
overrides: [#{inspect(overrides)}, AshAuthentication.Phoenix.Overrides.Default]
175+
overrides: [#{inspect(overrides)}, #{override_module}]
169176
170177
# Remove this if you do not want to use the reset password feature
171-
reset_route auth_routes_prefix: "/auth", overrides: [#{inspect(overrides)}, AshAuthentication.Phoenix.Overrides.Default]
178+
reset_route auth_routes_prefix: "/auth", overrides: [#{inspect(overrides)}, #{override_module}]
172179
173180
# Remove this if you do not use the confirmation strategy
174181
confirm_route #{inspect(options[:user])},
175182
:confirm_new_user,
176183
auth_routes_prefix: "/auth",
177-
overrides: [#{inspect(overrides)}, AshAuthentication.Phoenix.Overrides.Default]
184+
overrides: [#{inspect(overrides)}, #{override_module}]
178185
179186
# Remove this if you do not use the magic link strategy.
180187
magic_sign_in_route #{inspect(options[:user])},
181188
:magic_link,
182189
auth_routes_prefix: "/auth",
183-
overrides: [#{inspect(overrides)}, AshAuthentication.Phoenix.Overrides.Default]
190+
overrides: [#{inspect(overrides)}, #{override_module}]
184191
""",
185192
with_pipelines: [:browser],
186193
arg2: Igniter.Libs.Phoenix.web_module(igniter),

test/mix/tasks/ash_authentication_phoenix.install_test.exs

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# credo:disable-for-this-file Credo.Check.Design.AliasUsage
22
defmodule Mix.Tasks.AshAuthenticationPhoenix.InstallTest do
3-
use ExUnit.Case
3+
use ExUnit.Case, parameterize: [%{daisy_ui: true}, %{daisy_ui: false}]
44
@moduletag :igniter
55

66
import Igniter.Test
77

8-
setup do
8+
setup context do
99
igniter =
1010
test_project()
11+
|> maybe_add_daisy_ui(context)
1112
|> Igniter.Project.Deps.add_dep({:simple_sat, ">= 0.0.0"})
1213
|> Igniter.Project.Deps.add_dep({:ash_authentication, ">= 0.0.0"})
1314
|> Igniter.Project.Formatter.add_formatter_plugin(Spark.Formatter)
@@ -32,7 +33,14 @@ defmodule Mix.Tasks.AshAuthenticationPhoenix.InstallTest do
3233
""")
3334
|> apply_igniter!()
3435

35-
[igniter: igniter]
36+
base_override =
37+
if context.daisy_ui do
38+
AshAuthentication.Phoenix.Overrides.DaisyUI
39+
else
40+
AshAuthentication.Phoenix.Overrides.Default
41+
end
42+
43+
[igniter: igniter, base_override: base_override]
3644
end
3745

3846
test "installation is idempotent", %{igniter: igniter} do
@@ -196,7 +204,10 @@ defmodule Mix.Tasks.AshAuthenticationPhoenix.InstallTest do
196204
""")
197205
end
198206

199-
test "installation modifies the router", %{igniter: igniter} do
207+
test "installation modifies the router", %{
208+
igniter: igniter,
209+
base_override: base_override
210+
} do
200211
igniter
201212
|> Igniter.compose_task("ash_authentication_phoenix.install")
202213
|> assert_has_patch("lib/test_web/router.ex", """
@@ -241,27 +252,33 @@ defmodule Mix.Tasks.AshAuthenticationPhoenix.InstallTest do
241252
+ | reset_path: "/reset",
242253
+ | auth_routes_prefix: "/auth",
243254
+ | on_mount: [{TestWeb.LiveUserAuth, :live_no_user}],
244-
+ | overrides: [TestWeb.AuthOverrides, AshAuthentication.Phoenix.Overrides.Default]
255+
+ | overrides: [TestWeb.AuthOverrides, #{base_override}]
245256
+ | )
246257
+ |
247258
+ | # Remove this if you do not want to use the reset password feature
248259
+ | reset_route(
249260
+ | auth_routes_prefix: "/auth",
250-
+ | overrides: [TestWeb.AuthOverrides, AshAuthentication.Phoenix.Overrides.Default]
261+
+ | overrides: [TestWeb.AuthOverrides, #{base_override}]
251262
+ | )
252263
+ |
253264
+ | # Remove this if you do not use the confirmation strategy
254265
+ | confirm_route(Test.Accounts.User, :confirm_new_user,
255266
+ | auth_routes_prefix: "/auth",
256-
+ | overrides: [TestWeb.AuthOverrides, AshAuthentication.Phoenix.Overrides.Default]
267+
+ | overrides: [TestWeb.AuthOverrides, #{base_override}]
257268
+ | )
258269
+ |
259270
+ | # Remove this if you do not use the magic link strategy.
260271
+ | magic_sign_in_route(Test.Accounts.User, :magic_link,
261272
+ | auth_routes_prefix: "/auth",
262-
+ | overrides: [TestWeb.AuthOverrides, AshAuthentication.Phoenix.Overrides.Default]
273+
+ | overrides: [TestWeb.AuthOverrides, #{base_override}]
263274
+ | )
264275
+ | end
265276
""")
266277
end
278+
279+
defp maybe_add_daisy_ui(igniter, %{daisy_ui: true}) do
280+
Igniter.create_new_file(igniter, "assets/vendor/daisyui.js", "")
281+
end
282+
283+
defp maybe_add_daisy_ui(igniter, _), do: igniter
267284
end

0 commit comments

Comments
 (0)