Skip to content

Commit

Permalink
Update to latest Phoenix 1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyalIcing committed Feb 27, 2023
1 parent 36d2e00 commit f8155da
Show file tree
Hide file tree
Showing 33 changed files with 963 additions and 13,230 deletions.
6 changes: 4 additions & 2 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[
import_deps: [:phoenix],
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}"]
import_deps: [:ecto, :phoenix],
subdirectories: ["priv/*/migrations"],
plugins: [Phoenix.LiveView.HTMLFormatter],
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"]
]
13,169 changes: 45 additions & 13,124 deletions assets/package-lock.json

Large diffs are not rendered by default.

96 changes: 96 additions & 0 deletions lib/components_guide/content.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,100 @@ defmodule ComponentsGuide.Content do
Cachex.del(@cache_name, id)
end
end

alias ComponentsGuide.Content.Text2

@doc """
Returns the list of texts2.
## Examples
iex> list_texts2()
[%Text2{}, ...]
"""
def list_texts2 do
Repo.all(Text2)
end

@doc """
Gets a single text2.
Raises `Ecto.NoResultsError` if the Text2 does not exist.
## Examples
iex> get_text2!(123)
%Text2{}
iex> get_text2!(456)
** (Ecto.NoResultsError)
"""
def get_text2!(id), do: Repo.get!(Text2, id)

@doc """
Creates a text2.
## Examples
iex> create_text2(%{field: value})
{:ok, %Text2{}}
iex> create_text2(%{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def create_text2(attrs \\ %{}) do
%Text2{}
|> Text2.changeset(attrs)
|> Repo.insert()
end

@doc """
Updates a text2.
## Examples
iex> update_text2(text2, %{field: new_value})
{:ok, %Text2{}}
iex> update_text2(text2, %{field: bad_value})
{:error, %Ecto.Changeset{}}
"""
def update_text2(%Text2{} = text2, attrs) do
text2
|> Text2.changeset(attrs)
|> Repo.update()
end

@doc """
Deletes a text2.
## Examples
iex> delete_text2(text2)
{:ok, %Text2{}}
iex> delete_text2(text2)
{:error, %Ecto.Changeset{}}
"""
def delete_text2(%Text2{} = text2) do
Repo.delete(text2)
end

@doc """
Returns an `%Ecto.Changeset{}` for tracking text2 changes.
## Examples
iex> change_text2(text2)
%Ecto.Changeset{data: %Text2{}}
"""
def change_text2(%Text2{} = text2, attrs \\ %{}) do
Text2.changeset(text2, attrs)
end
end
17 changes: 17 additions & 0 deletions lib/components_guide/content/text2.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
defmodule ComponentsGuide.Content.Text2 do
use Ecto.Schema
import Ecto.Changeset

embedded_schema do
field :content, :string

timestamps()
end

@doc false
def changeset(text2, attrs) do
text2
|> cast(attrs, [:content])
|> validate_required([:content])
end
end
36 changes: 32 additions & 4 deletions lib/components_guide_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ defmodule ComponentsGuideWeb do
and import those modules here.
"""

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

def controller do
quote do
use Phoenix.Controller, namespace: ComponentsGuideWeb
Expand All @@ -25,6 +27,30 @@ defmodule ComponentsGuideWeb do
import ComponentsGuideWeb.Gettext
import Phoenix.LiveView.Controller
alias ComponentsGuideWeb.Router.Helpers, as: Routes

unquote(verified_routes())
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 general helpers for rendering HTML
unquote(html_helpers())
end
end

def verified_routes do
quote do
use Phoenix.VerifiedRoutes,
endpoint: ComponentsGuideWeb.Endpoint,
router: ComponentsGuideWeb.Router,
statics: ComponentsGuideWeb.static_paths()
end
end

Expand Down Expand Up @@ -57,7 +83,7 @@ defmodule ComponentsGuideWeb do
quote do
@opts Keyword.merge(
[
layout: {ComponentsGuideWeb.LayoutView, "live.html"},
layout: {ComponentsGuideWeb.LayoutView, :live},
container: {:div, class: "relative h-screen flex overflow-hidden"}
],
unquote(opts)
Expand Down Expand Up @@ -99,12 +125,12 @@ defmodule ComponentsGuideWeb do
use Phoenix.HTML

# Import LiveView helpers (live_render, live_component, live_patch, etc)
import Phoenix.LiveView.Helpers
import Phoenix.Component

# Import basic rendering functionality (render, render_layout, etc)
import Phoenix.View
# import Phoenix.View

import ComponentsGuideWeb.ErrorHelpers
import ComponentsGuideWeb.CoreComponents
import ComponentsGuideWeb.Gettext
alias ComponentsGuideWeb.Router.Helpers, as: Routes

Expand All @@ -117,6 +143,8 @@ defmodule ComponentsGuideWeb do
alias ComponentsGuideWeb.FormattingHelpers, as: Format
# alias ComponentsGuideWeb.PrimitiveHelpers, as: Primitives

unquote(verified_routes())

# def dev_inspect(value) do
# content_tag("pre", inspect(value, pretty: true))
# end
Expand Down
Loading

0 comments on commit f8155da

Please sign in to comment.