/
Dsl.purs
42 lines (28 loc) · 1.16 KB
/
Dsl.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
module Materialize.Markup.Dsl
( ClassDsl
, liftClassDsl
, classList
, renderClasses
) where
import Control.Monad.Writer (Writer, execWriter, tell)
import Data.List (List)
import Data.Newtype (class Newtype, unwrap, wrap)
import Prelude
import Text.Smolder.HTML.Attributes (className) as A
import Text.Smolder.Markup (Attribute)
import Materialize.Markup.Render (class Render, render, renderString)
newtype ClassDsl a = ClassDsl (Writer (List String) a)
derive instance newtypeClassDsl :: Newtype (ClassDsl a) _
derive newtype instance functorClassDsl :: Functor ClassDsl
derive newtype instance applyClassDsl :: Apply ClassDsl
derive newtype instance applicativeClassDsl :: Applicative ClassDsl
derive newtype instance bindClassDsl :: Bind ClassDsl
derive newtype instance monadClassDsl :: Monad ClassDsl
liftClassDsl :: forall c. Render c => c -> ClassDsl Unit
liftClassDsl = wrap <<< tell <<< render
instance renderClassDsl :: Render (ClassDsl a) where
render = execWriter <<< unwrap
classList :: forall a. ClassDsl a -> Attribute
classList = A.className <<< renderString
renderClasses :: forall a. ClassDsl a -> String
renderClasses = renderString