Skip to content

Commit

Permalink
Update artemis.gen.resource mix task
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislaskey committed Apr 5, 2021
1 parent 7cf21c0 commit a155e7f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
20 changes: 20 additions & 0 deletions apps/artemis/lib/mix/task_helpers/strings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,24 @@ defmodule Mix.TaskHelpers.Strings do
|> Enum.map(&String.capitalize/1)
|> Enum.join("")
end

@doc """
Returns true if value is a single word
"""
def single_word?(value) do
count =
value
|> snakecase()
|> String.split("_")
|> length()

count == 1
end

@doc """
Returns true if value contains multiple words
"""
def multi_word?(value) do
!single_word?(value)
end
end
29 changes: 20 additions & 9 deletions apps/artemis/lib/mix/tasks/artemis.gen.resource.ex
Original file line number Diff line number Diff line change
Expand Up @@ -195,15 +195,26 @@ defmodule Mix.Tasks.Artemis.Gen.Resource do
source_single_dashcase = dashcase(source_single_snakecase_lower)
target_single_dashcase = dashcase(target_single_snakecase_lower)

case_order = [
:spacecase,
:modulecase,
:dashcase,
:snakecase_lower,
:snakecase_upper,
:spacecase_lower,
:spacecase_upper
]
case_order =
case single_word?(source_single_spacecase) && multi_word?(target_single_spacecase) do
true ->
[
:modulecase,
:snakecase_lower,
:snakecase_upper
]

false ->
[
:spacecase,
:modulecase,
:dashcase,
:snakecase_lower,
:snakecase_upper,
:spacecase_lower,
:spacecase_upper
]
end

cases = %{
source: %{
Expand Down

0 comments on commit a155e7f

Please sign in to comment.