module Data.Niagra
(
css,
css',
cssBuilder,
cssBuilder',
block,
(?),
declaration,
(.=),
module Data.Niagra.At,
module Data.Niagra.Monad,
module Data.Niagra.Block,
module Data.Niagra.Selector,
module Data.Niagra.Selector.Tags
)
where
import Data.Niagra.At
import Data.Niagra.Monad
import Data.Niagra.Block
import Data.Niagra.Selector
import Data.Niagra.Selector.Tags
import Data.Either
import Control.Monad.Identity
import Data.Text.Lazy.Builder (Builder,toLazyText)
import Data.Text.Lazy (Text)
css :: (Monad m) => NiagraT m ()
-> m Text
css = fmap toLazyText . cssBuilder
css' :: NiagraT Identity () -> Text
css' = runIdentity . css
cssBuilder :: (Monad m) => NiagraT m ()
-> m Builder
cssBuilder = fmap (mconcat . map buildBlock) . niagraBlocks
cssBuilder' :: NiagraT Identity () -> Builder
cssBuilder' = runIdentity . cssBuilder
block :: (Monad m) => Selector
-> NiagraT (NiagraT m) ()
-> NiagraT m ()
block b act = niagraState act >>= writeBlocks . uncurry f
where f l = (:) (DeclarationBlock b l) . map appendSel
where appendSel (DeclarationBlock b2 d2) = DeclarationBlock (b <||> b2) d2
infix 2 ?
(?) :: (Monad m) => Selector -> NiagraT (NiagraT m) () -> NiagraT m ()
(?) = block
declaration :: (Monad m) => Text
-> Text
-> NiagraT (NiagraT m) ()
declaration p v = writeDeclarations [Declaration p v]
infix 2 .=
(.=) :: (Monad m) => Text -> Text -> NiagraT (NiagraT m) ()
(.=) = declaration