Skip to content

Commit

Permalink
Merge pull request #288 from aesmail/better-version-check
Browse files Browse the repository at this point in the history
Remove deprecation warnings
  • Loading branch information
aesmail authored Sep 9, 2023
2 parents 9aaed6c + f171d9e commit 52929be
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 24 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
otp: ['22', '23', '24', '25']
elixir: ['1.11.4', '1.12.3', '1.13.4', '1.14.5', '1.15.5']
elixir: ['1.12.3', '1.13.4', '1.14.5', '1.15.5']
# Exclude invalid combinations of Elixir and OTP
exclude:
- otp: '22'
Expand All @@ -22,8 +22,6 @@ jobs:
elixir: '1.15.5'
- otp: '23'
elixir: '1.15.5'
- otp: '25'
elixir: '1.11.4'
- otp: '25'
elixir: '1.12.3'
- otp: '25'
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixes
- Crash when updating records.
- Removes elixir and phoenix deprecation warnings [PR#288](https://github.com/aesmail/kaffy/pull/288)

### Added
- Support for filtering `{:array, :string}` fields [PR#285](https://github.com/aesmail/kaffy/pull/262)
Expand Down
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,18 @@ If you or your company wants to sponsor the development of Kaffy, please reach o

## Minimum Requirements

- Elixir 1.11.4
- Phoenix 1.5.0
Starting with v0.10.0, Kaffy will officially support the latest two phoenix versions.

We aim to follow Elixir's [support policy](https://hexdocs.pm/elixir/compatibility-and-deprecations.html) for the minimum required Elixir version.
| Kaffy | Supported phoenix versions |
|---------|----------------------------|
| v0.10.0 | 1.6, 1.7 |
| v0.9.X | 1.5, 1.6, 1.7 |
| | |


## Support Policy

The latest released `major.minor` version will be supported. For example, if the latest version is `0.9.0`, then `0.9.1` will be released with bug fixes. If a new version `0.10.0` is released, then `0.9.1` will no longer receive bug fixes or security patches.

## Installation

Expand Down
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 @@ -482,4 +489,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 @@ -130,7 +130,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 @@ -149,11 +149,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
16 changes: 15 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,20 @@ 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), do: conn.assigns.flash

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
6 changes: 3 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ defmodule Kaffy.MixProject do
[
app: :kaffy,
version: @version,
elixir: "~> 1.11",
compilers: [:phoenix] ++ Mix.compilers(),
elixir: "~> 1.12",
compilers: Mix.compilers(),
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
description: description(),
Expand All @@ -35,7 +35,7 @@ defmodule Kaffy.MixProject do
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:phoenix, "~> 1.5"},
{:phoenix, "~> 1.6"},
{:phoenix_html, "~> 3.0"},
{:phoenix_view, "~> 2.0.2"},
{:mock, "~> 0.3.3", only: :test},
Expand Down
10 changes: 5 additions & 5 deletions test/actions_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule ActionsTest do
use ExUnit.Case
use Phoenix.ConnTest
import Phoenix.ConnTest

import Mock
alias Phoenix.Controller, as: PhoenixController
Expand Down Expand Up @@ -164,7 +164,7 @@ defmodule ActionsTest do
"id" => "id"
})

assert %{"success" => _} = get_flash(result_conn)
assert %{"success" => _} = KaffyWeb.LayoutView.get_flash(result_conn)
end
end

Expand All @@ -178,7 +178,7 @@ defmodule ActionsTest do
"id" => "id"
})

assert %{"success" => _} = get_flash(result_conn)
assert %{"success" => _} = KaffyWeb.LayoutView.get_flash(result_conn)
end
end

Expand All @@ -192,7 +192,7 @@ defmodule ActionsTest do
"id" => "1:1"
})

assert %{"success" => _} = get_flash(result_conn)
assert %{"success" => _} = KaffyWeb.LayoutView.get_flash(result_conn)
end
end

Expand All @@ -207,7 +207,7 @@ defmodule ActionsTest do
"id" => "1:1,1:2"
})

assert %{"success" => _} = get_flash(result_conn)
assert %{"success" => _} = KaffyWeb.LayoutView.get_flash(result_conn)
end
end
end
3 changes: 2 additions & 1 deletion test/kaffy/resource_form_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ defmodule Kaffy.ResourceFormTest do
field_opts = Keyword.get(opts, :field_opts, %{})

changeset = Ecto.Changeset.change(schema, %{})
form = Phoenix.HTML.Form.form_for(:dummy, "/")

form = Phoenix.HTML.FormData.to_form(changeset.changes, as: :dummy)
ast = ResourceForm.form_field(changeset, form, {name, field_opts})

case ast do
Expand Down

0 comments on commit 52929be

Please sign in to comment.