2022-09-15 20:59:33 +03:00
|
|
|
module GenerateMain exposing (..)
|
|
|
|
|
|
|
|
import Elm exposing (File)
|
|
|
|
import Elm.Annotation as Type
|
|
|
|
import Elm.Case
|
|
|
|
import Elm.CodeGen
|
|
|
|
import Elm.Declare
|
|
|
|
import Elm.Op
|
|
|
|
import Elm.Pretty
|
|
|
|
import Gen.Basics
|
|
|
|
import Gen.CodeGen.Generate exposing (Error)
|
|
|
|
import Gen.Html
|
|
|
|
import Gen.Html.Attributes
|
|
|
|
import Gen.List
|
|
|
|
import Gen.Path
|
|
|
|
import Gen.Server.Response
|
|
|
|
import Gen.String
|
|
|
|
import Gen.Tuple
|
2022-09-15 21:11:05 +03:00
|
|
|
import Gen.Url
|
2022-09-15 20:59:33 +03:00
|
|
|
import Pages.Internal.RoutePattern as RoutePattern exposing (RoutePattern)
|
|
|
|
import Pretty
|
|
|
|
import Regex exposing (Regex)
|
|
|
|
|
|
|
|
|
|
|
|
otherFile : List RoutePattern.RoutePattern -> File
|
|
|
|
otherFile routes =
|
|
|
|
Elm.file [ "Main" ]
|
|
|
|
[ Elm.alias "Model"
|
|
|
|
(Type.record
|
|
|
|
[ ( "global", Type.named [ "Shared" ] "Model" )
|
|
|
|
, ( "page", Type.named [] "PageModel" )
|
|
|
|
, ( "current"
|
|
|
|
, Type.maybe
|
|
|
|
(Type.record
|
|
|
|
[ ( "path", Type.named [ "Path" ] "Path" )
|
|
|
|
, ( "query", Type.named [ "Path" ] "Path" |> Type.maybe )
|
|
|
|
, ( "fragment", Type.string |> Type.maybe )
|
|
|
|
]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
, Elm.customType "PageModel"
|
|
|
|
((routes
|
|
|
|
|> List.map
|
|
|
|
(\route ->
|
|
|
|
Elm.variantWith
|
|
|
|
("Model"
|
|
|
|
++ (RoutePattern.toModuleName route |> String.join "__")
|
|
|
|
)
|
|
|
|
[ Type.named
|
|
|
|
("Route"
|
|
|
|
:: RoutePattern.toModuleName route
|
|
|
|
)
|
|
|
|
"Model"
|
|
|
|
]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
++ [ Elm.variantWith "ModelErrorPage____"
|
|
|
|
[ Type.named [ "ErrorPage" ] "Model" ]
|
|
|
|
, Elm.variant "NotFound"
|
|
|
|
]
|
|
|
|
)
|
2022-09-15 21:11:05 +03:00
|
|
|
, Elm.customType "Msg"
|
|
|
|
((routes
|
|
|
|
|> List.map
|
|
|
|
(\route ->
|
|
|
|
Elm.variantWith
|
|
|
|
("Msg"
|
|
|
|
++ (RoutePattern.toModuleName route |> String.join "__")
|
|
|
|
)
|
|
|
|
[ Type.named
|
|
|
|
("Route"
|
|
|
|
:: RoutePattern.toModuleName route
|
|
|
|
)
|
|
|
|
"Msg"
|
|
|
|
]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
++ [ Elm.variantWith "MsgGlobal" [ Type.named [ "Shared" ] "Msg" ]
|
|
|
|
, Elm.variantWith "OnPageChange"
|
|
|
|
[ Type.record
|
|
|
|
[ ( "protocol", Gen.Url.annotation_.protocol )
|
|
|
|
, ( "host", Type.string )
|
|
|
|
, ( "port_", Type.maybe Type.int )
|
|
|
|
, ( "path", pathType )
|
|
|
|
, ( "query", Type.maybe Type.string )
|
|
|
|
, ( "fragment", Type.maybe Type.string )
|
|
|
|
, ( "metadata", Type.maybe (Type.named [ "Route" ] "Route") )
|
|
|
|
]
|
|
|
|
]
|
|
|
|
, Elm.variantWith "MsgErrorPage____" [ Type.named [ "ErrorPage" ] "Msg" ]
|
|
|
|
]
|
|
|
|
)
|
|
|
|
, Elm.customType "PageData"
|
|
|
|
((routes
|
|
|
|
|> List.map
|
|
|
|
(\route ->
|
|
|
|
Elm.variantWith
|
|
|
|
("Data"
|
|
|
|
++ (RoutePattern.toModuleName route |> String.join "__")
|
|
|
|
)
|
|
|
|
[ Type.named
|
|
|
|
("Route"
|
|
|
|
:: RoutePattern.toModuleName route
|
|
|
|
)
|
|
|
|
"Data"
|
|
|
|
]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
++ [ Elm.variant "Data404NotFoundPage____"
|
|
|
|
, Elm.variantWith "DataErrorPage____" [ Type.named [ "ErrorPage" ] "ErrorPage" ]
|
|
|
|
]
|
|
|
|
)
|
|
|
|
, Elm.customType "ActionData"
|
|
|
|
(routes
|
|
|
|
|> List.map
|
|
|
|
(\route ->
|
|
|
|
Elm.variantWith
|
|
|
|
("ActionData"
|
|
|
|
++ (RoutePattern.toModuleName route |> String.join "__")
|
|
|
|
)
|
|
|
|
[ Type.named
|
|
|
|
("Route"
|
|
|
|
:: RoutePattern.toModuleName route
|
|
|
|
)
|
|
|
|
"ActionData"
|
|
|
|
]
|
|
|
|
)
|
|
|
|
)
|
2022-09-15 20:59:33 +03:00
|
|
|
]
|
2022-09-15 21:11:05 +03:00
|
|
|
|
|
|
|
|
|
|
|
pathType : Type.Annotation
|
|
|
|
pathType =
|
|
|
|
Type.named [ "Path" ] "Path"
|