aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Page.elm
blob: 7cfbbc7208a8e077f0da02ee96bb2b88a2c61841 (plain)
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
module Page exposing
  ( Page(..)
  , toHash
  , fromHash
  )

import Navigation
import UrlParser exposing (..)
import String

type Page =
  Home
  | Income
  | Statistics

toHash : Page -> String
toHash page =
  case page of
    Home -> "#"
    Income -> "#income"
    Statistics -> "#statistics"

fromHash : Navigation.Location -> Result String Page
fromHash location = UrlParser.parse identity pageParser (String.dropLeft 1 location.hash)

pageParser : Parser (Page -> a) a
pageParser =
  oneOf
    [ format Home (s "")
    , format Income (s "income")
    , format Statistics (s "statistics")
    ]