packages feed

hsp-0.2: HSP/Data/CSS.hs

{-# OPTIONS -fallow-overlapping-instances -fallow-undecidable-instances 
  -fglasgow-exts #-}
-----------------------------------------------------------------------
-- |  
-- Module      :  HSP.Data.CSS
-- Copyright   :  
-- License     :  BSD-style (see the file LICENSE.txt)
-- 
-- Maintainer  :  
-- Stability   :  experimental
-- Portability :  
-----------------------------------------------------------------------
module HSP.Data.CSS (
        -- * The CSS datatype
        CSS(..),
        CSSEntry(..),
        CSSType(..),
        -- * The Style datatype
        Style(..),
        StyleValue(..),
        ) where


-----------------------------------------------------------------------
-- Data types

newtype Style = Style [(String, StyleValue)]
newtype StyleValue = StyleValue String

data CSSEntry = CSSEntry [CSSType] Style

data CSSType = CSSId String
             | CSSClass String
             | CSSElem String
             | CSSPseudoClass CSSType String

newtype CSS = CSS [CSSEntry]


-----------------------------------------------------------------------
-- Rendering

instance Show Style where
    show (Style stl) = 
        concatMap (\(name, (StyleValue sv)) -> name ++ ": " ++  sv ++ ";") stl

instance Show StyleValue where
    show (StyleValue str) = str

instance Show CSSType where
    show typ = case typ of
        (CSSId str) -> "#" ++ str ++ " "
        (CSSClass str) -> "." ++ str ++ " "
        (CSSElem str) -> str ++ " "
        (CSSPseudoClass typ str) -> show typ ++ ":" ++ str ++ " "

instance Show CSSEntry where
    show (CSSEntry typ sty) = concatMap show typ ++ "\t{ " ++ show sty ++ " }"