-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathSnapshot.Html.purs
60 lines (44 loc) · 1.45 KB
/
Snapshot.Html.purs
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
56
57
58
59
60
module Snapshot.Html (Html, test) where
import Prelude hiding (discard)
import Data.Array as Array
class BuildArray a b c | a b -> c where
buildArray :: a -> b -> Array c
instance BuildArray (Array a) (Array a) a where
buildArray = append
else instance BuildArray a (Array a) a where
buildArray = Array.cons
else instance BuildArray (Array a) a a where
buildArray = Array.snoc
else instance BuildArray a a a where
buildArray a b = [ a, b ]
discard :: forall a b c. BuildArray a b c => a -> (Unit -> b) -> Array c
discard a k = buildArray a (k unit)
data Html = Elem String (Array Html) | Text String
class BuildChildren a where
buildChildren :: a -> Array Html
instance BuildChildren Html where
buildChildren = pure
instance BuildChildren (Array Html) where
buildChildren = identity
section :: forall a. BuildChildren a => a -> Html
section = Elem "section" <<< buildChildren
article :: forall a. BuildChildren a => a -> Html
article = Elem "article" <<< buildChildren
h1 :: forall a. BuildChildren a => a -> Html
h1 = Elem "h1" <<< buildChildren
h2 :: forall a. BuildChildren a => a -> Html
h2 = Elem "h2" <<< buildChildren
p :: forall a. BuildChildren a => a -> Html
p = Elem "p" <<< buildChildren
text :: String -> Html
text = Text
test :: String -> Html
test user = section do
h1 do
text $ "Posts for " <> user
article do
h2 do
text "The first post"
p do
text "This is the first post."
text "Not much else to say."