~alcinnz/haskell-stylist

b6808a67bb5a6dfcbecc131d31f390b4f74ef102 — Adrian Cochrane 5 years ago 2128054
Code cleanliness: Interpret Data.CSS.Style.Importance.splitProperties return value correctly.
1 files changed, 7 insertions(+), 4 deletions(-)

M src/Data/CSS/Style/Importance.hs
M src/Data/CSS/Style/Importance.hs => src/Data/CSS/Style/Importance.hs +7 -4
@@ 1,6 1,6 @@
{-# LANGUAGE OverloadedStrings #-}
module Data.CSS.Style.Importance (
        splitProperties, ImportanceSplitter(..)
        ImportanceSplitter(..)
    ) where

import Data.CSS.Syntax.Tokens


@@ 15,15 15,18 @@ splitProperties (prop@(name, value):rest)
    where (unimportant, important) = splitProperties rest
splitProperties [] = ([], [])

--- NOTE: Prorities are defined with lower numbers being more important,
---     so negate to be consistant with other priority sources.
--- This API decision started out being accidental, but I find it more intuitive.
data ImportanceSplitter a = ImportanceSplitter a
instance RuleStore inner => RuleStore (ImportanceSplitter inner) where
    new = ImportanceSplitter new
    addStyleRule (ImportanceSplitter self) priority rule =
            ImportanceSplitter $ addStyleRule (
                addStyleRule self (negate priority) $ buildRule important
            ) priority $ buildRule unimportant
                addStyleRule self (negate priority) $ buildRule unimportant
            ) priority $ buildRule important
        where
            (important, unimportant) = splitProperties properties
            (unimportant, important) = splitProperties properties
            (StyleRule selector properties) = inner rule
            buildRule properties = rule {inner = StyleRule selector properties}
    lookupRules (ImportanceSplitter self) el = lookupRules self el