Skip to content

Commit

Permalink
remove deprecation warnings, remove support for phx1.4 layout.
Browse files Browse the repository at this point in the history
  • Loading branch information
aesmail committed Sep 9, 2023
1 parent 6104735 commit b6d10be
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
16 changes: 14 additions & 2 deletions lib/kaffy/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,15 @@ defmodule Kaffy.Utils do
"""
@spec get_version_of(atom()) :: String.t()
def get_version_of(package) do
{:ok, version} = :application.get_key(package, :vsn)
to_string(version)
case package do
:elixir ->
System.version()

_ ->
{:ok, version} = :application.get_key(package, :vsn)
version
end
|> to_string()
end

@doc """
Expand Down Expand Up @@ -469,4 +476,9 @@ defmodule Kaffy.Utils do
def visible?(options) do
Keyword.get(options, :in_menu, true)
end

def version_match?(app, version) do
get_version_of(app)
|> Version.match?(version)
end
end
8 changes: 2 additions & 6 deletions lib/kaffy_web/templates/layout/app.html.eex
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
<div class="content-wrapper">
<%= if get_flash(@conn, :success) do %>
<div class="alert alert-success">
<i class="fa fa-check"></i><strong>Success: </strong> <%= get_flash(@conn, :success) %>
<i class="fa fa-check"></i><strong>Success: </strong> <%= get_flash(@conn, :success) %>
</div>
<% end %>
<%= if get_flash(@conn, :info) do %>
Expand All @@ -146,11 +146,7 @@
</div>
<% end %>

<%= if Kaffy.Utils.phoenix_version?("1.4.") do %>
<%= render(@view_module, @view_template, assigns) %>
<% else %>
<%= @inner_content %>
<% end %>
<%= @inner_content %>
</div>

<footer class="footer">
Expand Down
14 changes: 13 additions & 1 deletion lib/kaffy_web/views/layout_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ defmodule KaffyWeb.LayoutView do
root: "lib/kaffy_web/templates",
namespace: KaffyWeb

import Phoenix.Controller, only: [get_flash: 2]
use Phoenix.HTML

def get_flash(conn, key) do
[mod, func, args] =
cond do
Kaffy.Utils.version_match?(:phoenix, "~> 1.7") ->
[Phoenix.Flash, :get, [conn.assigns.flash, key]]

true ->
[Phoenix.Controller, :get_flash, [conn, key]]
end

apply(mod, func, args)
end
end
10 changes: 9 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ defmodule Kaffy.MixProject do
@version "0.10.0-rc.1"

def project do
elixir_version = System.version()

included_compilers =
cond do
Version.match?(elixir_version, "~> 1.13") -> []
true -> [:phoenix]
end

[
app: :kaffy,
version: @version,
elixir: "~> 1.11",
compilers: [:phoenix] ++ Mix.compilers(),
compilers: included_compilers ++ Mix.compilers(),
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
description: description(),
Expand Down

0 comments on commit b6d10be

Please sign in to comment.