-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathRoute.elm
55 lines (33 loc) · 975 Bytes
/
Route.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
module Route exposing (Route(..), fromLocation, href)
import Html exposing (Attribute)
import Html.Attributes as Attr
import Showcase exposing (Showcase)
import Url exposing (Url)
import Url.Parser exposing ((</>), Parser, custom, oneOf, parse, s, string)
-- ROUTING --
type Route
= ShowcasePage Showcase
route : Parser (Route -> a) a
route =
oneOf
[ Url.Parser.map ShowcasePage <| s "json-form" </> s "showcase" </> showcaseParser
]
showcaseParser =
custom "SHOWCASE" Showcase.getShowcaseById
-- INTERNAL --
routeToString : Route -> String
routeToString page =
let
pieces =
case page of
ShowcasePage sc ->
[ "showcase", sc |> Showcase.getShowcaseId ]
in
"/json-form/" ++ String.join "/" pieces
-- PUBLIC HELPERS --
href : Route -> Attribute msg
href =
routeToString >> Attr.href
fromLocation : Url -> Maybe Route
fromLocation url =
parse route url