Skip to content

Commit

Permalink
Create two separate 'version' functions
Browse files Browse the repository at this point in the history
  • Loading branch information
angelikatyborska committed Jul 24, 2024
1 parent 8c1341a commit 7e6333a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion lib/bitstyles_phoenix.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ defmodule BitstylesPhoenix do
### Bitstyles version
BitstylesPhoenix will generate classes #{BitstylesPhoenix.Bitstyles.version(:string)} of bitstyles.
BitstylesPhoenix will generate classes #{BitstylesPhoenix.Bitstyles.version_string()} of bitstyles.
You can set older versions with a configuration:
```elixir
Expand Down
30 changes: 14 additions & 16 deletions lib/bitstyles_phoenix/bitstyles.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ defmodule BitstylesPhoenix.Bitstyles do
when target_version < version and current_version >= version

def cdn_url do
"#{@cdn_url}@#{version(:string)}"
"#{@cdn_url}@#{version_string()}"
end

@doc """
Returns the classnames for the configured version.
Input classnames are assumed to be from the #{@default_version} version of bitstyles.
"""
def classname(name), do: classname(name, version(:tuple))
def classname(name), do: classname(name, version())

def classname(class, version) when is_tuple(version) do
downgrade_classname(class, version, default_version(:tuple))
downgrade_classname(class, version, default_version())
end

# Note about class renaming:
Expand Down Expand Up @@ -162,25 +162,23 @@ defmodule BitstylesPhoenix.Bitstyles do
""")
end

def version(format \\ :tuple) do
bitstyles_version_override = Process.get(:bitstyles_phoenix_bistyles_version)
def version() do
version_to_tuple(version_string())
end

version =
bitstyles_version_override ||
Application.get_env(:bitstyles_phoenix, :bitstyles_version, @default_version)
def version_string() do
bitstyles_version_override = Process.get(:bitstyles_phoenix_bistyles_version)

get_version_in_format(version, format)
bitstyles_version_override ||
Application.get_env(:bitstyles_phoenix, :bitstyles_version, @default_version)
end

def default_version(format \\ :tuple) do
get_version_in_format(@default_version, format)
def default_version() do
version_to_tuple(@default_version)
end

defp get_version_in_format(version, format) do
case format do
:tuple -> version_to_tuple(version)
:string -> version_to_string(version)
end
def default_version_string do
@default_version
end

defp version_to_tuple(version) when is_tuple(version), do: version
Expand Down
6 changes: 3 additions & 3 deletions lib/bitstyles_phoenix/component/button.ex
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ defmodule BitstylesPhoenix.Component.Button do
extra = assigns_to_attributes(assigns, [:icon, :class, :color, :shape, :variant])

assigns =
if Bitstyles.version(:tuple) >= {5, 0, 0} && assigns[:variant] do
if Bitstyles.version() >= {5, 0, 0} && assigns[:variant] do
IO.warn("Attribute `variant` is deprecated in ui_button/1! Change to `color` and `shape`")

assigns
Expand All @@ -298,7 +298,7 @@ defmodule BitstylesPhoenix.Component.Button do
end

classes =
if Bitstyles.version(:tuple) >= {5, 0, 0} do
if Bitstyles.version() >= {5, 0, 0} do
color_and_shape_classes(assigns[:color], assigns[:shape])
else
variant_classes(assigns[:variant])
Expand Down Expand Up @@ -538,7 +538,7 @@ defmodule BitstylesPhoenix.Component.Button do
extra = assigns_to_attributes(assigns, [:icon, :label, :reversed, :color, :title])

extra =
if Bitstyles.version(:tuple) >= {5, 0, 0} do
if Bitstyles.version() >= {5, 0, 0} do
if assigns[:reversed] do
Keyword.put_new(extra, :"data-theme", "dark")
else
Expand Down
2 changes: 1 addition & 1 deletion lib/bitstyles_phoenix/component/description_list.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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(:tuple) >= {5, 0, 0} do
if Bitstyles.version() >= {5, 0, 0} do
"u-gap-l"
else
"u-gap-m"
Expand Down
4 changes: 2 additions & 2 deletions lib/bitstyles_phoenix/component/dropdown.ex
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ defmodule BitstylesPhoenix.Component.Dropdown do
assigns_from_single_slot(assigns, :button, exclude: [:label, :icon_file])

button_extra =
if Bitstyles.version(:tuple) >= {5, 0, 0} do
if Bitstyles.version() >= {5, 0, 0} do
button_extra
|> Keyword.put_new(:color, :secondary)
else
Expand Down Expand Up @@ -516,7 +516,7 @@ defmodule BitstylesPhoenix.Component.Dropdown do
|> assigns_to_attributes()

extra =
if Bitstyles.version(:tuple) >= {5, 0, 0} do
if Bitstyles.version() >= {5, 0, 0} do
extra
|> Keyword.put_new(:shape, "menu")
|> Keyword.put_new(:color, "transparent")
Expand Down
2 changes: 1 addition & 1 deletion lib/bitstyles_phoenix/showcase.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule BitstylesPhoenix.Showcase do

defmacro story(name, doctest_iex_code, doctest_expected_results, opts \\ []) do
default_version =
BitstylesPhoenix.Bitstyles.default_version(:string)
BitstylesPhoenix.Bitstyles.default_version_string()
|> String.to_atom()

doctest_expected_results =
Expand Down

0 comments on commit 7e6333a

Please sign in to comment.