Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import Config

config :esbuild,
version: "0.12.18",
version: "0.25.4",
default: [
args: ~w(js/app.js --bundle --target=es2016 --outdir=../priv/static/assets),
args:
~w(js/app.js --bundle --target=es2022 --outdir=../priv/static/assets/js --external:/fonts/* --external:/images/* --alias:@=.),
cd: Path.expand("../assets", __DIR__),
env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
env: %{"NODE_PATH" => [Path.expand("../deps", __DIR__), Mix.Project.build_path()]}
]

config :dart_sass,
version: "1.61.0",
default: [
args: ~w(css/app.scss ../priv/static/assets/app.css),
args: ~w(css/app.scss ../priv/static/assets/css/app.css),
cd: Path.expand("../assets", __DIR__)
]

Expand All @@ -27,12 +28,17 @@ config :logger, :console,

# Configures the endpoint
config :todo_app, TodoWeb.Endpoint,
# url: [host: "localhost", port: 10_000 + :rand.uniform(45_000)],
# because of the iOS rebind - this is now a fixed port, but randomly selected
http: [ip: {127, 0, 0, 1}, port: 10_000 + :rand.uniform(45_000)],
render_errors: [view: TodoWeb.ErrorView, accepts: ~w(html json), layout: false],
adapter: Bandit.PhoenixAdapter,
render_errors: [
formats: [html: TodoWeb.ErrorHTML, json: TodoWeb.ErrorJSON],
layout: false
],
pubsub_server: TodoApp.PubSub,
live_view: [signing_salt: "sWpG9ljX"],
secret_key_base: :crypto.strong_rand_bytes(32),
secret_key_base: :crypto.strong_rand_bytes(64),
server: true

config :phoenix, :json_library, Jason
Expand Down
16 changes: 13 additions & 3 deletions lib/todo_app.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,24 @@ defmodule TodoApp do
Desktop.identify_default_locale(TodoWeb.Gettext)
File.mkdir_p!(config_dir())

# TODO: move to runtime.exs
Application.put_env(:todo_app, TodoApp.Repo,
database: Path.join(config_dir(), "/database.sq3")
)

{:ok, sup} = Supervisor.start_link([TodoApp.Repo], name: __MODULE__, strategy: :one_for_one)
TodoApp.Repo.initialize()
:ets.new(:session, [:named_table, :public, read_concurrency: true])

{:ok, _} = Supervisor.start_child(sup, TodoWeb.Sup)
{:ok, sup} = Supervisor.start_link([
TodoWeb.Telemetry,
TodoApp.Repo,
{DNSCluster, query: Application.get_env(:todo, :dns_cluster_query) || :ignore},
{Phoenix.PubSub, name: TodoApp.PubSub},
# Start a worker by calling: Todo.Worker.start_link(arg)
# {Todo.Worker, arg},
# Start to serve requests, typically the last entry
TodoWeb.Endpoint
], name: __MODULE__, strategy: :one_for_one)
TodoApp.Repo.initialize()

{:ok, _} =
Supervisor.start_child(sup, {
Expand Down
10 changes: 5 additions & 5 deletions lib/todo_app/menu_bar.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ defmodule TodoApp.MenuBar do
<item
type="checkbox" onclick={"toggle:#{item.id}"}
checked={item.status == "done"}
><%= item.text %></item>
>{item.text}</item>
<% end %>
<hr/>
<item onclick="quit"><%= gettext "Quit" %></item>
<item onclick="quit">{gettext "Quit"}</item>
</menu>
<menu label={gettext "Extra"}>
<item onclick="notification"><%= gettext "Show Notification" %></item>
<item onclick="observer"><%= gettext "Show Observer" %></item>
<item onclick="browser"><%= gettext "Open Browser" %></item>
<item onclick="notification">{gettext "Show Notification"}</item>
<item onclick="observer">{gettext "Show Observer"}</item>
<item onclick="browser">{gettext "Open Browser"}</item>
</menu>
</menubar>
"""
Expand Down
89 changes: 48 additions & 41 deletions lib/todo_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,84 +17,91 @@ defmodule TodoWeb do
and import those modules here.
"""

def controller do
def static_paths, do: ~w(assets fonts images favicon.ico robots.txt)

def router do
quote do
use Phoenix.Controller, namespace: TodoWeb
use Phoenix.Router, helpers: false

# Import common connection and controller functions to use in pipelines
import Plug.Conn
use Gettext, backend: TodoWeb.Gettext
alias TodoWeb.Router.Helpers, as: Routes
import Phoenix.Controller
import Phoenix.LiveView.Router
end
end

def view do
def channel do
quote do
use Phoenix.View,
root: "lib/todo_web/templates",
namespace: TodoWeb
use Phoenix.Channel
end
end

# Import convenience functions from controllers
import Phoenix.Controller,
only: [view_module: 1, view_template: 1]
def controller do
quote do
use Phoenix.Controller, formats: [:html, :json]

use Gettext, backend: TodoWeb.Gettext

alias Phoenix.Flash
import Plug.Conn

# Include shared imports and aliases for views
unquote(view_helpers())
alias TodoWeb.Router.Helpers, as: Routes
unquote(verified_routes())
end
end

def live_view do
quote do
use Phoenix.LiveView,
layout: {TodoWeb.LayoutView, :live}
use Phoenix.LiveView

unquote(view_helpers())
alias TodoWeb.Router.Helpers, as: Routes
unquote(html_helpers())
end
end

def live_component do
quote do
use Phoenix.LiveComponent

unquote(view_helpers())
alias TodoWeb.Router.Helpers, as: Routes
unquote(html_helpers())
end
end

def router do
def html do
quote do
use Phoenix.Router
use Phoenix.Component

import Plug.Conn
import Phoenix.Controller
import Phoenix.LiveView.Router
# Import convenience functions from controllers
import Phoenix.Controller,
only: [get_csrf_token: 0, view_module: 1, view_template: 1]

# Include general helpers for rendering HTML
unquote(html_helpers())
end
end

def channel do
defp html_helpers do
quote do
use Phoenix.Channel
# Translation
use Gettext, backend: TodoWeb.Gettext
end
end

defp view_helpers do
quote do
# Use all HTML functionality (forms, tags, etc)
use Phoenix.HTML
# HTML escaping functionality
import Phoenix.HTML
# Core UI components
import TodoWeb.CoreComponents

# Import LiveView helpers (live_render, live_component, live_patch, etc)
import Phoenix.LiveView.Helpers
import Phoenix.Component
# Common modules used in templates
alias Phoenix.LiveView.JS
alias TodoWeb.Layouts

# Import basic rendering functionality (render, render_layout, etc)
import Phoenix.View
# Routes generation with the ~p sigil
unquote(verified_routes())
end
end

import TodoWeb.ErrorHelpers
use Gettext, backend: TodoWeb.Gettext
def verified_routes do
quote do
use Phoenix.VerifiedRoutes,
endpoint: TodoWeb.Endpoint,
router: TodoWeb.Router,
statics: TodoWeb.static_paths()
end
end

Expand Down
Loading
Loading