elm-matrix-sdk-beta/dev/Route.elm

71 lines
1.2 KiB
Elm
Raw Permalink Normal View History

2024-01-23 12:41:19 +00:00
module Route exposing (..)
{-| This module helps parse the URL route into explicable data.
-}
import Url
import Url.Parser as P exposing ((</>))
type Route
= Home
| NotFound
| ViewObject String
toRoute : Url.Url -> Route
toRoute url =
P.parse routeParser url |> Maybe.withDefault NotFound
2024-01-23 17:45:19 +00:00
toPath : Route -> String
toPath route =
case route of
Home ->
"/"
NotFound ->
"/"
ViewObject o ->
"/object/" ++ o
2024-01-23 12:41:19 +00:00
toString : Route -> String
toString route =
case route of
Home ->
"Home"
NotFound ->
"404"
ViewObject o ->
o
routeParser : P.Parser (Route -> a) a
routeParser =
P.oneOf
[ P.top
|> P.map Home
, P.s "elm-matrix-sdk-beta"
|> P.map Home
2024-01-23 12:41:19 +00:00
, P.s "home"
|> P.map Home
, P.s "index"
|> P.map Home
, P.s "dev"
2024-01-23 17:45:19 +00:00
</> P.s "Main.elm"
2024-01-23 12:41:19 +00:00
|> P.map Home
, P.s "elm-matrix-sdk-beta"
</> P.top
|> P.map Home
2024-01-23 12:41:19 +00:00
, P.s "object"
</> P.string
|> P.map ViewObject
, P.s "object"
</> P.top
|> P.map (ViewObject "")
]