Skip to content

Commit 54bd909

Browse files
committed
fix warnings on Elixir 1.19-dev
1 parent 3b4f773 commit 54bd909

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ jobs:
2222
- elixir: 1.14.5
2323
otp: 25.3.2.9
2424

25+
- elixir: 1.15.x
26+
otp: 25.x
27+
2528
- elixir: 1.17.3
26-
otp: 27.1
29+
otp: 27.2
2730
lint: true
2831
installer: true
2932

guides/contexts.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ Next we can create the template at `lib/hello_web/controllers/cart_html/show.htm
957957
<.back navigate={~p"/products"}>Back to products</.back>
958958
```
959959

960-
We started by showing the empty cart message if our preloaded `cart.items` is empty. If we have items, we use the `simple_form` component provided by our `HelloWeb.CoreComponents` to take our cart changeset that we assigned in the `CartController.show/2` action and create a form which maps to our cart controller `update/2` action. Within the form, we use the [`inputs_for`](`Phoenix.Component.inputs_for/1`) component to render inputs for the nested cart items. This will allow us to map item inputs back together when the form is submitted. Next, we display a number input for the item quantity and label it with the product title. We finish the item form by converting the item price to string. We haven't written the `ShoppingCart.total_item_price/1` function yet, but again we employed the idea of clear, descriptive public interfaces for our contexts. After rendering inputs for all the cart items, we show an "update cart" submit button, along with the total price of the entire cart. This is accomplished with another new `ShoppingCart.total_cart_price/1` function which we'll implement in a moment. Finally, we added a `back` component to go back to our products page.
960+
We started by showing the empty cart message if our preloaded `cart.items` is empty. If we have items, we use the `simple_form` component provided by our `HelloWeb.CoreComponents` to take our cart changeset that we assigned in the `CartController.show/2` action and create a form which maps to our cart controller `update/2` action. Within the form, we use the [`inputs_for`](https://hexdocs.pm/phoenix_live_view/Phoenix.Component.html#inputs_for/1) component to render inputs for the nested cart items. This will allow us to map item inputs back together when the form is submitted. Next, we display a number input for the item quantity and label it with the product title. We finish the item form by converting the item price to string. We haven't written the `ShoppingCart.total_item_price/1` function yet, but again we employed the idea of clear, descriptive public interfaces for our contexts. After rendering inputs for all the cart items, we show an "update cart" submit button, along with the total price of the entire cart. This is accomplished with another new `ShoppingCart.total_cart_price/1` function which we'll implement in a moment. Finally, we added a `back` component to go back to our products page.
961961

962962
We're almost ready to try out our cart page, but first we need to implement our new currency calculation functions. Open up your shopping cart context at `lib/hello/shopping_cart.ex` and add these new functions:
963963

@@ -1027,7 +1027,7 @@ Head back over to your shopping cart context in `lib/hello/shopping_cart.ex` and
10271027
end
10281028
```
10291029

1030-
We started much like how our out-of-the-box code started – we take the cart struct and cast the user input to a cart changeset, except this time we use `Ecto.Changeset.cast_assoc/3` to cast the nested item data into `CartItem` changesets. Remember the [`<.inputs_for />`](`Phoenix.Component.inputs_for/1`) call in our cart form template? That hidden ID data is what allows Ecto's `cast_assoc` to map item data back to existing item associations in the cart. Next we use `Ecto.Multi.new/0`, which you may not have seen before. Ecto's `Multi` is a feature that allows lazily defining a chain of named operations to eventually execute inside a database transaction. Each operation in the multi chain receives the values from the previous steps and executes until a failed step is encountered. When an operation fails, the transaction is rolled back and an error is returned, otherwise the transaction is committed.
1030+
We started much like how our out-of-the-box code started – we take the cart struct and cast the user input to a cart changeset, except this time we use `Ecto.Changeset.cast_assoc/3` to cast the nested item data into `CartItem` changesets. Remember the [`<.inputs_for />`](https://hexdocs.pm/phoenix_live_view/Phoenix.Component.html#inputs_for/1) call in our cart form template? That hidden ID data is what allows Ecto's `cast_assoc` to map item data back to existing item associations in the cart. Next we use `Ecto.Multi.new/0`, which you may not have seen before. Ecto's `Multi` is a feature that allows lazily defining a chain of named operations to eventually execute inside a database transaction. Each operation in the multi chain receives the values from the previous steps and executes until a failed step is encountered. When an operation fails, the transaction is rolled back and an error is returned, otherwise the transaction is committed.
10311031

10321032
For our multi operations, we start by issuing an update of our cart, which we named `:cart`. After the cart update is issued, we perform a multi `delete_all` operation, which takes the updated cart and applies our zero-quantity logic. We prune any items in the cart with zero quantity by returning an ecto query that finds all cart items for this cart with an empty quantity. Calling `Repo.transaction/1` with our multi will execute the operations in a new transaction and we return the success or failure result to the caller just like the original function.
10331033

lib/phoenix/naming.ex

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ defmodule Phoenix.Naming do
2525
|> underscore()
2626
end
2727

28+
# TODO: remove conditional once we require Elixir 1.15 for existing apps
29+
if Version.match?(System.version(), ">= 1.15.0") do
30+
defmacrop maybe_pin(name) do
31+
quote do
32+
^unquote(name)
33+
end
34+
end
35+
else
36+
defmacrop maybe_pin(name) do
37+
quote do
38+
unquote(name)
39+
end
40+
end
41+
end
42+
2843
@doc """
2944
Removes the given suffix from the name if it exists.
3045
@@ -43,7 +58,8 @@ defmodule Phoenix.Naming do
4358
suffix_size = byte_size(suffix)
4459
prefix_size = byte_size(string) - suffix_size
4560
case string do
46-
<<prefix::binary-size(prefix_size), ^suffix::binary>> -> prefix
61+
# TODO: replace maybe_pin with ^prefix_size once we require Elixir 1.15 for existing apps
62+
<<prefix::binary-size(maybe_pin(prefix_size)), ^suffix::binary>> -> prefix
4763
_ -> string
4864
end
4965
end

mix.exs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ defmodule Phoenix.MixProject do
2323
elixir: @elixir_requirement,
2424
deps: deps(),
2525
package: package(),
26-
preferred_cli_env: [docs: :docs],
2726
consolidate_protocols: Mix.env() != :test,
2827
xref: [
2928
exclude: [
@@ -47,6 +46,12 @@ defmodule Phoenix.MixProject do
4746
]
4847
end
4948

49+
def cli do
50+
[
51+
preferred_envs: [docs: :docs]
52+
]
53+
end
54+
5055
defp elixirc_paths(:docs), do: ["lib", "installer/lib"]
5156
defp elixirc_paths(_), do: ["lib"]
5257

@@ -124,12 +129,12 @@ defmodule Phoenix.MixProject do
124129
main: "overview",
125130
logo: "logo.png",
126131
extra_section: "GUIDES",
127-
assets: "guides/assets",
132+
assets: %{"guides/assets" => "assets"},
128133
formatters: ["html", "epub"],
129134
groups_for_modules: groups_for_modules(),
130135
extras: extras(),
131136
groups_for_extras: groups_for_extras(),
132-
groups_for_functions: [
137+
groups_for_docs: [
133138
Reflection: &(&1[:type] == :reflection)
134139
],
135140
skip_undefined_reference_warnings_on: ["CHANGELOG.md"]

0 commit comments

Comments
 (0)