~alcinnz/haskell-stylist

b15571fe8903b17ecbcc098f4f3ac3e357346a27 — Adrian Cochrane 5 years ago 7061161
Add method to override CSS inheritance.
2 files changed, 6 insertions(+), 2 deletions(-)

M src/Data/CSS/Style.hs
M stylish-haskell.cabal
M src/Data/CSS/Style.hs => src/Data/CSS/Style.hs +5 -1
@@ 53,6 53,9 @@ cascadeProperties overrides props = fromList (props ++ overrides)

class PropertyParser a where
    temp :: a
    inherit :: a -> a
    inherit = id

    shorthand :: a -> Text -> [Token] -> [(Text, [Token])]
    shorthand self name value | Just _ <- longhand self self name value = [(name, value)]
        | otherwise = []


@@ 60,7 63,8 @@ class PropertyParser a where
    longhand :: a -> a -> Text -> [Token] -> Maybe a

cascade :: PropertyParser p => QueryableStyleSheet p -> Element -> [(Text, [Token])] -> p -> p
cascade self el overrides parent = dispatch parent parent $ toList $ cascadeRules overrides $ queryRules self el
cascade self el overrides parent = dispatch parent (inherit parent) $
    toList $ cascadeRules overrides $ queryRules self el

dispatch parent child ((name, value):props)
    | Just child' <- longhand parent child name value = dispatch parent child' props

M stylish-haskell.cabal => stylish-haskell.cabal +1 -1
@@ 10,7 10,7 @@ name:                stylish-haskell
-- PVP summary:      +-+------- breaking API changes
--                   | | +----- non-breaking API additions
--                   | | | +--- code changes with no API change
version:             0.3.0
version:             0.4.0

-- A short (one-line) description of the package.
synopsis:            Apply CSS styles to a document tree.