Implement more config generation.

This commit is contained in:
Dillon Kearns 2022-09-15 14:53:33 -07:00
parent aa1a4ba017
commit b4a7b0a315

View File

@ -24,6 +24,7 @@ import Gen.Json.Encode
import Gen.List import Gen.List
import Gen.Maybe import Gen.Maybe
import Gen.Pages.Internal.Platform import Gen.Pages.Internal.Platform
import Gen.Pages.Internal.RoutePattern
import Gen.Pages.ProgramConfig import Gen.Pages.ProgramConfig
import Gen.Path import Gen.Path
import Gen.Platform.Sub import Gen.Platform.Sub
@ -118,9 +119,9 @@ otherFile routes phaseString =
applyIdentityTo (Elm.val "gotBatchSub") applyIdentityTo (Elm.val "gotBatchSub")
, hotReloadData = , hotReloadData =
applyIdentityTo (Elm.val "hotReloadData") applyIdentityTo (Elm.val "hotReloadData")
, onPageChange = todo , onPageChange = Elm.val "OnPageChange"
, apiRoutes = todo , apiRoutes = todo
, pathPatterns = todo , pathPatterns = pathPatterns.reference
, basePath = todo , basePath = todo
, sendPageData = Elm.val "sendPageData" , sendPageData = Elm.val "sendPageData"
, byteEncodePageData = todo , byteEncodePageData = todo
@ -183,6 +184,18 @@ otherFile routes phaseString =
) )
|> topLevelValue "config" |> topLevelValue "config"
pathPatterns :
{ declaration : Elm.Declaration
, reference : Elm.Expression
, referenceFrom : List String -> Elm.Expression
}
pathPatterns =
topLevelValue "routePatterns3"
(routes
|> List.map routePatternToSyntax
|> Elm.list
)
globalHeadTags : globalHeadTags :
{ declaration : Elm.Declaration { declaration : Elm.Declaration
, reference : Elm.Expression , reference : Elm.Expression
@ -456,6 +469,7 @@ otherFile routes phaseString =
) )
, globalHeadTags.declaration , globalHeadTags.declaration
, encodeResponse.declaration , encodeResponse.declaration
, pathPatterns.declaration
, decodeResponse.declaration , decodeResponse.declaration
, Elm.portIncoming "hotReloadData" , Elm.portIncoming "hotReloadData"
[ Gen.Bytes.annotation_.bytes ] [ Gen.Bytes.annotation_.bytes ]
@ -481,3 +495,36 @@ todo =
pathType : Type.Annotation pathType : Type.Annotation
pathType = pathType =
Type.named [ "Path" ] "Path" Type.named [ "Path" ] "Path"
routePatternToSyntax : RoutePattern -> Elm.Expression
routePatternToSyntax route =
Gen.Pages.Internal.RoutePattern.make_.routePattern
{ segments =
route.segments
|> List.map
(\segment ->
case segment of
RoutePattern.StaticSegment name ->
Gen.Pages.Internal.RoutePattern.make_.staticSegment (Elm.string name)
RoutePattern.DynamicSegment name ->
Gen.Pages.Internal.RoutePattern.make_.dynamicSegment (Elm.string name)
)
|> Elm.list
, ending =
route.ending
|> Maybe.map
(\ending ->
case ending of
RoutePattern.Optional name ->
Gen.Pages.Internal.RoutePattern.make_.optional (Elm.string name)
RoutePattern.RequiredSplat ->
Gen.Pages.Internal.RoutePattern.make_.requiredSplat
RoutePattern.OptionalSplat ->
Gen.Pages.Internal.RoutePattern.make_.optionalSplat
)
|> Elm.maybe
}