diff --git a/elm-generator/src/main/scala/generator/elm/ElmEnum.scala b/elm-generator/src/main/scala/generator/elm/ElmEnum.scala index fb6246e9..05e67e7f 100644 --- a/elm-generator/src/main/scala/generator/elm/ElmEnum.scala +++ b/elm-generator/src/main/scala/generator/elm/ElmEnum.scala @@ -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, @@ -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 @@ -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) } diff --git a/elm-generator/src/main/scala/generator/elm/ElmModel.scala b/elm-generator/src/main/scala/generator/elm/ElmModel.scala index c95e6dec..d2219efa 100644 --- a/elm-generator/src/main/scala/generator/elm/ElmModel.scala +++ b/elm-generator/src/main/scala/generator/elm/ElmModel.scala @@ -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 @@ -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 diff --git a/elm-generator/src/main/scala/generator/elm/ElmType.scala b/elm-generator/src/main/scala/generator/elm/ElmType.scala index a1928afc..fcb57524 100644 --- a/elm-generator/src/main/scala/generator/elm/ElmType.scala +++ b/elm-generator/src/main/scala/generator/elm/ElmType.scala @@ -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