Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert owner view to components/html #1243

Merged
merged 2 commits into from
Feb 19, 2024
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
51 changes: 51 additions & 0 deletions lib/ex338_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ defmodule Ex338Web do
end
end

def controller_html do
quote do
use Phoenix.Controller,
formats: [:html, :json],
layouts: [html: {Ex338Web.LayoutView, :app}]

import Ecto
import Ecto.Query
import Ex338Web.Gettext
import Phoenix.LiveView.Controller
import Plug.Conn

alias Ex338.Repo

unquote(verified_routes())
end
end

def view do
quote do
use Phoenix.View,
Expand Down Expand Up @@ -111,6 +129,39 @@ defmodule Ex338Web do
end
end

def html do
quote do
use Phoenix.Component

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

# include while migrating to Phoenix.Component
import Phoenix.View

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

defp html_helpers do
quote do
# HTML escaping functionality
# Core UI components and translation
import Ex338Web.CoreComponents
import Ex338Web.Gettext
import Ex338Web.ViewHelpers
import Phoenix.HTML

# Shortcut for generating JS commands
alias Phoenix.LiveView.JS

# Routes generation with the ~p sigil
unquote(verified_routes())
end
end

def verified_routes do
quote do
use Phoenix.VerifiedRoutes,
Expand Down
Loading
Loading