git.iko.soy/rowtype-yoga/purescript-backend-optimizer
on main help sign in
60 lines 1.5 kB history raw
1module Snapshot.Html (Html, test) where
3import Prelude hiding (discard)
5import Data.Array as Array
7class BuildArray a b c | a b -> c where
8 buildArray :: a -> b -> Array c
10instance BuildArray (Array a) (Array a) a where
11 buildArray = append
12else instance BuildArray a (Array a) a where
13 buildArray = Array.cons
14else instance BuildArray (Array a) a a where
15 buildArray = Array.snoc
16else instance BuildArray a a a where
17 buildArray a b = [ a, b ]
19discard :: forall a b c. BuildArray a b c => a -> (Unit -> b) -> Array c
20discard a k = buildArray a (k unit)
22data Html = Elem String (Array Html) | Text String
24class BuildChildren a where
25 buildChildren :: a -> Array Html
27instance BuildChildren Html where
28 buildChildren = pure
30instance BuildChildren (Array Html) where
31 buildChildren = identity
33section :: forall a. BuildChildren a => a -> Html
34section = Elem "section" <<< buildChildren
36article :: forall a. BuildChildren a => a -> Html
37article = Elem "article" <<< buildChildren
39h1 :: forall a. BuildChildren a => a -> Html
40h1 = Elem "h1" <<< buildChildren
42h2 :: forall a. BuildChildren a => a -> Html
43h2 = Elem "h2" <<< buildChildren
45p :: forall a. BuildChildren a => a -> Html
46p = Elem "p" <<< buildChildren
48text :: String -> Html
49text = Text
51test :: String -> Html
52test user = section do
53 h1 do
54 text $ "Posts for " <> user
55 article do
56 h2 do
57 text "The first post"
58 p do
59 text "This is the first post."
60 text "Not much else to say."