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

Elm: Add support for date, date time #689

Merged
merged 4 commits into from
Oct 25, 2023
Merged
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
10 changes: 5 additions & 5 deletions elm-generator/src/main/scala/generator/elm/ElmEnum.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ case class ElmEnum(args: GenArgs) {
// "type MemberStatus = MemberStatusPending | MemberStatusActive | MemberStatusInactive | MemberStatusUnknown"
def generate(e: Enum): String = {
Seq(
s"type ${Names.pascalCase(e.name)} = " + values(e).mkString(" | "),
s"type ${Names.pascalCase(e.name)}\n = " + values(e).mkString("\n | "),
genToString(e).code,
genFromString(e).code,
genEncoder(e).code,
Expand Down Expand Up @@ -79,11 +79,11 @@ case class ElmEnum(args: GenArgs) {
/*
memberStatusFromString : String -> MemberStatus
memberStatusFromString value =
if (value == "active") then
if value == "active" then
MemberStatusActive
else if (value == "pending") then
else if value == "pending" then
MemberStatusPending
else if (value == "inactive") then
else if value == "inactive" then
MemberStatusInactive
else
MemberStatusUnknown
Expand All @@ -92,7 +92,7 @@ case class ElmEnum(args: GenArgs) {
def singleValue(isFirst: Boolean, name: String, value: String) = {
val prefix = if (isFirst) { "" } else { "else " }
Seq(
s"${prefix}if (value == ${Names.wrapInQuotes(value)}) then",
s"${prefix}if value == ${Names.wrapInQuotes(value)} then",
s" $name"
).mkString("\n").indent(4)
}
Expand Down
20 changes: 16 additions & 4 deletions elm-generator/src/main/scala/generator/elm/ElmModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,14 @@ case class ElmModel(args: GenArgs) {
case Double => "Encode.float"
case Integer => "Encode.int"
case Long => "Encode.int"
case DateIso8601 => "Encode.string"
case DateTimeIso8601 => "Encode.string"
case DateIso8601 => {
args.imports.addAs("Util.DateFormatter", "DateFormatter")
"DateFormatter.encode"
}
case DateTimeIso8601 => {
args.imports.addAs("Iso8601", "Iso8601")
"Iso8601.encode"
}
case Decimal => "Encode.float"
case Object => "Encode.string" // TODO
case JsonValue => "Encode.string" // TODO
Expand Down Expand Up @@ -199,8 +205,14 @@ case class ElmModel(args: GenArgs) {
case Double => "Decode.float"
case Integer => "Decode.int"
case Long => "Decode.int"
case DateIso8601 => "Decode.string"
case DateTimeIso8601 => "Decode.string"
case DateIso8601 => {
args.imports.addAs("Util.DateFormatter", "DateFormatter")
"DateFormatter.decoder"
}
case DateTimeIso8601 => {
args.imports.addAs("Iso8601", "Iso8601")
"Iso8601.decoder"
}
case Decimal => "Decode.float"
case Object => "Decode.string" // TODO
case JsonValue => "Decode.string" // TODO
Expand Down
10 changes: 8 additions & 2 deletions elm-generator/src/main/scala/generator/elm/ElmType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ case class ElmType(args: GenArgs) {
case Double => "Float"
case Integer => "Int"
case Long => "Int"
case DateIso8601 => "String"
case DateTimeIso8601 => "String"
case DateIso8601 => {
args.imports.addExposing("Date", "Date")
"Date"
}
case DateTimeIso8601 => {
args.imports.addExposing("Time", "Posix")
"Posix"
}
case Decimal => "Float"
case Object => "String" // TODO
case JsonValue => "String" // TODO
Expand Down