Skip to content

Commit dfd1229

Browse files
committed
Upgrade to phoenix 1.7
1 parent ed7c6ef commit dfd1229

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2788
-2230
lines changed

README.md

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Petal Boilerplate
22

3-
A clean install of the latest Phoenix with some extras to get you started:
4-
- Tailwind CSS - using the [mix library](https://hexdocs.pm/tailwind/Tailwind.html)
3+
A clean install of the Phoenix 1.7 (RC) along with:
54
- Alpine JS - using a CDN to avoid needing `node_modules`
65
- 🌺 [Petal Components Library](https://github.com/petalframework/petal_components)
76

@@ -13,6 +12,21 @@ Optionally change your database name in `dev.exs`.
1312
2. Start Phoenix endpoint with `mix phx.server` or inside IEx with `iex -S mix phx.server`
1413
3. Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
1514

15+
## Phoenix 1.7 generators
16+
17+
The CRUD generators (eg. `mix phx.gen.live`) will produce code that doesn't quite work. Basically, they will use components defined in `core_components.ex` that we have renamed due to naming clashes with Petal Components.
18+
To fix, simply do a find and replace in the generated code:
19+
20+
```
21+
Replace `.modal` with `.phx_modal`
22+
Replace `.table` with `.phx_table`
23+
Replace `.button` with `.phx_button`
24+
```
25+
26+
This should make it work but it'll be using a different style of buttons/tables/modal to Petal Components. To work with Petal Components you will need to replace all buttons/tables/modal with the Petal Component versions.
27+
28+
Petal Pro currently comes with a generator to build CRUD interfaces with Petal Components. You can purchase it [here](https://petal.build/pro).
29+
1630
## Renaming your project
1731

1832
Your app module is currently called `PetalBoilerplate`. There is a script file included that will rename your project to anything you like in one go.

assets/css/app.css

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* This file is for your main application CSS */
21
@import "tailwindcss/base";
32
@import "./petal-components-enhancements.css";
43
@import "tailwindcss/components";

assets/js/app.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ let liveSocket = new LiveSocket("/live", Socket, {
4040

4141
// Show progress bar on live navigation and form submits
4242
topbar.config({ barColors: { 0: "#29d" }, shadowColor: "rgba(0, 0, 0, .3)" });
43-
window.addEventListener("phx:page-loading-start", (info) => topbar.show());
43+
window.addEventListener("phx:page-loading-start", (info) =>
44+
topbar.delayedShow(200)
45+
);
4446
window.addEventListener("phx:page-loading-stop", (info) => topbar.hide());
4547

4648
// connect if there are any LiveViews on the page

assets/tailwind.config.js

+29-5
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,48 @@
1+
// See the Tailwind configuration guide for advanced usage
2+
// https://tailwindcss.com/docs/configuration
3+
14
const colors = require("tailwindcss/colors");
5+
const plugin = require("tailwindcss/plugin");
26

37
module.exports = {
48
content: [
5-
"../lib/*_web/**/*.*ex",
69
"./js/**/*.js",
10+
"../lib/*_web.ex",
11+
"../lib/*_web/**/*.*ex",
712
"../deps/petal_components/**/*.*ex",
813
],
914
theme: {
1015
extend: {
1116
colors: {
17+
brand: "#FD4F00",
1218
primary: colors.blue,
1319
secondary: colors.pink,
1420
},
1521
},
1622
},
23+
darkMode: "class",
1724
plugins: [
18-
require("@tailwindcss/typography"),
1925
require("@tailwindcss/forms"),
20-
require("@tailwindcss/line-clamp"),
21-
require("@tailwindcss/aspect-ratio"),
26+
plugin(({ addVariant }) =>
27+
addVariant("phx-no-feedback", [".phx-no-feedback&", ".phx-no-feedback &"])
28+
),
29+
plugin(({ addVariant }) =>
30+
addVariant("phx-click-loading", [
31+
".phx-click-loading&",
32+
".phx-click-loading &",
33+
])
34+
),
35+
plugin(({ addVariant }) =>
36+
addVariant("phx-submit-loading", [
37+
".phx-submit-loading&",
38+
".phx-submit-loading &",
39+
])
40+
),
41+
plugin(({ addVariant }) =>
42+
addVariant("phx-change-loading", [
43+
".phx-change-loading&",
44+
".phx-change-loading &",
45+
])
46+
),
2247
],
23-
darkMode: "class",
2448
};

assets/vendor/topbar.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/**
22
* @license MIT
33
* topbar 1.0.0, 2021-01-06
4-
* https://buunguyen.github.io/topbar
4+
* Modifications:
5+
* - add delayedShow(time) (2022-09-21)
6+
* http://buunguyen.github.io/topbar
57
* Copyright (c) 2021 Buu Nguyen
68
*/
79
(function (window, document) {
@@ -35,10 +37,11 @@
3537
})();
3638

3739
var canvas,
38-
progressTimerId,
39-
fadeTimerId,
4040
currentProgress,
4141
showing,
42+
progressTimerId = null,
43+
fadeTimerId = null,
44+
delayTimerId = null,
4245
addEvent = function (elem, type, handler) {
4346
if (elem.addEventListener) elem.addEventListener(type, handler, false);
4447
else if (elem.attachEvent) elem.attachEvent("on" + type, handler);
@@ -95,6 +98,11 @@
9598
for (var key in opts)
9699
if (options.hasOwnProperty(key)) options[key] = opts[key];
97100
},
101+
delayedShow: function(time) {
102+
if (showing) return;
103+
if (delayTimerId) return;
104+
delayTimerId = setTimeout(() => topbar.show(), time);
105+
},
98106
show: function () {
99107
if (showing) return;
100108
showing = true;
@@ -125,6 +133,8 @@
125133
return currentProgress;
126134
},
127135
hide: function () {
136+
clearTimeout(delayTimerId);
137+
delayTimerId = null;
128138
if (!showing) return;
129139
showing = false;
130140
if (progressTimerId != null) {

config/config.exs

+18-17
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ config :petal_boilerplate,
1313
# Configures the endpoint
1414
config :petal_boilerplate, PetalBoilerplateWeb.Endpoint,
1515
url: [host: "localhost"],
16-
render_errors: [view: PetalBoilerplateWeb.ErrorView, accepts: ~w(html json), layout: false],
16+
render_errors: [
17+
formats: [html: PetalBoilerplateWeb.ErrorHTML, json: PetalBoilerplateWeb.ErrorJSON],
18+
layout: false
19+
],
1720
pubsub_server: PetalBoilerplate.PubSub,
18-
live_view: [signing_salt: "Fd8SWPu3"]
21+
live_view: [signing_salt: "Nwp6Nmtc"]
1922

2023
# Configures the mailer
2124
#
@@ -26,9 +29,6 @@ config :petal_boilerplate, PetalBoilerplateWeb.Endpoint,
2629
# at the `config/runtime.exs`.
2730
config :petal_boilerplate, PetalBoilerplate.Mailer, adapter: Swoosh.Adapters.Local
2831

29-
# Swoosh API client is needed for adapters other than SMTP.
30-
config :swoosh, :api_client, false
31-
3232
# Configure esbuild (the version is required)
3333
config :esbuild,
3434
version: "0.15.5",
@@ -39,6 +39,18 @@ config :esbuild,
3939
env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
4040
]
4141

42+
# Configure tailwind (the version is required)
43+
config :tailwind,
44+
version: "3.2.4",
45+
default: [
46+
args: ~w(
47+
--config=tailwind.config.js
48+
--input=css/app.css
49+
--output=../priv/static/assets/app.css
50+
),
51+
cd: Path.expand("../assets", __DIR__)
52+
]
53+
4254
# Configures Elixir's Logger
4355
config :logger, :console,
4456
format: "$time $metadata[$level] $message\n",
@@ -49,18 +61,7 @@ config :phoenix, :json_library, Jason
4961

5062
config :petal_components,
5163
:error_translator_function,
52-
{PetalBoilerplateWeb.ErrorHelpers, :translate_error}
53-
54-
config :tailwind,
55-
version: "3.1.8",
56-
default: [
57-
args: ~w(
58-
--config=tailwind.config.js
59-
--input=css/app.css
60-
--output=../priv/static/assets/app.css
61-
),
62-
cd: Path.expand("../assets", __DIR__)
63-
]
64+
{PetalBoilerplateWeb.CoreComponents, :translate_error}
6465

6566
# Import environment specific config. This must remain at the bottom
6667
# of this file so it overrides the configuration defined above.

config/dev.exs

+10-5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import Config
44
config :petal_boilerplate, PetalBoilerplate.Repo,
55
username: "postgres",
66
password: "postgres",
7-
database: "petal_boilerplate_dev",
87
hostname: "localhost",
8+
database: "petal_boilerplate_dev",
9+
stacktrace: true,
910
show_sensitive_data_on_connection_error: true,
1011
pool_size: 10
1112

@@ -22,7 +23,7 @@ config :petal_boilerplate, PetalBoilerplateWeb.Endpoint,
2223
check_origin: false,
2324
code_reloader: true,
2425
debug_errors: true,
25-
secret_key_base: "47TFd8fpLTZROcN4Lxz/OQ5fz4hVFMNCsSxHKwSrRGZGxDcWKyGH+1uxAtGYn1/Q",
26+
secret_key_base: "ukpF68Q3LDULmUU6dX+IvlxG+bCDjJpDNjAP04W5hwt6G6UraVzzZBWEtAvkxlUi",
2627
watchers: [
2728
esbuild: {Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]},
2829
tailwind: {Tailwind, :install_and_run, [:default, ~w(--watch)]}
@@ -36,7 +37,6 @@ config :petal_boilerplate, PetalBoilerplateWeb.Endpoint,
3637
#
3738
# mix phx.gen.cert
3839
#
39-
# Note that this task requires Erlang/OTP 20 or later.
4040
# Run `mix help phx.gen.cert` for more information.
4141
#
4242
# The `http:` config above can be replaced with:
@@ -58,11 +58,13 @@ config :petal_boilerplate, PetalBoilerplateWeb.Endpoint,
5858
patterns: [
5959
~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
6060
~r"priv/gettext/.*(po)$",
61-
~r"lib/petal_boilerplate_web/(live|views)/.*(ex)$",
62-
~r"lib/petal_boilerplate_web/templates/.*(eex)$"
61+
~r"lib/petal_boilerplate_web/(controllers|live|components)/.*(ex|heex)$"
6362
]
6463
]
6564

65+
# Enable dev routes for dashboard and mailbox
66+
config :petal_boilerplate, dev_routes: true
67+
6668
# Do not include metadata nor timestamps in development logs
6769
config :logger, :console, format: "[$level] $message\n"
6870

@@ -72,3 +74,6 @@ config :phoenix, :stacktrace_depth, 20
7274

7375
# Initialize plugs at runtime for faster development compilation
7476
config :phoenix, :plug_init_mode, :runtime
77+
78+
# Disable swoosh api client as it is only required for production adapters.
79+
config :swoosh, :api_client, false

config/prod.exs

+6-34
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Config
33
# For production, don't forget to configure the url host
44
# to something meaningful, Phoenix uses this information
55
# when generating URLs.
6-
#
6+
77
# Note we also include the path to a cache manifest
88
# containing the digested version of static files. This
99
# manifest is generated by the `mix phx.digest` task,
@@ -12,39 +12,11 @@ import Config
1212
config :petal_boilerplate, PetalBoilerplateWeb.Endpoint,
1313
cache_static_manifest: "priv/static/cache_manifest.json"
1414

15+
# Configures Swoosh API Client
16+
config :swoosh, :api_client, PetalBoilerplate.Finch
17+
1518
# Do not print debug messages in production
1619
config :logger, level: :info
1720

18-
# ## SSL Support
19-
#
20-
# To get SSL working, you will need to add the `https` key
21-
# to the previous section and set your `:url` port to 443:
22-
#
23-
# config :petal_boilerplate, PetalBoilerplateWeb.Endpoint,
24-
# ...,
25-
# url: [host: "example.com", port: 443],
26-
# https: [
27-
# ...,
28-
# port: 443,
29-
# cipher_suite: :strong,
30-
# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
31-
# certfile: System.get_env("SOME_APP_SSL_CERT_PATH")
32-
# ]
33-
#
34-
# The `cipher_suite` is set to `:strong` to support only the
35-
# latest and more secure SSL ciphers. This means old browsers
36-
# and clients may not be supported. You can set it to
37-
# `:compatible` for wider support.
38-
#
39-
# `:keyfile` and `:certfile` expect an absolute path to the key
40-
# and cert in disk or a relative path inside priv, for example
41-
# "priv/ssl/server.key". For all supported SSL configuration
42-
# options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1
43-
#
44-
# We also recommend setting `force_ssl` in your endpoint, ensuring
45-
# no data is ever sent via http, always redirecting to https:
46-
#
47-
# config :petal_boilerplate, PetalBoilerplateWeb.Endpoint,
48-
# force_ssl: [hsts: true]
49-
#
50-
# Check `Plug.SSL` for all available options in `force_ssl`.
21+
# Runtime production configuration, including reading
22+
# of environment variables, is done on config/runtime.exs.

config/runtime.exs

+41-11
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@ import Config
77
# any compile-time configuration in here, as it won't be applied.
88
# The block below contains prod specific runtime configuration.
99

10-
# Start the phoenix server if environment is set and running in a release
11-
if System.get_env("PHX_SERVER") && System.get_env("RELEASE_NAME") do
12-
config :petal_boilerplate, PetalBoilerplate.Endpoint, server: true
10+
# ## Using releases
11+
#
12+
# If you use `mix release`, you need to explicitly enable the server
13+
# by passing the PHX_SERVER=true when you start it:
14+
#
15+
# PHX_SERVER=true bin/petal_boilerplate start
16+
#
17+
# Alternatively, you can use `mix phx.gen.release` to generate a `bin/server`
18+
# script that automatically sets the env var above.
19+
if System.get_env("PHX_SERVER") do
20+
config :petal_boilerplate, PetalBoilerplateWeb.Endpoint, server: true
1321
end
1422

1523
if config_env() == :prod do
@@ -44,26 +52,48 @@ if config_env() == :prod do
4452
port = String.to_integer(System.get_env("PORT") || "4000")
4553

4654
config :petal_boilerplate, PetalBoilerplateWeb.Endpoint,
47-
url: [host: host, port: 443],
55+
url: [host: host, port: 443, scheme: "https"],
4856
http: [
4957
# Enable IPv6 and bind on all interfaces.
50-
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
58+
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
5159
# See the documentation on https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html
5260
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
5361
ip: {0, 0, 0, 0, 0, 0, 0, 0},
5462
port: port
5563
],
5664
secret_key_base: secret_key_base
5765

58-
# ## Using releases
66+
# ## SSL Support
5967
#
60-
# If you are doing OTP releases, you need to instruct Phoenix
61-
# to start each relevant endpoint:
68+
# To get SSL working, you will need to add the `https` key
69+
# to your endpoint configuration:
6270
#
63-
# config :petal_boilerplate, PetalBoilerplateWeb.Endpoint, server: true
71+
# config :petal_boilerplate, PetalBoilerplateWeb.Endpoint,
72+
# https: [
73+
# ...,
74+
# port: 443,
75+
# cipher_suite: :strong,
76+
# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
77+
# certfile: System.get_env("SOME_APP_SSL_CERT_PATH")
78+
# ]
6479
#
65-
# Then you can assemble a release by calling `mix release`.
66-
# See `mix help release` for more information.
80+
# The `cipher_suite` is set to `:strong` to support only the
81+
# latest and more secure SSL ciphers. This means old browsers
82+
# and clients may not be supported. You can set it to
83+
# `:compatible` for wider support.
84+
#
85+
# `:keyfile` and `:certfile` expect an absolute path to the key
86+
# and cert in disk or a relative path inside priv, for example
87+
# "priv/ssl/server.key". For all supported SSL configuration
88+
# options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1
89+
#
90+
# We also recommend setting `force_ssl` in your endpoint, ensuring
91+
# no data is ever sent via http, always redirecting to https:
92+
#
93+
# config :petal_boilerplate, PetalBoilerplateWeb.Endpoint,
94+
# force_ssl: [hsts: true]
95+
#
96+
# Check `Plug.SSL` for all available options in `force_ssl`.
6797

6898
# ## Configuring the mailer
6999
#

0 commit comments

Comments
 (0)