module Data.AdobeSwatchExchange.LESS where
import Control.Monad.State (State, evalState, get, put)
import Data.AdobeSwatchExchange as ASE (ASEBlock(CE, GroupStart, GroupEnd), ColorEntry(color), AdobeSwatchExchange, Color(RGB), blocks, colorToHex, getASE)
import qualified Data.ByteString.Lazy as B
import Numeric (showHex)
import Text.PrettyPrint.HughesPJ (Doc, (<>), (<+>), ($+$), braces, colon, empty, int, semi, text, vcat)
ase2less :: AdobeSwatchExchange -> Doc
ase2less ase =
vcat $ evalState (mapM genColor (blocks ase)) 1
genColor :: ASEBlock -> State Int Doc
genColor (CE colorEntry) =
do n <- get
put $! (n + 1)
let colorAse = text "@color-ase-" <> int n
return $ colorAse <> colon <+> (text $ colorToHex (color colorEntry)) <> semi $+$
text ".fg-color-ase-" <> int n <+> braces (text "color:" <+> colorAse <> semi) $+$
text ".bg-color-ase-" <> int n <+> braces (text "background-color:" <+> colorAse <> semi) $+$
text ".border-color-ase-" <> int n <+> braces (text "border-color:" <+> colorAse <> semi) $+$
text ""
genColor (GroupStart name) =
return $ text "/* Group" <+> text name <+> text "*/"
genColor _ = return empty