mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-23 14:15:33 +03:00
Build up more generated Main code.
This commit is contained in:
parent
5b4754de37
commit
3eb61c8151
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user