-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathKotlinxHtml.hs
45 lines (41 loc) · 1.17 KB
/
KotlinxHtml.hs
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
module Hemmet.Dom.Rendering.KotlinxHtml where
import Control.Monad
import Data.Foldable
import qualified Data.List as L
import Hemmet.Rendering
import Hemmet.Tree
import Hemmet.Dom.Rendering.Common
import Hemmet.Dom.Tree
renderKotlinxHtmlM :: Renderer DomPayload
renderKotlinxHtmlM = run render
where
render (Node name (DomTag mbId classes childs)) = do
let tagName = if name == "" then "div" else name
pad
out $ tagName <> " {"
case (mbId, classes, childs) of
(Nothing, [], []) -> pure ()
_ -> do
nl
withOffset 4 $ do
case mbId of
Just x -> do
pad
out $"id = \"" <> x <> "\""
nl
_ -> pure ()
unless (L.null classes) $ do
pad
out $ "classes = setOf("
<> mconcat (L.intersperse ", " $ L.map quoted classes)
<> ")"
nl
unless (L.null childs) $ do
traverse_ render childs
pad
out "}"
nl
render (Node _ (DomPlainText text)) = do
pad
out $ "+\"" <> text <> "\""
nl