Update elm-pages add codegen template.

This commit is contained in:
Dillon Kearns 2022-05-13 11:56:18 -07:00
parent 484d45bf5e
commit 05f2702e97

View File

@ -51,9 +51,9 @@ function fileContentWithParams(
serverRender, serverRender,
withFallback withFallback
) { ) {
return `module Route.${pageModuleName} exposing (Model, Msg, Data, route) return `module Route.${pageModuleName} exposing (ActionData, Model, Msg, Data, route)
${serverRender ? `import Server.Request as Request\n` : ""} ${serverRender ? `import Pages.Msg\nimport Server.Request as Request\n` : ""}
${withState ? "\nimport Effect exposing (Effect)" : ""} ${withState ? "\nimport Effect exposing (Effect)" : ""}
import DataSource exposing (DataSource) import DataSource exposing (DataSource)
${serverRender ? `import ErrorPage exposing (ErrorPage)` : ""} ${serverRender ? `import ErrorPage exposing (ErrorPage)` : ""}
@ -89,8 +89,8 @@ type alias RouteParams =
route : ${ route : ${
withState withState
? "StatefulRoute RouteParams Data Model Msg" ? "StatefulRoute RouteParams Data ActionData Model Msg"
: "StatelessRoute RouteParams Data" : "StatelessRoute RouteParams Data ActionData"
} }
route = route =
${ ${
@ -98,6 +98,7 @@ route =
? `RouteBuilder.serverRender ? `RouteBuilder.serverRender
{ head = head { head = head
, data = data , data = data
, action = action
}` }`
: withFallback : withFallback
? `RouteBuilder.preRenderWithFallback { head = head ? `RouteBuilder.preRenderWithFallback { head = head
@ -132,7 +133,7 @@ ${
init : init :
Maybe PageUrl Maybe PageUrl
-> Shared.Model -> Shared.Model
-> StaticPayload Data RouteParams -> StaticPayload Data ActionData RouteParams
-> ( Model, Effect Msg ) -> ( Model, Effect Msg )
init maybePageUrl sharedModel static = init maybePageUrl sharedModel static =
( {}, Effect.none ) ( {}, Effect.none )
@ -141,7 +142,7 @@ init maybePageUrl sharedModel static =
update : update :
PageUrl PageUrl
-> Shared.Model -> Shared.Model
-> StaticPayload Data RouteParams -> StaticPayload Data ActionData RouteParams
-> Msg -> Msg
-> Model -> Model
-> ${ -> ${
@ -180,6 +181,10 @@ type alias Data =
{} {}
type alias ActionData =
{}
${ ${
serverRender serverRender
? `data : RouteParams -> Request.Parser (DataSource (Response Data ErrorPage)) ? `data : RouteParams -> Request.Parser (DataSource (Response Data ErrorPage))
@ -205,8 +210,16 @@ data =`
: `DataSource.succeed Data` : `DataSource.succeed Data`
} }
${
serverRender
? `action : RouteParams -> Request.Parser (DataSource (Response ActionData ErrorPage))
action routeParams =
Request.skip "No action."
`
: ""
}
head : head :
StaticPayload Data RouteParams StaticPayload Data ActionData RouteParams
-> List Head.Tag -> List Head.Tag
head static = head static =
Seo.summary Seo.summary
@ -232,18 +245,17 @@ ${
Maybe PageUrl Maybe PageUrl
-> Shared.Model -> Shared.Model
-> Model -> Model
-> StaticPayload Data RouteParams -> StaticPayload Data ActionData RouteParams
-> View Msg -> View ${serverRender ? "(Pages.Msg.Msg Msg)" : "Msg"}
view maybeUrl sharedModel model static = view maybeUrl sharedModel model static =
` `
: `view : : `view :
Maybe PageUrl Maybe PageUrl
-> Shared.Model -> Shared.Model
-> StaticPayload Data RouteParams -> StaticPayload Data ActionData RouteParams
-> View Msg -> View ${serverRender ? "(Pages.Msg.Msg Msg)" : "Msg"}
view maybeUrl sharedModel static =` view maybeUrl sharedModel static =`
} } View.placeholder "${pageModuleName}"
View.placeholder "${pageModuleName}"
`; `;
} }