Build up more generated Main code.

This commit is contained in:
Dillon Kearns 2022-09-15 14:05:21 -07:00
parent 5b4754de37
commit 3eb61c8151
2 changed files with 45 additions and 2 deletions

View File

@ -216,7 +216,32 @@ otherFile routes phaseString =
getStaticRoutes =
topLevelValue "getStaticRoutes"
(Gen.DataSource.combine
[]
(routes
|> List.map
(\route ->
Elm.value
{ name = "route"
, annotation = Nothing
, importFrom = "Route" :: (route |> RoutePattern.toModuleName)
}
|> Elm.get "staticRoutes"
|> Gen.DataSource.map
(Gen.List.call_.map
(if RoutePattern.hasRouteParams route then
Elm.value
{ annotation = Nothing
, name =
(route |> RoutePattern.toModuleName)
|> String.join "__"
, importFrom = [ "Route" ]
}
else
todo
)
)
)
)
|> Gen.DataSource.call_.map Gen.List.values_.concat
|> Elm.withType
(Gen.DataSource.annotation_.dataSource

View File

@ -1,6 +1,6 @@
module Pages.Internal.RoutePattern exposing
( Ending(..), RoutePattern, Segment(..), view, toVariant, routeToBranch
, Param(..), RouteParam(..), fromModuleName, toModuleName, toRouteParamTypes, toRouteParamsRecord, toVariantName
, Param(..), RouteParam(..), fromModuleName, hasRouteParams, toModuleName, toRouteParamTypes, toRouteParamsRecord, toVariantName
)
{-| Exposed for internal use only (used in generated code).
@ -241,6 +241,24 @@ type RouteParam
| OptionalSplatParam2
hasRouteParams : RoutePattern -> Bool
hasRouteParams route =
route
|> toVariantName
|> .params
|> List.any (not << isStatic)
isStatic : RouteParam -> Bool
isStatic routeParam =
case routeParam of
StaticParam _ ->
True
_ ->
False
toVariantName : RoutePattern -> { variantName : String, params : List RouteParam }
toVariantName route =
let