Skip to content

Commit

Permalink
[gh315] Changes for Phoenix 1.7 Web
Browse files Browse the repository at this point in the history
  • Loading branch information
byhbt committed Mar 8, 2023
1 parent 1fcfaaa commit fb5d81b
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 80 deletions.
2 changes: 1 addition & 1 deletion lib/nimble_template/addons/variants/phoenix/oban.ex
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ defmodule NimbleTemplate.Addons.Phoenix.Oban do
Generator.inject_content!(
"config/test.exs",
"""
config :logger, level: :warn
config :logger, level: :warning
""",
"""
Expand Down
24 changes: 13 additions & 11 deletions lib/nimble_template/addons/variants/phoenix/web/dart_sass.ex
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,16 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.DartSass do
"mix.exs",
"""
"assets.deploy": [
"esbuild app --minify",
"tailwind default --minify",
"esbuild default --minify",
"cmd npm run postcss --prefix assets",
"phx.digest"
]
""",
"""
"assets.deploy": [
"esbuild app --minify",
"tailwind default --minify",
"esbuild default --minify",
"sass app --no-source-map --style=compressed",
"cmd npm run postcss --prefix assets",
"phx.digest"
Expand All @@ -94,15 +96,15 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.DartSass do
end

defp edit_app_js!(project) do
Generator.delete_content!(
"assets/js/app.js",
"""
// We import the CSS which is extracted to its own file by esbuild.
// Remove this line if you add a your own CSS build pipeline (e.g postcss).
import "../css/app.css"
"""
)
# Generator.delete_content!(
# "assets/js/app.js",
# """
# // We import the CSS which is extracted to its own file by esbuild.
# // Remove this line if you add a your own CSS build pipeline (e.g postcss).
# import "../css/app.css"

# """
# )

project
end
Expand Down
29 changes: 0 additions & 29 deletions lib/nimble_template/addons/variants/phoenix/web/es_lint.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,10 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.EsLint do
|> copy_files!()
end

def edit_app_js!(%Project{live_project?: true} = project) do
update_topbar_js_variables!()

project
end

def edit_app_js!(%Project{web_project?: true} = project) do
update_topbar_js_variables!()

project
end

def edit_app_js!(project), do: project

defp edit_files!(%Project{} = project) do
project
|> edit_assets_package!()
|> edit_mix!()
|> edit_app_js!()
end

defp copy_files!(%Project{} = project) do
Expand Down Expand Up @@ -91,18 +76,4 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.EsLint do

project
end

defp update_topbar_js_variables! do
Generator.replace_content!(
"assets/js/app.js",
"window.addEventListener(\"phx:page-loading-start\", info => topbar.show())",
"window.addEventListener(\"phx:page-loading-start\", _info => topbar.show())"
)

Generator.replace_content!(
"assets/js/app.js",
"window.addEventListener(\"phx:page-loading-stop\", info => topbar.hide())",
"window.addEventListener(\"phx:page-loading-stop\", _info => topbar.hide())"
)
end
end
27 changes: 10 additions & 17 deletions lib/nimble_template/addons/variants/phoenix/web/heex_formatter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,17 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.HeexFormatter do

@impl true
def do_apply!(%Project{} = project, _opts) do
Generator.replace_content!(".formatter.exs", "\"*.{ex,exs}\"", "\"*.{heex,ex,exs}\"")

Generator.replace_content!(
".formatter.exs",
"\"{config,lib,test}/**/*.{ex,exs}\"",
"\"{config,lib,test}/**/*.{heex,ex,exs}\""
)

Generator.replace_content!(
".formatter.exs",
"""
import_deps: [:ecto, :phoenix],
""",
"""
import_deps: [:ecto, :phoenix],
plugins: [Phoenix.LiveView.HTMLFormatter],
"""
)
# Generator.replace_content!(
# ".formatter.exs",
# """
# import_deps: [:ecto, :phoenix],
# """,
# """
# import_deps: [:ecto, :phoenix],
# plugins: [Phoenix.LiveView.HTMLFormatter],
# """
# )

project
end
Expand Down
5 changes: 3 additions & 2 deletions lib/nimble_template/addons/variants/phoenix/web/post_css.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.PostCSS do
Generator.replace_content!(
"mix.exs",
"""
"assets.deploy": ["esbuild app --minify", "phx.digest"]
"assets.deploy": ["tailwind default --minify", "esbuild default --minify", "phx.digest"]
""",
"""
"assets.deploy": [
"esbuild app --minify",
"tailwind default --minify",
"esbuild default --minify",
"cmd npm run postcss --prefix assets",
"phx.digest"
]
Expand Down
8 changes: 4 additions & 4 deletions lib/nimble_template/addons/variants/phoenix/web/svg_sprite.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ defmodule NimbleTemplate.Addons.Phoenix.Web.SvgSprite do
Generator.replace_content!(
"#{web_path}.ex",
"""
# Include shared imports and aliases for views
unquote(view_helpers())
# Include general helpers for rendering HTML
unquote(html_helpers())
""",
"""
import #{web_module}.IconHelper
# Include shared imports and aliases for views
unquote(view_helpers())
# Include general helpers for rendering HTML
unquote(html_helpers())
"""
)

Expand Down
5 changes: 1 addition & 4 deletions lib/nimble_template/templates/variants/phoenix/template.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ defmodule NimbleTemplate.Templates.Phoenix.Template do

defp apply_phoenix_common_setup(%Project{} = project) do
# TODO: Remove me after the Phoenix generator fix releases: https://github.com/phoenixframework/phoenix/pull/4894
remove_mix_compiler_config!()
# remove_mix_compiler_config!()

project
|> apply_default_common_phoenix_addons()
Expand Down Expand Up @@ -142,7 +142,4 @@ defmodule NimbleTemplate.Templates.Phoenix.Template do

defp apply_phoenix_variant_setup(%Project{web_project?: true, live_project?: true} = project),
do: LiveTemplate.apply!(project)

defp remove_mix_compiler_config!(),
do: Generator.delete_content!("mix.exs", "compilers: [:gettext] ++ Mix.compilers(),")
end
7 changes: 4 additions & 3 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%{
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"},
"castore": {:hex, :castore, "1.0.0", "c25cd0794c054ebe6908a86820c8b92b5695814479ec95eeff35192720b71eec", [:mix], [], "hexpm", "577d0e855983a97ca1dfa33cbb8a3b6ece6767397ffb4861514343b078fc284b"},
"castore": {:hex, :castore, "1.0.1", "240b9edb4e9e94f8f56ab39d8d2d0a57f49e46c56aced8f873892df8ff64ff5a", [:mix], [], "hexpm", "b4951de93c224d44fac71614beabd88b71932d0b1dea80d2f80fb9044e01bbb3"},
"certifi": {:hex, :certifi, "2.9.0", "6f2a475689dd47f19fb74334859d460a2dc4e3252a3324bd2111b8f0429e7e21", [:rebar3], [], "hexpm", "266da46bdb06d6c6d35fde799bcb28d36d985d424ad7c08b5bb48f5b5cdd4641"},
"credo": {:hex, :credo, "1.6.3", "0a9f8925dbc8f940031b789f4623fc9a0eea99d3eed600fe831e403eb96c6a83", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "1167cde00e6661d740fc54da2ee268e35d3982f027399b64d3e2e83af57a1180"},
"earmark_parser": {:hex, :earmark_parser, "1.4.30", "0b938aa5b9bafd455056440cdaa2a79197ca5e693830b4a982beada840513c5f", [:mix], [], "hexpm", "3b5385c2d36b0473d0b206927b841343d25adb14f95f0110062506b300cd5a1b"},
Expand All @@ -19,14 +19,15 @@
"mimic": {:hex, :mimic, "1.7.4", "cd2772ffbc9edefe964bc668bfd4059487fa639a5b7f1cbdf4fd22946505aa4f", [:mix], [], "hexpm", "437c61041ecf8a7fae35763ce89859e4973bb0666e6ce76d75efc789204447c3"},
"nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"},
"parse_trans": {:hex, :parse_trans, "3.3.1", "16328ab840cc09919bd10dab29e431da3af9e9e7e7e6f0089dd5a2d2820011d8", [:rebar3], [], "hexpm", "07cd9577885f56362d414e8c4c4e6bdf10d43a8767abb92d24cbe8b24c54888b"},
"phoenix": {:hex, :phoenix, "1.7.0", "cbed113bdc203e2ced75859011fe7e71eeebb6259cefa54de810d9c7048b5e22", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.4", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "8526139d4bd79ec97c5c3c8e69f6cd663597f782756cec874ba7da5429c93e34"},
"phoenix": {:hex, :phoenix, "1.7.1", "a029bde19d9c3b559e5c3d06c78b76e81396bedd456a6acedb42f9c7b2e535a9", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.4", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "ea9d4a85c3592e37efa07d0dc013254fda445885facaefddcbf646375c116457"},
"phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.1", "ba04e489ef03763bf28a17eb2eaddc2c20c6d217e2150a61e3298b0f4c2012b5", [:mix], [], "hexpm", "81367c6d1eea5878ad726be80808eb5a787a23dee699f96e72b1109c57cdd8d9"},
"phoenix_template": {:hex, :phoenix_template, "1.0.1", "85f79e3ad1b0180abb43f9725973e3b8c2c3354a87245f91431eec60553ed3ef", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "157dc078f6226334c91cb32c1865bf3911686f8bcd6bcff86736f6253e6993ee"},
"phoenix_view": {:hex, :phoenix_view, "1.1.2", "1b82764a065fb41051637872c7bd07ed2fdb6f5c3bd89684d4dca6e10115c95a", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "7ae90ad27b09091266f6adbb61e1d2516a7c3d7062c6789d46a7554ec40f3a56"},
"plug": {:hex, :plug, "1.14.0", "ba4f558468f69cbd9f6b356d25443d0b796fbdc887e03fa89001384a9cac638f", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "bf020432c7d4feb7b3af16a0c2701455cbbbb95e5b6866132cb09eb0c29adc14"},
"plug_crypto": {:hex, :plug_crypto, "1.2.3", "8f77d13aeb32bfd9e654cb68f0af517b371fb34c56c9f2b58fe3df1235c1251a", [:mix], [], "hexpm", "b5672099c6ad5c202c45f5a403f21a3411247f164e4a8fab056e5cd8a290f4a2"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
"websock": {:hex, :websock, "0.4.3", "184ac396bdcd3dfceb5b74c17d221af659dd559a95b1b92041ecb51c9b728093", [:mix], [], "hexpm", "5e4dd85f305f43fd3d3e25d70bec4a45228dfed60f0f3b072d8eddff335539cf"},
"websock": {:hex, :websock, "0.5.0", "f6bbce90226121d62a0715bca7c986c5e43de0ccc9475d79c55381d1796368cc", [:mix], [], "hexpm", "b51ac706df8a7a48a2c622ee02d09d68be8c40418698ffa909d73ae207eb5fb8"},
"websock_adapter": {:hex, :websock_adapter, "0.4.5", "30038a3715067f51a9580562c05a3a8d501126030336ffc6edb53bf57d6d2d26", [:mix], [{:bandit, "~> 0.6", [hex: :bandit, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:websock, "~> 0.4", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "1d9812dc7e703c205049426fd4fe0852a247a825f91b099e53dc96f68bafe4c8"},
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,13 @@ defmodule <%= web_module %>.IconHelper do

use Phoenix.HTML

alias <%= web_module %>.Router.Helpers, as: Routes

@svg_shape_id_prefix "icon-priv--static--images--icons--"

def icon_tag(conn, icon_file_name, opts \\ []) do
classes = "icon " <> Keyword.get(opts, :class, "")

icon_link = {~p"/images/icon-sprite.svg#" <> @svg_shape_id_prefix <> icon_file_name}
content_tag(:svg, class: classes) do
tag(:use,
"xlink:href":
Routes.static_path(
conn,
"/images/icon-sprite.svg#" <> @svg_shape_id_prefix <> icon_file_name
)
tag(:use, "xlink:href": icon_link
)
end
end
Expand Down

0 comments on commit fb5d81b

Please sign in to comment.