@@ -53,16 +53,22 @@ data ElmOptions = ElmOptions
5353 argument.
5454 -}
5555 urlPrefix :: UrlPrefix
56− , elmTypeAlterations :: (EType -> EType)
56+ , elmTypeAlterations :: (EType -> EType)
5757 -- ^ Alterations to perform on ETypes before code generation.
5858 , elmAlterations :: (ETypeDef -> ETypeDef)
5959 -- ^ Alterations to perform on ETypeDefs before code generation.
60− , elmToString :: (EType -> Text)
60+ , elmToString :: (EType -> Text)
6161 -- ^ Elm functions creating a string from a given type.
6262 , emptyResponseElmTypes :: [EType]
6363 -- ^ Types that represent an empty Http response.
6464 , stringElmTypes :: [EType]
6565 -- ^ Types that represent a String.
66+ , expectJsonMethod :: Text
67+ -- ^ The function to use for JSON responses.
68+ , expectStringMethod :: Text
69+ -- ^ The function to use for string responses.
70+ , httpErrorType :: Text
71+ -- ^ The type to use for Http errors.
6672 }
6773
6874
@@ -86,6 +92,9 @@ The default options are:
8692> , stringElmTypes =
8793> [ getType (Proxy :: Proxy String)
8894> , getType (Proxy :: Proxy T.Text) ]
95+> , expectJsonMethod = "Http.expectJson"
96+> , expectStringMethod = "Http.expectString"
97+> , httpErrorType = "Http.Error"
8998> }
9099-}
91100defElmOptions :: ElmOptions
@@ -101,6 +110,9 @@ defElmOptions = ElmOptions
101110 [ toElmType (Proxy :: Proxy String)
102111 , toElmType (Proxy :: Proxy T.Text)
103112 ]
113+ , expectJsonMethod = "Http.expectJson"
114+ , expectStringMethod = "Http.expectString"
115+ , httpErrorType = "Http.Error"
104116 }
105117
106118
@@ -247,7 +259,7 @@ generateElmForRequest opts request =
247259 fnName =
248260 request ^. F.reqFuncName . to (replace . F.camelCase) . to stext
249261
250− replace = T.replace "-" "" . T.replace "." ""
262+ replace = T.replace "-" "" . T.replace "." "" . T.replace " " ""
251263
252264 typeSignature =
253265 mkTypeSignature opts request
@@ -309,7 +321,7 @@ mkTypeSignature opts request =
309321 toMsgType :: Maybe Doc
310322 toMsgType = do
311323 result <- fmap elmTypeRef $ request ^. F.reqReturnType
312− Just ("(Result Http.Error " <+> parens result <+> " -> msg)")
324+ Just ("(Result" <+> stext (httpErrorType opts) <+> parens result <+> "-> msg)")
313325
314326 returnType :: Maybe Doc
315327 returnType = do
@@ -327,7 +339,7 @@ elmCaptureArg segment =
327339 "capture_" <>
328340 F.captureArg segment ^. F.argName . to (stext . replace . F.unPathSegment)
329341 where
330− replace = T.replace "-" "_"
342+ replace = T.replace "-" "_" . T.replace " " "_"
331343
332344
333345elmQueryArg :: F.QueryArg EType -> Doc
@@ -501,11 +513,11 @@ mkRequest opts request =
501513 | isEmptyType opts $ (elmTypeAlterations opts) elmTypeExpr
502514 -- let elmConstructor = T.pack (renderElm elmTypeExpr)
503515 ->
504− "Http.expectString " <> line <+> indent i "(\\x -> case x of" <> line <+>
516+ stext (expectStringMethod opts) <> line <+> indent i "(\\x -> case x of" <> line <+>
505517 indent i "Err e -> toMsg (Err e)" <> line <+>
506518 indent i "Ok _ -> toMsg (Ok ()))"
507519 Just elmTypeExpr ->
508− "Http.expectJson toMsg" <+> renderDecoderName ((elmTypeAlterations opts) elmTypeExpr)
520+ stext (expectJsonMethod opts) <+> "toMsg" <+> renderDecoderName ((elmTypeAlterations opts) elmTypeExpr)
509521 Nothing -> error "mkHttpRequest: no reqReturnType?"
510522 -- case request ^. F.reqReturnType of
511523 -- Just elmTypeExpr | isEmptyType opts elmTypeExpr ->
@@ -563,7 +575,7 @@ mkUrl opts segments =
563575 F.Cap arg ->
564576 let
565577 toStringSrc =
566− toString opts (maybeOf (arg ^. F.argType))
578+ toString opts (elmTypeAlterations opts (maybeOf (arg ^. F.argType)))
567579 in
568580 "Url.percentEncode " <> pipeRight [elmCaptureArg s, toStringSrc]
569581