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,
module Data.Niagra.Selector.Combinators
)
where
import Data.Niagra.At
import Data.Niagra.Monad
import Data.Niagra.Block
import Data.Niagra.Selector
import Data.Niagra.Selector.Tags
import Data.Niagra.Selector.Combinators
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 s act = niagraState act >>= writeBlocks . uncurry f
where f decls blocks = (DeclarationBlock s decls):(map prependSel blocks)
where prependSel (DeclarationBlock s2 d2) = DeclarationBlock (s <||> s2) d2
prependSel (BuilderBlock s2 b2) = BuilderBlock (s <||> s2) b2
infix 0 ?
(?) :: (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 0 .=
(.=) :: (Monad m) => Text -> Text -> NiagraT (NiagraT m) ()
(.=) = declaration