Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the decoder convention from decodeX to xDecoder #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions elm/TypeAlias.elm
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ capitalize name =
x :: xs ->
(String.toUpper (String.fromChar x)) ++ (String.fromList xs)

unCapitalize : String -> String
unCapitalize name =
case String.toList name of
[] ->
""

x :: xs ->
(String.toLower (String.fromChar x)) ++ (String.fromList xs)

badCharsRegex : Regex
badCharsRegex =
Expand Down
21 changes: 10 additions & 11 deletions elm/TypeAlias/O17.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module TypeAlias.O17 exposing (..)

import Regex exposing (regex, replace)
import Types
import TypeAlias exposing (TypeAlias, Field, capitalize, getFields, getTypeAliasName, getFieldNameAndType, prefixers, knownDecoders)
import TypeAlias exposing (TypeAlias, Field, capitalize, unCapitalize, getFields, getTypeAliasName, getFieldNameAndType, prefixers, knownDecoders)


formatDecoderField : Field -> String
Expand Down Expand Up @@ -72,12 +72,11 @@ createDecoder string =
|> String.join "\n "
in
String.join ""
[ "decode"
, typeName
[ unCapitalize (typeName ++ "Decoder")
, " : Json.Decode.Decoder "
, typeName
, "\ndecode"
, typeName
, "\n"
, unCapitalize (typeName ++ "Decoder")
, " =\n Json.Decode.succeed "
, typeName
, "\n "
Expand All @@ -103,12 +102,11 @@ createPipelineDecoder string =
|> String.join "\n "
in
String.join ""
[ "decode"
, typeName
[ unCapitalize (typeName ++ "Decoder")
, " : Json.Decode.Decoder "
, typeName
, "\ndecode"
, typeName
, "\n"
, unCapitalize (typeName ++ "Decoder")
, " =\n Json.Decode.Pipeline.decode "
, typeName
, "\n "
Expand Down Expand Up @@ -169,7 +167,8 @@ runtimeGuessDecoder field =
else
"$Json$Decode." ++ lower
else
"decode" ++ (capitalize typeName)
unCapitalize (typeName ++ "Decoder")

in
typeNames
|> List.map guessSingleDecoder
Expand All @@ -192,7 +191,7 @@ runtimeGuessEncoder field =
else
"$Json$Encode." ++ lower
else
"decode" ++ (capitalize typeName)
unCapitalize (typeName ++ "Decoder")


runtimeDecodeField : Field -> String
Expand Down
20 changes: 9 additions & 11 deletions elm/TypeAlias/O18.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module TypeAlias.O18 exposing (..)

import Regex exposing (regex, replace)
import Types
import TypeAlias exposing (TypeAlias, Field, capitalize, getFields, getTypeAliasName, getFieldNameAndType, prefixers, knownDecoders)
import TypeAlias exposing (TypeAlias, Field, capitalize, unCapitalize, getFields, getTypeAliasName, getFieldNameAndType, prefixers, knownDecoders)


formatDecoderField : Field -> String
Expand Down Expand Up @@ -84,12 +84,11 @@ createDecoder string =
"import Json.Decode.Pipeline\n\n" ++ (createPipelineDecoder string)
else
String.join ""
[ "decode"
, typeName
[ unCapitalize (typeName ++ "Decoder")
, " : Json.Decode.Decoder "
, typeName
, "\ndecode"
, typeName
, "\n"
, unCapitalize (typeName ++ "Decoder")
, " =\n Json.Decode."
, mapName
, " "
Expand Down Expand Up @@ -117,12 +116,11 @@ createPipelineDecoder string =
|> String.join "\n "
in
String.join ""
[ "decode"
, typeName
[ unCapitalize (typeName ++ "Decoder")
, " : Json.Decode.Decoder "
, typeName
, "\ndecode"
, typeName
, "\n"
, unCapitalize (typeName ++ "Decoder")
, " =\n Json.Decode.Pipeline.decode "
, typeName
, "\n "
Expand Down Expand Up @@ -183,7 +181,7 @@ runtimeGuessDecoder field =
else
"$Json$Decode." ++ lower
else
"decode" ++ (capitalize typeName)
unCapitalize (typeName ++ "Decoder")
in
typeNames
|> List.map guessSingleDecoder
Expand All @@ -206,7 +204,7 @@ runtimeGuessEncoder field =
else
"$Json$Encode." ++ lower
else
"decode" ++ (capitalize typeName)
unCapitalize (typeName ++ "Decoder")


runtimeDecodeField : Field -> String
Expand Down