Skip to content

Commit 9068e67

Browse files
authored
Merge pull request #1435 from naymspace/feature/phoenix-1.8
Support Phoenix 1.8
2 parents 87c254d + ba06279 commit 9068e67

File tree

25 files changed

+158
-57
lines changed

25 files changed

+158
-57
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ RUN yarn install --pure-lockfile
6464
COPY demo/assets assets/
6565
COPY demo/lib lib/
6666

67+
RUN mix compile
6768
RUN mix assets.deploy
6869

6970
# Copy the rest of the application files

demo/assets/css/app.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@import "tailwindcss";
22

3-
@plugin "./tailwind_heroicons.js";
3+
@plugin "../vendor/heroicons";
44

55
@plugin "daisyui" {
66
themes: all;

demo/assets/js/app.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as Sentry from '@sentry/browser'
33
import topbar from 'topbar'
44
import { Socket } from 'phoenix'
55
import { LiveSocket } from 'phoenix_live_view'
6+
import { hooks as colocatedHooks } from 'phoenix-colocated/demo'
67
// in your app.js, just use 'backpex' like this:
78
// import { Hooks as BackpexHooks } from 'backpex'
89
import { Hooks as BackpexHooks } from '#backpex'
@@ -34,7 +35,7 @@ const csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute
3435

3536
const liveSocket = new LiveSocket('/live', Socket, {
3637
params: { _csrf_token: csrfToken },
37-
hooks: { ...BackpexHooks }
38+
hooks: { ...BackpexHooks, ...colocatedHooks }
3839
})
3940

4041
liveSocket.connect()
@@ -43,3 +44,38 @@ liveSocket.connect()
4344
* Globals
4445
*/
4546
window.liveSocket = liveSocket
47+
48+
// The lines below enable quality of life phoenix_live_reload
49+
// development features:
50+
//
51+
// 1. stream server logs to the browser console
52+
// 2. click on elements to jump to their definitions in your code editor
53+
//
54+
if (process.env.NODE_ENV === 'development') {
55+
window.addEventListener('phx:live_reload:attached', ({ detail: reloader }) => {
56+
// Enable server log streaming to client.
57+
// Disable with reloader.disableServerLogs()
58+
reloader.enableServerLogs()
59+
60+
// Open configured PLUG_EDITOR at file:line of the clicked element's HEEx component
61+
//
62+
// * click with "c" key pressed to open at caller location
63+
// * click with "d" key pressed to open at function component definition location
64+
let keyDown
65+
window.addEventListener('keydown', function (e) { keyDown = e.key })
66+
window.addEventListener('keyup', function (e) { keyDown = null })
67+
window.addEventListener('click', function (e) {
68+
if (keyDown === 'c') {
69+
e.preventDefault()
70+
e.stopImmediatePropagation()
71+
reloader.openEditorAtCaller(e.target)
72+
} else if (keyDown === 'd') {
73+
e.preventDefault()
74+
e.stopImmediatePropagation()
75+
reloader.openEditorAtDef(e.target)
76+
}
77+
}, true)
78+
79+
window.liveReloader = reloader
80+
})
81+
}

demo/assets/tsconfig.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": ".",
4+
"allowJs": true,
5+
"noEmit": true
6+
},
7+
"include": [
8+
"js/**/*"
9+
]
10+
}
File renamed without changes.

demo/config/config.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ config :tailwind,
6666
cd: Path.expand("..", __DIR__)
6767
]
6868

69-
config :logger, :console,
69+
config :logger, :default_formatter,
7070
format: "$time $metadata[$level] $message\n",
7171
metadata: [:request_id]
7272

demo/config/dev.exs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,17 @@ config :demo, DemoWeb.Endpoint,
2222
],
2323
live_reload: [
2424
patterns: [
25-
~r"demo/priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
26-
~r"demo/priv/gettext/.*(po)$",
27-
~r"demo/lib/demo_web/helpers.ex$",
28-
~r"demo/lib/demo_web/(live|views)/.*(ex)$",
29-
~r"demo/lib/demo_web/templates/.*(eex)$",
30-
~r"lib/backpex/(fields|html)/.*(ex)$",
31-
~r"priv/static/js/.*(js)$"
25+
~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
26+
~r"priv/gettext/.*(po)$",
27+
~r"lib/demo_web/(?:controllers|live|components|router)/?.*\.(ex|heex)$",
28+
~r"lib/backpex/(fields|html)/.*(ex)$"
3229
]
3330
],
3431
force_ssl: [hsts: true],
3532
http: [port: 4000],
3633
reloadable_apps: [:demo, :backpex]
3734

38-
config :logger, :console, format: "[$level] $message\n"
35+
config :logger, :default_formatter, format: "[$level] $message\n"
3936

4037
config :phoenix, :stacktrace_depth, 20
4138

demo/lib/demo_web.ex

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ defmodule DemoWeb do
3838

3939
def controller do
4040
quote do
41-
use Phoenix.Controller,
42-
formats: [:html, :json],
43-
layouts: [html: DemoWeb.Layouts]
41+
use Phoenix.Controller, formats: [:html, :json]
4442

4543
use Gettext, backend: DemoWeb.Gettext
4644

@@ -50,16 +48,9 @@ defmodule DemoWeb do
5048
end
5149
end
5250

53-
def live_view(opts \\ []) do
51+
def live_view do
5452
quote do
55-
@opts Keyword.merge(
56-
[
57-
layout: {DemoWeb.Layouts, :app},
58-
container: {:div, class: "h-full"}
59-
],
60-
unquote(opts)
61-
)
62-
use Phoenix.LiveView, @opts
53+
use Phoenix.LiveView
6354

6455
unquote(html_helpers())
6556
end
@@ -94,7 +85,8 @@ defmodule DemoWeb do
9485
# Core UI components and translation
9586
import DemoWeb.CoreComponents
9687

97-
# Shortcut for generating JS commands
88+
# Common modules used in templates
89+
alias DemoWeb.Layouts
9890
alias Phoenix.LiveView.JS
9991

10092
# Routes generation with the ~p sigil

demo/lib/demo_web/components/layouts.ex

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,12 @@ defmodule DemoWeb.Layouts do
33
use DemoWeb, :html
44

55
embed_templates "layouts/*"
6+
7+
attr :flash, :map, required: true, doc: "the map of flash messages"
8+
attr :fluid?, :boolean, default: true, doc: "if the content uses full width"
9+
attr :current_url, :string, required: true, doc: "the current url"
10+
11+
slot :inner_block, required: true
12+
13+
def admin(assigns)
614
end

demo/lib/demo_web/components/layouts/admin.html.heex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,5 @@
9393
</Backpex.HTML.Layout.sidebar_section>
9494
</:sidebar>
9595
<Backpex.HTML.Layout.flash_messages flash={@flash} />
96-
{@inner_content}
96+
{render_slot(@inner_block)}
9797
</Backpex.HTML.Layout.app_shell>

0 commit comments

Comments
 (0)