Current section
48 Versions
Jump to
Current section
48 Versions
Compare versions
6
files changed
+119
additions
-16
deletions
| @@ -1,9 +1,9 @@ | |
| 1 1 | {<<"links">>, |
| 2 2 | [{<<"GitHub">>,<<"https://github.com/ArthurClemens/primer_live">>}]}. |
| 3 3 | {<<"name">>,<<"primer_live">>}. |
| 4 | - {<<"version">>,<<"0.4.0">>}. |
| 4 | + {<<"version">>,<<"0.4.1">>}. |
| 5 5 | {<<"description">>, |
| 6 | - <<"A collection of function components that implements GitHub's Primer Design System.">>}. |
| 6 | + <<"An implementation of GitHub's Primer Design System for Phoenix LiveView.">>}. |
| 7 7 | {<<"app">>,<<"primer_live">>}. |
| 8 8 | {<<"licenses">>,[<<"MIT">>]}. |
| 9 9 | {<<"files">>, |
| @@ -12,7 +12,11 @@ | |
| 12 12 | <<"lib/helpers/form_helpers.ex">>,<<"lib/helpers/attribute_helpers.ex">>, |
| 13 13 | <<"lib/helpers/octicons_helper.ex">>,<<"lib/helpers/schema_helpers.ex">>, |
| 14 14 | <<"lib/helpers/component_helpers.ex">>, |
| 15 | - <<"lib/helpers/declaration_helpers.ex">>, |
| 15 | + <<"lib/helpers/declaration_helpers.ex">>,<<"lib/helpers/test_helpers">>, |
| 16 | + <<"lib/helpers/test_helpers/test_helpers.ex">>, |
| 17 | + <<"lib/helpers/test_helpers/todos">>, |
| 18 | + <<"lib/helpers/test_helpers/todos/todos.ex">>, |
| 19 | + <<"lib/helpers/test_helpers/todos/todo.ex">>, |
| 16 20 | <<"lib/helpers/prompt_declaration_helpers.ex">>,<<"lib/ui_icons.ex">>, |
| 17 21 | <<"lib/octicons.ex">>,<<".formatter.exs">>,<<"mix.exs">>,<<"README.md">>, |
| 18 22 | <<"LICENSE.md">>,<<"priv/octicon_builder/build.exs">>,<<"priv/static">>, |
| @@ -23,7 +27,12 @@ | |
| 23 27 | <<"priv/static/index.d.ts">>,<<"priv/static/primer-live.esm.js.map">>, |
| 24 28 | <<"CHANGELOG.md">>,<<"package.json">>]}. |
| 25 29 | {<<"requirements">>, |
| 26 | - [[{<<"name">>,<<"phoenix_html">>}, |
| 30 | + [[{<<"name">>,<<"ecto">>}, |
| 31 | + {<<"app">>,<<"ecto">>}, |
| 32 | + {<<"optional">>,false}, |
| 33 | + {<<"requirement">>,<<"~> 3.10">>}, |
| 34 | + {<<"repository">>,<<"hexpm">>}], |
| 35 | + [{<<"name">>,<<"phoenix_html">>}, |
| 27 36 | {<<"app">>,<<"phoenix_html">>}, |
| 28 37 | {<<"optional">>,false}, |
| 29 38 | {<<"requirement">>,<<"~> 3.3">>}, |
| @@ -317,7 +317,7 @@ defmodule PrimerLive.Helpers.AttributeHelpers do | |
| 317 317 | uppercase letters, digits, etc... |
| 318 318 | """ |
| 319 319 | def random_string(len \\ 12) when is_integer(len) and len > 0 do |
| 320 | - (for _ <- 1..len, do: rand_uniform(32, 126)) |
| 320 | + for(_ <- 1..len, do: rand_uniform(32, 126)) |
| 321 321 | |> List.to_string() |
| 322 322 | end |
| 323 323 | |
| @@ -329,8 +329,10 @@ defmodule PrimerLive.Helpers.AttributeHelpers do | |
| 329 329 | # distributed in the range `n <= Y <= m`. |
| 330 330 | # (Because we just shift X to the right). |
| 331 331 | defp rand_uniform(n, m) do |
| 332 | - :rand.uniform(m - n + 1) # random X |
| 333 | - |> Kernel.+(n - 1) # shift X to the right to get Y |
| 332 | + # random X |
| 333 | + :rand.uniform(m - n + 1) |
| 334 | + # shift X to the right to get Y |
| 335 | + |> Kernel.+(n - 1) |
| 334 336 | end |
| 335 337 | |
| 336 338 | @doc """ |
| @@ -960,7 +962,8 @@ defmodule PrimerLive.Helpers.AttributeHelpers do | |
| 960 962 | touch_layer_attrs = |
| 961 963 | append_attributes([ |
| 962 964 | ["data-touch": ""], |
| 963 | - !is_nil(assigns[:phx_click_touch]) && !is_modal && ["phx-click": assigns[:phx_click_touch]] |
| 965 | + !is_nil(assigns[:phx_click_touch]) && !is_modal && |
| 966 | + ["phx-click": assigns[:phx_click_touch]] |
| 964 967 | ]) |
| 965 968 | |
| 966 969 | focus_wrap_id = "focus-wrap-#{id || generated_id}" |
| @@ -0,0 +1,28 @@ | |
| 1 | + defmodule PrimerLive.Helpers.TestHelpers do |
| 2 | + @moduledoc false |
| 3 | + |
| 4 | + @doc ~S""" |
| 5 | + Tweaks Phoenix.LiveView.HTMLFormatter.format/2 to remove spaces surrounding HTML tags. |
| 6 | + |
| 7 | + ## Tests |
| 8 | + |
| 9 | + iex> PrimerLive.Helpers.TestHelpers.format_html(" |
| 10 | + ...> <div> <span>Content</span> |
| 11 | + ...> </div> |
| 12 | + ...> ") |
| 13 | + "<div><span>Content</span></div>" |
| 14 | + |
| 15 | + iex> PrimerLive.Helpers.TestHelpers.format_html(" |
| 16 | + ...> <button class=\"btn\" type=\"submit\"> Button </button>") |
| 17 | + "<button class=\"btn\" type=\"submit\">Button</button>" |
| 18 | + """ |
| 19 | + def format_html(html) do |
| 20 | + html |
| 21 | + |> Phoenix.LiveView.HTMLFormatter.format([]) |
| 22 | + |> String.replace(~r/\s*\n\s*/, " ") |
| 23 | + |> String.replace(~r/\s*\<\s*/, "<") |
| 24 | + |> String.replace(~r/\s*\>\s*/, ">") |
| 25 | + |> String.replace(~r/<path .*?<\/path>/, "STRIPPED_SVG_PATHS") |
| 26 | + |> String.trim() |
| 27 | + end |
| 28 | + end |
| @@ -0,0 +1,11 @@ | |
| 1 | + defmodule PrimerLive.TestHelpers.Repo.Todo do |
| 2 | + @moduledoc false |
| 3 | + |
| 4 | + use Ecto.Schema |
| 5 | + |
| 6 | + schema "todos" do |
| 7 | + field(:statuses, {:array, :string}, default: []) |
| 8 | + |
| 9 | + timestamps() |
| 10 | + end |
| 11 | + end |
| @@ -0,0 +1,57 @@ | |
| 1 | + defmodule PrimerLive.TestHelpers.Repo.Todos do |
| 2 | + @moduledoc false |
| 3 | + |
| 4 | + import Ecto.Changeset, except: [change: 1] |
| 5 | + alias PrimerLive.TestHelpers.Repo.Todo |
| 6 | + |
| 7 | + @doc """ |
| 8 | + Returns an `%Ecto.Changeset{}` for tracking to do item changes. |
| 9 | + |
| 10 | + ## Examples |
| 11 | + |
| 12 | + iex> change(to do item) |
| 13 | + %Ecto.Changeset{data: %Todo{}} |
| 14 | + |
| 15 | + """ |
| 16 | + def change(%Todo{} = todo, attrs \\ %{}) do |
| 17 | + todo |
| 18 | + |> changeset(attrs) |
| 19 | + end |
| 20 | + |
| 21 | + def init() do |
| 22 | + change(%Todo{}) |
| 23 | + end |
| 24 | + |
| 25 | + @status_options [ |
| 26 | + {"In progress", "in-progress"}, |
| 27 | + {"Needs review", "needs-review"}, |
| 28 | + {"Complete", "complete"} |
| 29 | + ] |
| 30 | + |
| 31 | + def status_options, do: @status_options |
| 32 | + |
| 33 | + @allowed_fields [ |
| 34 | + :statuses |
| 35 | + ] |
| 36 | + |
| 37 | + @required_fields [ |
| 38 | + :statuses |
| 39 | + ] |
| 40 | + |
| 41 | + defp changeset(todo, attrs) do |
| 42 | + todo |
| 43 | + |> cast(attrs, @allowed_fields) |
| 44 | + |> validate_required(@required_fields) |
| 45 | + |> validate_empty(:statuses, "must select a status") |
| 46 | + end |
| 47 | + |
| 48 | + defp validate_empty(changeset, field, message) do |
| 49 | + values = get_field(changeset, field) |
| 50 | + |
| 51 | + if Enum.empty?(values) do |
| 52 | + add_error(changeset, field, message) |
| 53 | + else |
| 54 | + changeset |
| 55 | + end |
| 56 | + end |
| 57 | + end |
Loading more files…