Skip to content

Commit 7e6333a

Browse files
Create two separate 'version' functions
1 parent 8c1341a commit 7e6333a

File tree

6 files changed

+22
-24
lines changed

6 files changed

+22
-24
lines changed

lib/bitstyles_phoenix.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ defmodule BitstylesPhoenix do
4848
4949
### Bitstyles version
5050
51-
BitstylesPhoenix will generate classes #{BitstylesPhoenix.Bitstyles.version(:string)} of bitstyles.
51+
BitstylesPhoenix will generate classes #{BitstylesPhoenix.Bitstyles.version_string()} of bitstyles.
5252
You can set older versions with a configuration:
5353
5454
```elixir

lib/bitstyles_phoenix/bitstyles.ex

+14-16
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ defmodule BitstylesPhoenix.Bitstyles do
88
when target_version < version and current_version >= version
99

1010
def cdn_url do
11-
"#{@cdn_url}@#{version(:string)}"
11+
"#{@cdn_url}@#{version_string()}"
1212
end
1313

1414
@doc """
1515
Returns the classnames for the configured version.
1616
Input classnames are assumed to be from the #{@default_version} version of bitstyles.
1717
"""
18-
def classname(name), do: classname(name, version(:tuple))
18+
def classname(name), do: classname(name, version())
1919

2020
def classname(class, version) when is_tuple(version) do
21-
downgrade_classname(class, version, default_version(:tuple))
21+
downgrade_classname(class, version, default_version())
2222
end
2323

2424
# Note about class renaming:
@@ -162,25 +162,23 @@ defmodule BitstylesPhoenix.Bitstyles do
162162
""")
163163
end
164164

165-
def version(format \\ :tuple) do
166-
bitstyles_version_override = Process.get(:bitstyles_phoenix_bistyles_version)
165+
def version() do
166+
version_to_tuple(version_string())
167+
end
167168

168-
version =
169-
bitstyles_version_override ||
170-
Application.get_env(:bitstyles_phoenix, :bitstyles_version, @default_version)
169+
def version_string() do
170+
bitstyles_version_override = Process.get(:bitstyles_phoenix_bistyles_version)
171171

172-
get_version_in_format(version, format)
172+
bitstyles_version_override ||
173+
Application.get_env(:bitstyles_phoenix, :bitstyles_version, @default_version)
173174
end
174175

175-
def default_version(format \\ :tuple) do
176-
get_version_in_format(@default_version, format)
176+
def default_version() do
177+
version_to_tuple(@default_version)
177178
end
178179

179-
defp get_version_in_format(version, format) do
180-
case format do
181-
:tuple -> version_to_tuple(version)
182-
:string -> version_to_string(version)
183-
end
180+
def default_version_string do
181+
@default_version
184182
end
185183

186184
defp version_to_tuple(version) when is_tuple(version), do: version

lib/bitstyles_phoenix/component/button.ex

+3-3
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ defmodule BitstylesPhoenix.Component.Button do
287287
extra = assigns_to_attributes(assigns, [:icon, :class, :color, :shape, :variant])
288288

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

293293
assigns
@@ -298,7 +298,7 @@ defmodule BitstylesPhoenix.Component.Button do
298298
end
299299

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

540540
extra =
541-
if Bitstyles.version(:tuple) >= {5, 0, 0} do
541+
if Bitstyles.version() >= {5, 0, 0} do
542542
if assigns[:reversed] do
543543
Keyword.put_new(extra, :"data-theme", "dark")
544544
else

lib/bitstyles_phoenix/component/description_list.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ defmodule BitstylesPhoenix.Component.DescriptionList do
161161

162162
# 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
163163
gap_class =
164-
if Bitstyles.version(:tuple) >= {5, 0, 0} do
164+
if Bitstyles.version() >= {5, 0, 0} do
165165
"u-gap-l"
166166
else
167167
"u-gap-m"

lib/bitstyles_phoenix/component/dropdown.ex

+2-2
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ defmodule BitstylesPhoenix.Component.Dropdown do
456456
assigns_from_single_slot(assigns, :button, exclude: [:label, :icon_file])
457457

458458
button_extra =
459-
if Bitstyles.version(:tuple) >= {5, 0, 0} do
459+
if Bitstyles.version() >= {5, 0, 0} do
460460
button_extra
461461
|> Keyword.put_new(:color, :secondary)
462462
else
@@ -516,7 +516,7 @@ defmodule BitstylesPhoenix.Component.Dropdown do
516516
|> assigns_to_attributes()
517517

518518
extra =
519-
if Bitstyles.version(:tuple) >= {5, 0, 0} do
519+
if Bitstyles.version() >= {5, 0, 0} do
520520
extra
521521
|> Keyword.put_new(:shape, "menu")
522522
|> Keyword.put_new(:color, "transparent")

lib/bitstyles_phoenix/showcase.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ defmodule BitstylesPhoenix.Showcase do
66

77
defmacro story(name, doctest_iex_code, doctest_expected_results, opts \\ []) do
88
default_version =
9-
BitstylesPhoenix.Bitstyles.default_version(:string)
9+
BitstylesPhoenix.Bitstyles.default_version_string()
1010
|> String.to_atom()
1111

1212
doctest_expected_results =

0 commit comments

Comments
 (0)