module Data.Niagra.DSL
(
css,
css',
cssBuilder,
cssBuilder',
block,
declaration,
(?),
(.=),
)
where
import Data.Niagra.Monad
import Data.Niagra.Selector
import Data.Niagra.Block
import Data.Niagra.Builder
import Control.Monad.Identity
import Data.Text (Text)
import Data.Monoid
import Data.Foldable
css :: (Monad m) => NiagraT m ()
-> m Text
css = fmap toText . cssBuilder
css' :: NiagraT Identity () -> Text
css' = runIdentity . css
cssBuilder :: (Monad m) => NiagraT m ()
-> m Builder
cssBuilder = fmap reduce . execNiagraT Null
where reduce = foldl' (\a b -> a <> (buildBlock b)) mempty
cssBuilder' :: NiagraT Identity () -> Builder
cssBuilder' = runIdentity . cssBuilder
block :: (Monad m) => Selector
-> NiagraT m ()
-> NiagraT m ()
block sel declarator = do
withNewScope sel $ do
declarator
getCurrentBlock >>= addBlock
declaration :: (Monad m) => Text
-> Builder
-> NiagraT m ()
declaration p v = addDeclaration $ Declaration p v
infix 0 ?
(?) :: (Monad m) => Selector -> NiagraT m () -> NiagraT m ()
(?) = block
infix 1 .=
(.=) :: (Monad m) => Text -> Builder -> NiagraT m ()
(.=) = declaration