diff --git a/CHANGELOG.md b/CHANGELOG.md index 07c666b..487d58a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## Unreleased + +- Switched bitstyles version comparisons from string comparisons to tuple comparisons, which will ensure correct output if bitstyles version ever contains a number above 9. +- Modified the process of downgrading classnames to the target bitstyles version by chaining renames. This is necessary preparation work to support bitstyles 6.0.0. + ## v2.4.0 - 2024-07-18 - Added support for phoenix_html `v4`. You can also continue using phoenix_html `v3`. To replace `Phoenix.HTML.Form` input helpers removed in phoenix_html `v4`, new components `ui_raw_input` and `ui_raw_label` were added. diff --git a/config/config.exs b/config/config.exs index 6048e84..3c32b1b 100644 --- a/config/config.exs +++ b/config/config.exs @@ -4,3 +4,7 @@ config :bitstyles_phoenix, trim_e2e_classes: [enabled: true] config :phoenix, :json_library, Jason + +if config_env() === :test do + config :bitstyles_phoenix, add_version_test_classes: true +end diff --git a/docs/bitstyles_version_compatibility.md b/docs/bitstyles_version_compatibility.md index 82743e7..bb59518 100644 --- a/docs/bitstyles_version_compatibility.md +++ b/docs/bitstyles_version_compatibility.md @@ -78,9 +78,9 @@ open version_showcase/index.html ```elixir def ui_tricky_component(assigns) do - version = BitstylesPhoenix.Bitstyles.version() + version = BitstylesPhoenix.Bitstyles.Version.version() - if version >= "5.0.0" do + if version >= {5,0,0} do ~H"""
...
""" diff --git a/lib/bitstyles_phoenix.ex b/lib/bitstyles_phoenix.ex index 9c677f9..1485211 100644 --- a/lib/bitstyles_phoenix.ex +++ b/lib/bitstyles_phoenix.ex @@ -48,7 +48,7 @@ defmodule BitstylesPhoenix do ### Bitstyles version - BitstylesPhoenix will generate classes #{BitstylesPhoenix.Bitstyles.version()} of bitstyles. + BitstylesPhoenix will generate classes #{BitstylesPhoenix.Bitstyles.Version.version_string()} of bitstyles. You can set older versions with a configuration: ```elixir diff --git a/lib/bitstyles_phoenix/bitstyles.ex b/lib/bitstyles_phoenix/bitstyles.ex index 2794ac9..6a85068 100644 --- a/lib/bitstyles_phoenix/bitstyles.ex +++ b/lib/bitstyles_phoenix/bitstyles.ex @@ -1,22 +1,23 @@ defmodule BitstylesPhoenix.Bitstyles do @moduledoc false - @default_version "5.0.1" + require BitstylesPhoenix.Bitstyles.Version + alias BitstylesPhoenix.Bitstyles.Version + @cdn_url "https://cdn.jsdelivr.net/npm/bitstyles" def cdn_url do - "#{@cdn_url}@#{version()}" + "#{@cdn_url}@#{Version.version_string()}" end @doc """ Returns the classnames for the configured version. - Input classnames are assumed to be from the #{@default_version} version of bitstyles. + Input classnames are assumed to be from the #{Version.default_version_string()} version of bitstyles. """ - def classname(name), do: classname(name, version()) + def classname(name), do: classname(name, Version.version()) - def classname(class, version) when version > "5.0.1" do - IO.warn("Version #{version} of bitstyles is not yet supported") - class + def classname(class, version) when is_tuple(version) do + downgrade_classname(class, version, Version.default_version()) end # Note about class renaming: @@ -25,11 +26,24 @@ defmodule BitstylesPhoenix.Bitstyles do # If it does exist, then doing this renaming in the classname/2 function would make it impossible # for users of older bitstyles to use the "class-name-A" classname. - def classname(class, version) when version >= "5.0.0" do + defp downgrade_classname(class, target_version, _current_version) + when target_version > {5, 0, 1} do + IO.warn("Version #{Version.to_string(target_version)} of bitstyles is not yet supported") + class + end + + defp downgrade_classname(class, target_version, current_version) + when target_version == current_version do class end - def classname(class, version) when version >= "4.2.0" do + defp downgrade_classname(class, target_version, {5, 0, 1}) do + # no changes when downgrading 5.0.1 -> 5.0.0 + downgrade_classname(class, target_version, {5, 0, 0}) + end + + defp downgrade_classname(class, target_version, {5, 0, 0}) do + # downgrading 5.0.0 -> 4.3.0 sizes_renaming = %{ "3xs" => "xxxs", "2xs" => "xxs", @@ -66,23 +80,36 @@ defmodule BitstylesPhoenix.Bitstyles do class -> class end - classname(class, "5.0.0") + class = test_only_downgrade(class, "u-version-5-0-0", "u-version-4") + + downgrade_classname(class, target_version, {4, 3, 0}) end - def classname(class, version) when version >= "4.0.0" do - mapping = + defp downgrade_classname(class, target_version, {4, 3, 0}) do + # no changes when downgrading from 4.3.0 -> 4.2.0 + downgrade_classname(class, target_version, {4, 2, 0}) + end + + defp downgrade_classname(class, target_version, {4, 2, 0}) do + # downgrading from 4.2.0 -> 4.1.0 + class = case class do "u-border-radius-" <> variant -> "u-round-#{variant}" _ -> class end - classname(mapping, "4.3.0") + downgrade_classname(class, target_version, {4, 1, 0}) end - def classname(class, version) when version >= "2.0.0" do - # credo:disable-for-previous-line Credo.Check.Refactor.CyclomaticComplexity + defp downgrade_classname(class, target_version, {4, 1, 0}) do + # no changes when downgrading from 4.1.0 -> 4.0.0 + downgrade_classname(class, target_version, {4, 0, 0}) + end - mapping = + # credo:disable-for-next-line Credo.Check.Refactor.CyclomaticComplexity + defp downgrade_classname(class, target_version, {4, 0, 0}) do + # downgrading from 4.0.0 -> 3.0.0 + class = case class do # Make sure that we leave the classes in place that are old anyway (update compatibility) "u-bg--" <> _ -> class @@ -104,11 +131,24 @@ defmodule BitstylesPhoenix.Bitstyles do _ -> class end - classname(mapping, "4.0.0") + class = test_only_downgrade(class, "u-version-4", "u-version-2") + + downgrade_classname(class, target_version, {3, 1, 0}) end - def classname(class, version) when version >= "1.5.0" do - mapping = + defp downgrade_classname(class, target_version, {3, 1, 0}) do + # no changes when downgrading from 3.1.0 -> 3.0.0 + downgrade_classname(class, target_version, {3, 0, 0}) + end + + defp downgrade_classname(class, target_version, {3, 0, 0}) do + # no changes when downgrading from 3.0.0 -> 2.0.0 + downgrade_classname(class, target_version, {2, 0, 0}) + end + + defp downgrade_classname(class, target_version, {2, 0, 0}) do + # downgrading 2.0.0 -> 1.5.0 + class = case class do "u-flex-shrink-" <> number -> "u-flex__shrink-#{number}" "u-flex-grow-" <> number -> "u-flex__grow-#{number}" @@ -117,11 +157,19 @@ defmodule BitstylesPhoenix.Bitstyles do _ -> class end - classname(mapping, "2.0.0") + class = test_only_downgrade(class, "u-version-2", "u-version-1-4") + + downgrade_classname(class, target_version, {1, 5, 0}) + end + + defp downgrade_classname(class, target_version, {1, 5, 0}) do + # no changes when downgrading from 1.5.0 -> 1.4.0 + downgrade_classname(class, target_version, {1, 4, 0}) end - def classname(class, version) when version >= "1.3.0" do - mapping = + defp downgrade_classname(class, target_version, {1, 4, 0}) do + # downgrading 1.4.0 -> 1.3.0 + class = case class do "u-grid-cols-" <> number -> "u-grid--#{number}-col" "u-col-span-" <> number -> "u-grid__col-span-#{number}" @@ -129,24 +177,27 @@ defmodule BitstylesPhoenix.Bitstyles do _ -> class end - classname(mapping, "1.5.0") + class = test_only_downgrade(class, "u-version-1-4", "u-version-1-3") + + downgrade_classname(class, target_version, {1, 3, 0}) + end + + defp downgrade_classname(class, target_version, {1, 3, 0}) do + # no changes when downgrading from 1.3.0 -> 1.2.0 + downgrade_classname(class, target_version, {1, 2, 0}) end - def classname(_class, version) do + defp downgrade_classname(_class, target_version, {1, 2, 0}) do raise(""" - The version #{version} of bitstyles is not supported. The helpers will produce incorrect classes. + The version #{Version.to_string(target_version)} of bitstyles is not supported. The helpers will produce incorrect classes. Please upgrade bitsyles and set the `bitsyles_version` to the updated version. """) end - def version do - bitstyles_version_override = Process.get(:bitstyles_phoenix_bistyles_version) - - bitstyles_version_override || - Application.get_env(:bitstyles_phoenix, :bitstyles_version, @default_version) - end - - def default_version do - @default_version + if Application.compile_env(:bitstyles_phoenix, :add_version_test_classes, false) do + defp test_only_downgrade(from, from, to), do: to + defp test_only_downgrade(class, _, _), do: class + else + defp test_only_downgrade(class, _, _), do: class end end diff --git a/lib/bitstyles_phoenix/bitstyles/version.ex b/lib/bitstyles_phoenix/bitstyles/version.ex new file mode 100644 index 0000000..9ee0ec8 --- /dev/null +++ b/lib/bitstyles_phoenix/bitstyles/version.ex @@ -0,0 +1,39 @@ +defmodule BitstylesPhoenix.Bitstyles.Version do + @moduledoc false + + @default_version "5.0.1" + + def version do + to_tuple(version_string()) + end + + def version_string do + bitstyles_version_override = Process.get(:bitstyles_phoenix_bistyles_version) + + bitstyles_version_override || + Application.get_env(:bitstyles_phoenix, :bitstyles_version, @default_version) + end + + def default_version do + to_tuple(@default_version) + end + + def default_version_string, do: @default_version + + def to_tuple(version) when is_tuple(version), do: version + + def to_tuple(version) when is_binary(version) do + version + |> String.split(".") + |> Enum.map(&String.to_integer/1) + |> List.to_tuple() + end + + def to_string(version) when is_binary(version), do: version + + def to_string(version) when is_tuple(version) do + version + |> Tuple.to_list() + |> Enum.map_join(".", &Kernel.to_string/1) + end +end diff --git a/lib/bitstyles_phoenix/component/button.ex b/lib/bitstyles_phoenix/component/button.ex index e11734a..358bfff 100644 --- a/lib/bitstyles_phoenix/component/button.ex +++ b/lib/bitstyles_phoenix/component/button.ex @@ -287,7 +287,7 @@ defmodule BitstylesPhoenix.Component.Button do extra = assigns_to_attributes(assigns, [:icon, :class, :color, :shape, :variant]) assigns = - if Bitstyles.version() >= "5.0.0" && assigns[:variant] do + if Bitstyles.Version.version() >= {5, 0, 0} && assigns[:variant] do IO.warn("Attribute `variant` is deprecated in ui_button/1! Change to `color` and `shape`") assigns @@ -298,7 +298,7 @@ defmodule BitstylesPhoenix.Component.Button do end classes = - if Bitstyles.version() >= "5.0.0" do + if Bitstyles.Version.version() >= {5, 0, 0} do color_and_shape_classes(assigns[:color], assigns[:shape]) else variant_classes(assigns[:variant]) @@ -538,7 +538,7 @@ defmodule BitstylesPhoenix.Component.Button do extra = assigns_to_attributes(assigns, [:icon, :label, :reversed, :color, :title]) extra = - if Bitstyles.version() >= "5.0.0" do + if Bitstyles.Version.version() >= {5, 0, 0} do if assigns[:reversed] do Keyword.put_new(extra, :"data-theme", "dark") else diff --git a/lib/bitstyles_phoenix/component/description_list.ex b/lib/bitstyles_phoenix/component/description_list.ex index 74460b3..da989e2 100644 --- a/lib/bitstyles_phoenix/component/description_list.ex +++ b/lib/bitstyles_phoenix/component/description_list.ex @@ -161,7 +161,7 @@ defmodule BitstylesPhoenix.Component.DescriptionList do # u-gap-l and u-gap-xl in 5.0.0 are equivalent to respectively u-gap-m and u-gap-l in 4.3.0 gap_class = - if Bitstyles.version() >= "5.0.0" do + if Bitstyles.Version.version() >= {5, 0, 0} do "u-gap-l" else "u-gap-m" diff --git a/lib/bitstyles_phoenix/component/dropdown.ex b/lib/bitstyles_phoenix/component/dropdown.ex index a0e9d31..bfbc198 100644 --- a/lib/bitstyles_phoenix/component/dropdown.ex +++ b/lib/bitstyles_phoenix/component/dropdown.ex @@ -456,7 +456,7 @@ defmodule BitstylesPhoenix.Component.Dropdown do assigns_from_single_slot(assigns, :button, exclude: [:label, :icon_file]) button_extra = - if Bitstyles.version() >= "5.0.0" do + if Bitstyles.Version.version() >= {5, 0, 0} do button_extra |> Keyword.put_new(:color, :secondary) else @@ -516,7 +516,7 @@ defmodule BitstylesPhoenix.Component.Dropdown do |> assigns_to_attributes() extra = - if Bitstyles.version() >= "5.0.0" do + if Bitstyles.Version.version() >= {5, 0, 0} do extra |> Keyword.put_new(:shape, "menu") |> Keyword.put_new(:color, "transparent") diff --git a/lib/bitstyles_phoenix/showcase.ex b/lib/bitstyles_phoenix/showcase.ex index 39b8ac0..49f9b40 100644 --- a/lib/bitstyles_phoenix/showcase.ex +++ b/lib/bitstyles_phoenix/showcase.ex @@ -5,7 +5,9 @@ defmodule BitstylesPhoenix.Showcase do alias Phoenix.HTML.Safe defmacro story(name, doctest_iex_code, doctest_expected_results, opts \\ []) do - default_version = BitstylesPhoenix.Bitstyles.default_version() |> String.to_atom() + default_version = + BitstylesPhoenix.Bitstyles.Version.default_version_string() + |> String.to_atom() doctest_expected_results = if is_list(doctest_expected_results) && is_tuple(List.first(doctest_expected_results)) do diff --git a/test/bitstyles_phoenix/bitstyles_test.exs b/test/bitstyles_phoenix/bitstyles_test.exs index fd528b4..d1c07e4 100644 --- a/test/bitstyles_phoenix/bitstyles_test.exs +++ b/test/bitstyles_phoenix/bitstyles_test.exs @@ -7,211 +7,235 @@ defmodule BitstylesPhoenix.BitstylesTest do test "version 6.0.0" do assert Regex.match?( ~r/6.0.0 of bitstyles is not yet supported/, - capture_io(:stderr, fn -> classname("u-flex", "6.0.0") end) + capture_io(:stderr, fn -> classname("u-flex", {6, 0, 0}) end) ) end + test "chained version downgrade" do + # those class changes are only added in the test environment, to test that chaining works + # and won't be available to the users of bitstyles_phoenix + assert classname("u-version-5-0-0", {5, 0, 1}) == "u-version-5-0-0" + assert classname("u-version-5-0-0", {5, 0, 0}) == "u-version-5-0-0" + assert classname("u-version-5-0-0", {4, 3, 0}) == "u-version-4" + assert classname("u-version-5-0-0", {4, 2, 0}) == "u-version-4" + assert classname("u-version-5-0-0", {4, 1, 0}) == "u-version-4" + assert classname("u-version-5-0-0", {4, 0, 0}) == "u-version-4" + assert classname("u-version-5-0-0", {3, 1, 0}) == "u-version-2" + assert classname("u-version-5-0-0", {3, 0, 0}) == "u-version-2" + assert classname("u-version-5-0-0", {2, 0, 0}) == "u-version-2" + assert classname("u-version-5-0-0", {1, 5, 0}) == "u-version-1-4" + assert classname("u-version-5-0-0", {1, 4, 0}) == "u-version-1-4" + assert classname("u-version-5-0-0", {1, 3, 0}) == "u-version-1-3" + end + test "version 5.0.0" do - assert classname("u-flex", "5.0.0") == "u-flex" - assert classname("u-border-radius-0", "5.0.0") == "u-border-radius-0" - assert classname("u-overflow-x-auto", "5.0.0") == "u-overflow-x-auto" - assert classname("u-overflow-y-auto", "5.0.0") == "u-overflow-y-auto" - assert classname("u-bg-gray-80", "5.0.0") == "u-bg-gray-80" - assert classname("u-fg-warning", "5.0.0") == "u-fg-warning" - assert classname("u-font-medium", "5.0.0") == "u-font-medium" - assert classname("u-line-height-min", "5.0.0") == "u-line-height-min" - assert classname("u-text-right", "5.0.0") == "u-text-right" - assert classname("u-flex-shrink-0", "5.0.0") == "u-flex-shrink-0" - assert classname("u-flex-grow-1", "5.0.0") == "u-flex-grow-1" - assert classname("u-flex-wrap", "5.0.0") == "u-flex-wrap" - assert classname("u-flex-col", "5.0.0") == "u-flex-col" - assert classname("u-grid-cols-3", "5.0.0") == "u-grid-cols-3" - assert classname("u-col-span-3", "5.0.0") == "u-col-span-3" - assert classname("u-col-start-1", "5.0.0") == "u-col-start-1" - assert classname("u-margin-2xs", "5.0.0") == "u-margin-2xs" - assert classname("u-margin-3xs\@m", "5.0.0") == "u-margin-3xs\@m" - assert classname("u-margin-3xs-bottom", "5.0.0") == "u-margin-3xs-bottom" - assert classname("u-padding-2xl", "5.0.0") == "u-padding-2xl" - assert classname("u-padding-3xl\@l", "5.0.0") == "u-padding-3xl\@l" - assert classname("u-margin-3xl-bottom", "5.0.0") == "u-margin-3xl-bottom" - assert classname("u-margin-neg-3xl-bottom", "5.0.0") == "u-margin-neg-3xl-bottom" - assert classname("u-list-none", "5.0.0") == "u-list-none" - assert classname("a-badge--text", "5.0.0") == "a-badge--text" - assert classname("u-fg-text", "5.0.0") == "u-fg-text" - assert classname("u-fg-text-darker", "5.0.0") == "u-fg-text-darker" - assert classname("u-bg-gray-darker", "5.0.0") == "u-bg-gray-darker" - assert classname("u-border-gray-light", "5.0.0") == "u-border-gray-light" - assert classname("u-border-gray-light-bottom", "5.0.0") == "u-border-gray-light-bottom" - assert classname("u-border-gray-dark", "5.0.0") == "u-border-gray-dark" + assert classname("u-flex", {5, 0, 0}) == "u-flex" + assert classname("u-border-radius-0", {5, 0, 0}) == "u-border-radius-0" + assert classname("u-overflow-x-auto", {5, 0, 0}) == "u-overflow-x-auto" + assert classname("u-overflow-y-auto", {5, 0, 0}) == "u-overflow-y-auto" + assert classname("u-bg-gray-80", {5, 0, 0}) == "u-bg-gray-80" + assert classname("u-fg-warning", {5, 0, 0}) == "u-fg-warning" + assert classname("u-font-medium", {5, 0, 0}) == "u-font-medium" + assert classname("u-line-height-min", {5, 0, 0}) == "u-line-height-min" + assert classname("u-text-right", {5, 0, 0}) == "u-text-right" + assert classname("u-flex-shrink-0", {5, 0, 0}) == "u-flex-shrink-0" + assert classname("u-flex-grow-1", {5, 0, 0}) == "u-flex-grow-1" + assert classname("u-flex-wrap", {5, 0, 0}) == "u-flex-wrap" + assert classname("u-flex-col", {5, 0, 0}) == "u-flex-col" + assert classname("u-grid-cols-3", {5, 0, 0}) == "u-grid-cols-3" + assert classname("u-col-span-3", {5, 0, 0}) == "u-col-span-3" + assert classname("u-col-start-1", {5, 0, 0}) == "u-col-start-1" + assert classname("u-margin-2xs", {5, 0, 0}) == "u-margin-2xs" + assert classname("u-margin-3xs\@m", {5, 0, 0}) == "u-margin-3xs\@m" + assert classname("u-margin-3xs-bottom", {5, 0, 0}) == "u-margin-3xs-bottom" + assert classname("u-padding-2xl", {5, 0, 0}) == "u-padding-2xl" + assert classname("u-padding-3xl\@l", {5, 0, 0}) == "u-padding-3xl\@l" + assert classname("u-margin-3xl-bottom", {5, 0, 0}) == "u-margin-3xl-bottom" + assert classname("u-margin-neg-3xl-bottom", {5, 0, 0}) == "u-margin-neg-3xl-bottom" + assert classname("u-list-none", {5, 0, 0}) == "u-list-none" + assert classname("a-badge--text", {5, 0, 0}) == "a-badge--text" + assert classname("u-fg-text", {5, 0, 0}) == "u-fg-text" + assert classname("u-fg-text-darker", {5, 0, 0}) == "u-fg-text-darker" + assert classname("u-bg-gray-darker", {5, 0, 0}) == "u-bg-gray-darker" + assert classname("u-border-gray-light", {5, 0, 0}) == "u-border-gray-light" + assert classname("u-border-gray-light-bottom", {5, 0, 0}) == "u-border-gray-light-bottom" + assert classname("u-border-gray-dark", {5, 0, 0}) == "u-border-gray-dark" end test "version 4.3.0" do - assert classname("u-flex", "4.3.0") == "u-flex" - assert classname("u-border-radius-0", "4.3.0") == "u-border-radius-0" - assert classname("u-overflow-x-auto", "4.3.0") == "u-overflow-x-auto" - assert classname("u-overflow-y-auto", "4.3.0") == "u-overflow-y-auto" - assert classname("u-bg-gray-80", "4.3.0") == "u-bg-gray-80" - assert classname("u-fg-warning", "4.3.0") == "u-fg-warning" - assert classname("u-font-medium", "4.3.0") == "u-font-medium" - assert classname("u-line-height-min", "4.3.0") == "u-line-height-min" - assert classname("u-text-right", "4.3.0") == "u-text-right" - assert classname("u-flex-shrink-0", "4.3.0") == "u-flex-shrink-0" - assert classname("u-flex-grow-1", "4.3.0") == "u-flex-grow-1" - assert classname("u-flex-wrap", "4.3.0") == "u-flex-wrap" - assert classname("u-flex-col", "4.3.0") == "u-flex-col" - assert classname("u-grid-cols-3", "4.3.0") == "u-grid-cols-3" - assert classname("u-col-span-3", "4.3.0") == "u-col-span-3" - assert classname("u-col-start-1", "4.3.0") == "u-col-start-1" - assert classname("u-margin-2xs", "4.3.0") == "u-margin-xxs" - assert classname("u-margin-3xs\@m", "4.3.0") == "u-margin-xxxs\@m" - assert classname("u-margin-3xs-bottom", "4.3.0") == "u-margin-xxxs-bottom" - assert classname("u-padding-2xl", "4.3.0") == "u-padding-xxl" - assert classname("u-padding-3xl\@l", "4.3.0") == "u-padding-xxxl\@l" - assert classname("u-margin-3xl-bottom", "4.3.0") == "u-margin-xxxl-bottom" - assert classname("u-margin-neg-3xl-bottom", "4.3.0") == "u-margin-neg-xxxl-bottom" - assert classname("u-list-none", "4.3.0") == "a-list-reset" - assert classname("a-badge--text", "4.3.0") == "a-badge--gray" - assert classname("u-gap-l", "4.3.0") == "u-gap-l" - assert classname("u-fg-text", "4.3.0") == "u-fg-gray-30" - assert classname("u-fg-text-darker", "4.3.0") == "u-fg-gray-50" - assert classname("u-bg-gray-darker", "4.3.0") == "u-bg-gray-80" - assert classname("u-border-gray-light", "4.3.0") == "u-border-gray-10" - assert classname("u-border-gray-light-bottom", "4.3.0") == "u-border-gray-10-bottom" - assert classname("u-border-gray-dark", "4.3.0") == "u-border-gray-70" + assert classname("u-flex", {4, 3, 0}) == "u-flex" + assert classname("u-border-radius-0", {4, 3, 0}) == "u-border-radius-0" + assert classname("u-overflow-x-auto", {4, 3, 0}) == "u-overflow-x-auto" + assert classname("u-overflow-y-auto", {4, 3, 0}) == "u-overflow-y-auto" + assert classname("u-bg-gray-80", {4, 3, 0}) == "u-bg-gray-80" + assert classname("u-fg-warning", {4, 3, 0}) == "u-fg-warning" + assert classname("u-font-medium", {4, 3, 0}) == "u-font-medium" + assert classname("u-line-height-min", {4, 3, 0}) == "u-line-height-min" + assert classname("u-text-right", {4, 3, 0}) == "u-text-right" + assert classname("u-flex-shrink-0", {4, 3, 0}) == "u-flex-shrink-0" + assert classname("u-flex-grow-1", {4, 3, 0}) == "u-flex-grow-1" + assert classname("u-flex-wrap", {4, 3, 0}) == "u-flex-wrap" + assert classname("u-flex-col", {4, 3, 0}) == "u-flex-col" + assert classname("u-grid-cols-3", {4, 3, 0}) == "u-grid-cols-3" + assert classname("u-col-span-3", {4, 3, 0}) == "u-col-span-3" + assert classname("u-col-start-1", {4, 3, 0}) == "u-col-start-1" + assert classname("u-margin-2xs", {4, 3, 0}) == "u-margin-xxs" + assert classname("u-margin-3xs\@m", {4, 3, 0}) == "u-margin-xxxs\@m" + assert classname("u-margin-3xs-bottom", {4, 3, 0}) == "u-margin-xxxs-bottom" + assert classname("u-padding-2xl", {4, 3, 0}) == "u-padding-xxl" + assert classname("u-padding-3xl\@l", {4, 3, 0}) == "u-padding-xxxl\@l" + assert classname("u-margin-3xl-bottom", {4, 3, 0}) == "u-margin-xxxl-bottom" + assert classname("u-margin-neg-3xl-bottom", {4, 3, 0}) == "u-margin-neg-xxxl-bottom" + assert classname("u-list-none", {4, 3, 0}) == "a-list-reset" + assert classname("a-badge--text", {4, 3, 0}) == "a-badge--gray" + assert classname("u-gap-l", {4, 3, 0}) == "u-gap-l" + assert classname("u-fg-text", {4, 3, 0}) == "u-fg-gray-30" + assert classname("u-fg-text-darker", {4, 3, 0}) == "u-fg-gray-50" + assert classname("u-bg-gray-darker", {4, 3, 0}) == "u-bg-gray-80" + assert classname("u-border-gray-light", {4, 3, 0}) == "u-border-gray-10" + assert classname("u-border-gray-light-bottom", {4, 3, 0}) == "u-border-gray-10-bottom" + assert classname("u-border-gray-dark", {4, 3, 0}) == "u-border-gray-70" end test "version 4.2.0" do - assert classname("u-border-radius-0", "4.2.0") == "u-border-radius-0" + assert classname("u-border-radius-0", {4, 2, 0}) == "u-border-radius-0" end test "version 4.1.0" do - assert classname("u-flex", "4.1.0") == "u-flex" - assert classname("u-border-radius-0", "4.1.0") == "u-round-0" - assert classname("u-overflow-x-auto", "4.1.0") == "u-overflow-x-auto" - assert classname("u-overflow-y-auto", "4.1.0") == "u-overflow-y-auto" - assert classname("u-bg-gray-80", "4.1.0") == "u-bg-gray-80" - assert classname("u-fg-warning", "4.1.0") == "u-fg-warning" - assert classname("u-font-medium", "4.1.0") == "u-font-medium" - assert classname("u-line-height-min", "4.1.0") == "u-line-height-min" - assert classname("u-text-right", "4.1.0") == "u-text-right" - assert classname("u-flex-shrink-0", "4.1.0") == "u-flex-shrink-0" - assert classname("u-flex-grow-1", "4.1.0") == "u-flex-grow-1" - assert classname("u-flex-wrap", "4.1.0") == "u-flex-wrap" - assert classname("u-flex-col", "4.1.0") == "u-flex-col" - assert classname("u-grid-cols-3", "4.1.0") == "u-grid-cols-3" - assert classname("u-col-span-3", "4.1.0") == "u-col-span-3" - assert classname("u-col-start-1", "4.1.0") == "u-col-start-1" + assert classname("u-flex", {4, 1, 0}) == "u-flex" + assert classname("u-border-radius-0", {4, 1, 0}) == "u-round-0" + assert classname("u-overflow-x-auto", {4, 1, 0}) == "u-overflow-x-auto" + assert classname("u-overflow-y-auto", {4, 1, 0}) == "u-overflow-y-auto" + assert classname("u-bg-gray-80", {4, 1, 0}) == "u-bg-gray-80" + assert classname("u-fg-warning", {4, 1, 0}) == "u-fg-warning" + assert classname("u-font-medium", {4, 1, 0}) == "u-font-medium" + assert classname("u-line-height-min", {4, 1, 0}) == "u-line-height-min" + assert classname("u-text-right", {4, 1, 0}) == "u-text-right" + assert classname("u-flex-shrink-0", {4, 1, 0}) == "u-flex-shrink-0" + assert classname("u-flex-grow-1", {4, 1, 0}) == "u-flex-grow-1" + assert classname("u-flex-wrap", {4, 1, 0}) == "u-flex-wrap" + assert classname("u-flex-col", {4, 1, 0}) == "u-flex-col" + assert classname("u-grid-cols-3", {4, 1, 0}) == "u-grid-cols-3" + assert classname("u-col-span-3", {4, 1, 0}) == "u-col-span-3" + assert classname("u-col-start-1", {4, 1, 0}) == "u-col-start-1" end test "version 4.0.0" do - assert classname("u-flex", "4.0.0") == "u-flex" - assert classname("u-border-radius-0", "4.0.0") == "u-round-0" - assert classname("u-overflow-x-auto", "4.0.0") == "u-overflow-x-auto" - assert classname("u-overflow-y-auto", "4.0.0") == "u-overflow-y-auto" - assert classname("u-bg-gray-80", "4.0.0") == "u-bg-gray-80" - assert classname("u-fg-warning", "4.0.0") == "u-fg-warning" - assert classname("u-font-medium", "4.0.0") == "u-font-medium" - assert classname("u-line-height-min", "4.0.0") == "u-line-height-min" - assert classname("u-text-right", "4.0.0") == "u-text-right" - assert classname("u-flex-shrink-0", "4.0.0") == "u-flex-shrink-0" - assert classname("u-flex-grow-1", "4.0.0") == "u-flex-grow-1" - assert classname("u-flex-wrap", "4.0.0") == "u-flex-wrap" - assert classname("u-flex-col", "4.0.0") == "u-flex-col" - assert classname("u-grid-cols-3", "4.0.0") == "u-grid-cols-3" - assert classname("u-col-span-3", "4.0.0") == "u-col-span-3" - assert classname("u-col-start-1", "4.0.0") == "u-col-start-1" + assert classname("u-flex", {4, 0, 0}) == "u-flex" + assert classname("u-border-radius-0", {4, 0, 0}) == "u-round-0" + assert classname("u-overflow-x-auto", {4, 0, 0}) == "u-overflow-x-auto" + assert classname("u-overflow-y-auto", {4, 0, 0}) == "u-overflow-y-auto" + assert classname("u-bg-gray-80", {4, 0, 0}) == "u-bg-gray-80" + assert classname("u-fg-warning", {4, 0, 0}) == "u-fg-warning" + assert classname("u-font-medium", {4, 0, 0}) == "u-font-medium" + assert classname("u-line-height-min", {4, 0, 0}) == "u-line-height-min" + assert classname("u-text-right", {4, 0, 0}) == "u-text-right" + assert classname("u-flex-shrink-0", {4, 0, 0}) == "u-flex-shrink-0" + assert classname("u-flex-grow-1", {4, 0, 0}) == "u-flex-grow-1" + assert classname("u-flex-wrap", {4, 0, 0}) == "u-flex-wrap" + assert classname("u-flex-col", {4, 0, 0}) == "u-flex-col" + assert classname("u-grid-cols-3", {4, 0, 0}) == "u-grid-cols-3" + assert classname("u-col-span-3", {4, 0, 0}) == "u-col-span-3" + assert classname("u-col-start-1", {4, 0, 0}) == "u-col-start-1" end test "version 3.0.0" do - assert classname("u-flex", "3.0.0") == "u-flex" - assert classname("u-overflow-x-auto", "3.0.0") == "u-overflow--x" - assert classname("u-overflow-y-auto", "3.0.0") == "u-overflow--y" - assert classname("u-bg-gray-80", "3.0.0") == "u-bg--gray-80" - assert classname("u-fg-warning", "3.0.0") == "u-fg--warning" - assert classname("u-font-medium", "3.0.0") == "u-font--medium" - assert classname("u-line-height-min", "3.0.0") == "u-line-height--min" - assert classname("u-text-right", "3.0.0") == "u-text--right" - assert classname("u-round-0-tr", "3.0.0") == "u-round--0-tr" - assert classname("u-border-radius-0-tr", "3.0.0") == "u-round--0-tr" - assert classname("u-flex-shrink-0", "3.0.0") == "u-flex-shrink-0" - assert classname("u-flex-grow-1", "3.0.0") == "u-flex-grow-1" - assert classname("u-flex-wrap", "3.0.0") == "u-flex-wrap" - assert classname("u-flex-col", "3.0.0") == "u-flex-col" - assert classname("u-grid-cols-3", "3.0.0") == "u-grid-cols-3" - assert classname("u-col-span-3", "3.0.0") == "u-col-span-3" - assert classname("u-col-start-1", "3.0.0") == "u-col-start-1" + assert classname("u-flex", {3, 0, 0}) == "u-flex" + assert classname("u-overflow-x-auto", {3, 0, 0}) == "u-overflow--x" + assert classname("u-overflow-y-auto", {3, 0, 0}) == "u-overflow--y" + assert classname("u-bg-gray-80", {3, 0, 0}) == "u-bg--gray-80" + assert classname("u-fg-warning", {3, 0, 0}) == "u-fg--warning" + assert classname("u-font-medium", {3, 0, 0}) == "u-font--medium" + assert classname("u-line-height-min", {3, 0, 0}) == "u-line-height--min" + assert classname("u-text-right", {3, 0, 0}) == "u-text--right" + assert classname("u-round-0-tr", {3, 0, 0}) == "u-round--0-tr" + assert classname("u-border-radius-0-tr", {3, 0, 0}) == "u-round--0-tr" + assert classname("u-flex-shrink-0", {3, 0, 0}) == "u-flex-shrink-0" + assert classname("u-flex-grow-1", {3, 0, 0}) == "u-flex-grow-1" + assert classname("u-flex-wrap", {3, 0, 0}) == "u-flex-wrap" + assert classname("u-flex-col", {3, 0, 0}) == "u-flex-col" + assert classname("u-grid-cols-3", {3, 0, 0}) == "u-grid-cols-3" + assert classname("u-col-span-3", {3, 0, 0}) == "u-col-span-3" + assert classname("u-col-start-1", {3, 0, 0}) == "u-col-start-1" # Support existing classes - assert classname("u-bg--gray-80", "3.0.0") == "u-bg--gray-80" - assert classname("u-fg--warning", "3.0.0") == "u-fg--warning" - assert classname("u-font--medium", "3.0.0") == "u-font--medium" - assert classname("u-line-height--min", "3.0.0") == "u-line-height--min" - assert classname("u-text--right", "3.0.0") == "u-text--right" - assert classname("u-round--0-tr", "3.0.0") == "u-round--0-tr" + assert classname("u-bg--gray-80", {3, 0, 0}) == "u-bg--gray-80" + assert classname("u-fg--warning", {3, 0, 0}) == "u-fg--warning" + assert classname("u-font--medium", {3, 0, 0}) == "u-font--medium" + assert classname("u-line-height--min", {3, 0, 0}) == "u-line-height--min" + assert classname("u-text--right", {3, 0, 0}) == "u-text--right" + assert classname("u-round--0-tr", {3, 0, 0}) == "u-round--0-tr" end test "version 2.0.0" do - assert classname("u-flex", "2.0.0") == "u-flex" - assert classname("u-overflow-x-auto", "2.0.0") == "u-overflow--x" - assert classname("u-overflow-y-auto", "2.0.0") == "u-overflow--y" - assert classname("u-bg-gray-80", "2.0.0") == "u-bg--gray-80" - assert classname("u-fg-warning", "2.0.0") == "u-fg--warning" - assert classname("u-font-medium", "2.0.0") == "u-font--medium" - assert classname("u-line-height-min", "2.0.0") == "u-line-height--min" - assert classname("u-text-right", "2.0.0") == "u-text--right" - assert classname("u-border-radius-0-tr", "2.0.0") == "u-round--0-tr" - assert classname("u-flex-shrink-0", "2.0.0") == "u-flex-shrink-0" - assert classname("u-flex-grow-1", "2.0.0") == "u-flex-grow-1" - assert classname("u-flex-wrap", "2.0.0") == "u-flex-wrap" - assert classname("u-flex-col", "2.0.0") == "u-flex-col" - assert classname("u-grid-cols-3", "2.0.0") == "u-grid-cols-3" - assert classname("u-col-span-3", "2.0.0") == "u-col-span-3" - assert classname("u-col-start-1", "2.0.0") == "u-col-start-1" + assert classname("u-flex", {2, 0, 0}) == "u-flex" + assert classname("u-overflow-x-auto", {2, 0, 0}) == "u-overflow--x" + assert classname("u-overflow-y-auto", {2, 0, 0}) == "u-overflow--y" + assert classname("u-bg-gray-80", {2, 0, 0}) == "u-bg--gray-80" + assert classname("u-fg-warning", {2, 0, 0}) == "u-fg--warning" + assert classname("u-font-medium", {2, 0, 0}) == "u-font--medium" + assert classname("u-line-height-min", {2, 0, 0}) == "u-line-height--min" + assert classname("u-text-right", {2, 0, 0}) == "u-text--right" + assert classname("u-border-radius-0-tr", {2, 0, 0}) == "u-round--0-tr" + assert classname("u-flex-shrink-0", {2, 0, 0}) == "u-flex-shrink-0" + assert classname("u-flex-grow-1", {2, 0, 0}) == "u-flex-grow-1" + assert classname("u-flex-wrap", {2, 0, 0}) == "u-flex-wrap" + assert classname("u-flex-col", {2, 0, 0}) == "u-flex-col" + assert classname("u-grid-cols-3", {2, 0, 0}) == "u-grid-cols-3" + assert classname("u-col-span-3", {2, 0, 0}) == "u-col-span-3" + assert classname("u-col-start-1", {2, 0, 0}) == "u-col-start-1" end test "version 1.5.0" do - assert classname("u-flex", "1.5.0") == "u-flex" - assert classname("u-overflow-x-auto", "1.5.0") == "u-overflow--x" - assert classname("u-overflow-y-auto", "1.5.0") == "u-overflow--y" - assert classname("u-bg-gray-80", "1.5.0") == "u-bg--gray-80" - assert classname("u-fg-warning", "1.5.0") == "u-fg--warning" - assert classname("u-font-medium", "1.5.0") == "u-font--medium" - assert classname("u-line-height-min", "1.5.0") == "u-line-height--min" - assert classname("u-text-right", "1.5.0") == "u-text--right" - assert classname("u-border-radius-0-tr", "1.5.0") == "u-round--0-tr" - assert classname("u-flex-shrink-0", "1.5.0") == "u-flex__shrink-0" - assert classname("u-flex-grow-1", "1.5.0") == "u-flex__grow-1" - assert classname("u-flex-wrap", "1.5.0") == "u-flex--wrap" - assert classname("u-flex-col", "1.5.0") == "u-flex--col" - assert classname("u-grid-cols-3", "1.5.0") == "u-grid-cols-3" - assert classname("u-col-span-3", "1.5.0") == "u-col-span-3" - assert classname("u-col-start-1", "1.5.0") == "u-col-start-1" + assert classname("u-flex", {1, 5, 0}) == "u-flex" + assert classname("u-overflow-x-auto", {1, 5, 0}) == "u-overflow--x" + assert classname("u-overflow-y-auto", {1, 5, 0}) == "u-overflow--y" + assert classname("u-bg-gray-80", {1, 5, 0}) == "u-bg--gray-80" + assert classname("u-fg-warning", {1, 5, 0}) == "u-fg--warning" + assert classname("u-font-medium", {1, 5, 0}) == "u-font--medium" + assert classname("u-line-height-min", {1, 5, 0}) == "u-line-height--min" + assert classname("u-text-right", {1, 5, 0}) == "u-text--right" + assert classname("u-border-radius-0-tr", {1, 5, 0}) == "u-round--0-tr" + assert classname("u-flex-shrink-0", {1, 5, 0}) == "u-flex__shrink-0" + assert classname("u-flex-grow-1", {1, 5, 0}) == "u-flex__grow-1" + assert classname("u-flex-wrap", {1, 5, 0}) == "u-flex--wrap" + assert classname("u-flex-col", {1, 5, 0}) == "u-flex--col" + assert classname("u-grid-cols-3", {1, 5, 0}) == "u-grid-cols-3" + assert classname("u-col-span-3", {1, 5, 0}) == "u-col-span-3" + assert classname("u-col-start-1", {1, 5, 0}) == "u-col-start-1" end test "version 1.3.0" do - assert classname("u-flex", "1.3.0") == "u-flex" - assert classname("u-overflow-x-auto", "1.3.0") == "u-overflow--x" - assert classname("u-overflow-y-auto", "1.3.0") == "u-overflow--y" - assert classname("u-bg-gray-80", "1.3.0") == "u-bg--gray-80" - assert classname("u-fg-warning", "1.3.0") == "u-fg--warning" - assert classname("u-font-medium", "1.3.0") == "u-font--medium" - assert classname("u-line-height-min", "1.3.0") == "u-line-height--min" - assert classname("u-text-right", "1.3.0") == "u-text--right" - assert classname("u-border-radius-0-tr", "1.3.0") == "u-round--0-tr" - assert classname("u-flex-shrink-0", "1.3.0") == "u-flex__shrink-0" - assert classname("u-flex-grow-1", "1.3.0") == "u-flex__grow-1" - assert classname("u-flex-wrap", "1.3.0") == "u-flex--wrap" - assert classname("u-flex-col", "1.3.0") == "u-flex--col" - assert classname("u-grid-cols-3", "1.3.0") == "u-grid--3-col" - assert classname("u-col-span-3", "1.3.0") == "u-grid__col-span-3" - assert classname("u-col-start-1", "1.3.0") == "u-grid__col-1" + assert classname("u-flex", {1, 3, 0}) == "u-flex" + assert classname("u-overflow-x-auto", {1, 3, 0}) == "u-overflow--x" + assert classname("u-overflow-y-auto", {1, 3, 0}) == "u-overflow--y" + assert classname("u-bg-gray-80", {1, 3, 0}) == "u-bg--gray-80" + assert classname("u-fg-warning", {1, 3, 0}) == "u-fg--warning" + assert classname("u-font-medium", {1, 3, 0}) == "u-font--medium" + assert classname("u-line-height-min", {1, 3, 0}) == "u-line-height--min" + assert classname("u-text-right", {1, 3, 0}) == "u-text--right" + assert classname("u-border-radius-0-tr", {1, 3, 0}) == "u-round--0-tr" + assert classname("u-flex-shrink-0", {1, 3, 0}) == "u-flex__shrink-0" + assert classname("u-flex-grow-1", {1, 3, 0}) == "u-flex__grow-1" + assert classname("u-flex-wrap", {1, 3, 0}) == "u-flex--wrap" + assert classname("u-flex-col", {1, 3, 0}) == "u-flex--col" + assert classname("u-grid-cols-3", {1, 3, 0}) == "u-grid--3-col" + assert classname("u-col-span-3", {1, 3, 0}) == "u-grid__col-span-3" + assert classname("u-col-start-1", {1, 3, 0}) == "u-grid__col-1" end test "version < 1.3.0" do assert_raise( RuntimeError, ~r/version 1.1.0 of bitstyles is not supported/, - fn -> classname("u-flex", "1.1.0") end + fn -> classname("u-flex", {1, 1, 0}) end + ) + end + + test "requires a version tuple" do + assert_raise( + FunctionClauseError, + fn -> classname("u-flex", "5.0.0") end ) end end