Skip to content

Commit

Permalink
Release 0.4.0 (#111)
Browse files Browse the repository at this point in the history
* Ensure correct order of theme menu items

* Remove unused

* Remove Ecto dependency
  • Loading branch information
ArthurClemens authored Aug 13, 2023
1 parent ff3d1e7 commit d467da2
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 42 deletions.
23 changes: 21 additions & 2 deletions lib/helpers/attribute_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,28 @@ defmodule PrimerLive.Helpers.AttributeHelpers do
end

@doc """
Generates a random string.
From: https://gist.github.com/ahmadshah/8d978bbc550128cca12dd917a09ddfb7?permalink_comment_id=4178225#gistcomment-4178225
A helper functions to generate a random (printable) string of given `len`.
You could change the hard-coded ascii codes 32 and 126 to only
uppercase letters, digits, etc...
"""
def random_string(), do: Ecto.UUID.generate()
def random_string(len \\ 12) when is_integer(len) and len > 0 do
(for _ <- 1..len, do: rand_uniform(32, 126))
|> List.to_string()
end

# Returns a random integer uniformly distributed in the range
# `n <= X <= m`.
#
# If the random variable `X` is uniformly distributed in the range
# `1 <= X <= m - n + 1`, then r.v `Y = X + n - 1` is uniformly
# distributed in the range `n <= Y <= m`.
# (Because we just shift X to the right).
defp rand_uniform(n, m) do
:rand.uniform(m - n + 1) # random X
|> Kernel.+(n - 1) # shift X to the right to get Y
end

@doc """
Verifies if a slot should be handled as a link.
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/form_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ defmodule PrimerLive.Helpers.FormHelpers do
...> })
%Ecto.Changeset{action: nil, changes: %{}, errors: [], data: nil, valid?: false}
"""
def form_changeset(%Phoenix.HTML.Form{source: %Ecto.Changeset{}} = form) do
def form_changeset(%Phoenix.HTML.Form{source: _} = form) do
form.source
end

Expand Down
35 changes: 0 additions & 35 deletions lib/helpers/schema_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,6 @@ defmodule PrimerLive.Helpers.SchemaHelpers do

use Phoenix.Component

import Ecto.Changeset

@doc """
Validates a changeset by verifying that at least one of the keys is present.
```
changeset |> validate_one_of_present(attrs, [:toggle, :menu, :option, :divider])
```
"""

def validate_one_of_present(changeset, attrs, keys) do
attr_keys = Map.keys(attrs)

in_list_count =
keys
|> Enum.reduce(0, fn key, acc ->
case Enum.member?(attr_keys, key) do
true -> acc + 1
false -> acc
end
end)

case in_list_count == 0 do
true ->
add_error(
changeset,
:dropdown_item,
"must contain one attribute from these options: #{keys |> Enum.join(", ")}"
)

false ->
changeset
end
end

@doc """
Validates attribute `form`.
Allowed values:
Expand Down
10 changes: 10 additions & 0 deletions lib/theme/theme.ex
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ defmodule PrimerLive.Theme do
|> Enum.map(&move_options_to_field/1)
|> Enum.map(&add_selected_state(&1, theme))
|> Enum.map(&add_labels(&1, menu_labels))
|> Enum.sort_by(fn {key, _item} ->
order =
case key do
:color_mode -> 0
:light_theme -> 1
:dark_theme -> 2
end

order
end)
end

defp move_options_to_field({key, options}) do
Expand Down
13 changes: 9 additions & 4 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ defmodule PrimerLive.MixProject do
aliases: aliases(),
name: "PrimerLive",
deps: deps(),
docs: docs()
docs: docs(),
elixirc_paths: elixirc_paths(Mix.env())
]
end

# Specifies which paths to compile per environment.
defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]

defp description() do
"A collection of function components that implements GitHub's Primer Design System."
end
Expand All @@ -30,11 +35,11 @@ defmodule PrimerLive.MixProject do
defp deps do
[
{:credo, "~> 1.7", only: [:dev, :test], runtime: false},
{:ecto, "~> 3.10", only: [:dev, :test], runtime: false},
{:ecto_sql, "~> 3.10", only: [:dev, :test], runtime: false},
{:ecto, "~> 3.10", only: :test, runtime: false},
{:ecto_sql, "~> 3.10", only: :test, runtime: false},
{:esbuild, "~> 0.7", only: :dev},
{:ex_doc, "~> 0.30", only: :dev},
{:phoenix_ecto, "~> 4.4", only: [:dev, :test], runtime: false},
{:phoenix_ecto, "~> 4.4", only: :test, runtime: false},
{:phoenix_html, "~> 3.3"},
{:phoenix_live_view, "~> 0.19"},
{:jason, "~> 1.4"}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit d467da2

Please sign in to comment.