module Data.Niagra.Block
(
Block(..),
Declaration(..),
buildBlock,
)
where
import Data.Niagra.Selector
import Data.Monoid
import Data.Text.Lazy (Text)
import Data.Text.Lazy.Builder
data Declaration = Declaration Text Text
data Block = DeclarationBlock Selector [Declaration]
| BuilderBlock Selector Builder
buildBlock :: Block
-> Builder
buildBlock (BuilderBlock sel b) = mconcat [buildSelector sel, "{", b, "}"]
buildBlock (DeclarationBlock sel d) = buildBlock $ BuilderBlock sel $ buildDecls mempty d
where
pair p v = fromLazyText p <> ":" <> fromLazyText v
buildDecls accum [] = accum
buildDecls accum [Declaration p v] = accum <> pair p v
buildDecls accum (x:xs) = buildDecls (buildDecls accum [x] <> ";") xs