M src/Data/CSS/Style.hs => src/Data/CSS/Style.hs +4 -1
@@ 12,6 12,7 @@ module Data.CSS.Style(
import Data.CSS.Style.Selector.Index
import Data.CSS.Style.Selector.Interpret
import Data.CSS.Style.Selector.Specificity
+import Data.CSS.Style.Selector.LowerWhere
import Data.CSS.Style.Importance
import Data.CSS.Style.Common
import qualified Data.CSS.Style.Cascade as Cascade
@@ 25,7 26,9 @@ import Data.List (elemIndex)
-- | A parsed CSS stylesheet from which you can query styles to match an element.
type QueryableStyleSheet parser = QueryableStyleSheet' (ImportanceSplitter (
- PropertyExpander parser (OrderedRuleStore (InterpretedRuleStore StyleIndex))
+ PropertyExpander parser (
+ OrderedRuleStore (WhereLowerer (InterpretedRuleStore StyleIndex))
+ )
)) parser
-- | More generic version of `QueryableStyleSheet`.
A src/Data/CSS/Style/Selector/LowerWhere.hs => src/Data/CSS/Style/Selector/LowerWhere.hs +32 -0
@@ 0,0 1,32 @@
+{-# LANGUAGE OverloadedStrings #-}
+module Data.CSS.Style.Selector.LowerWhere(
+ WhereLowerer(..)
+ ) where
+
+import Data.CSS.Syntax.Selector
+import Data.CSS.Style.Common
+
+lowerSelector :: Selector -> Selector
+lowerSelector (Element sel) = Element $ lowerSelector' sel
+lowerSelector (Child sel x) = Child (lowerSelector sel) x
+lowerSelector (Descendant sel x) = Descendant (lowerSelector sel) x
+lowerSelector (Adjacent sel x) = Adjacent (lowerSelector sel) x
+lowerSelector (Sibling sel x) = Sibling (lowerSelector sel) x
+
+lowerSelector' :: [SimpleSelector] -> [SimpleSelector]
+lowerSelector' (Psuedoclass c args:sel)
+ | c `elem` ["is", "where"], ([Element arg'], []) <- parseSelectors args =
+ arg' ++ lowerSelector' sel
+lowerSelector' (test:tests) = test : lowerSelector' tests
+lowerSelector' [] = []
+
+data WhereLowerer s = WhereLowerer s
+
+instance RuleStore s => RuleStore (WhereLowerer s) where
+ new = WhereLowerer new
+ addStyleRule (WhereLowerer self) priority rule =
+ WhereLowerer $ addStyleRule self priority $ rule {
+ inner = StyleRule (lowerSelector sel) props psuedo
+ }
+ where StyleRule sel props psuedo = inner rule
+ lookupRules (WhereLowerer self) el = lookupRules self el
M stylist.cabal => stylist.cabal +2 -1
@@ 61,7 61,8 @@ library
-- Modules included in this library but not exported.
other-modules: Data.CSS.Syntax.StylishUtil,
Data.CSS.Style.Importance, Data.CSS.Style.Common, Data.CSS.Style.Cascade,
- Data.CSS.Style.Selector.Index, Data.CSS.Style.Selector.Interpret, Data.CSS.Style.Selector.Specificity
+ Data.CSS.Style.Selector.Index, Data.CSS.Style.Selector.Interpret,
+ Data.CSS.Style.Selector.Specificity, Data.CSS.Style.Selector.LowerWhere
-- LANGUAGE extensions used by modules in this package.
-- other-extensions: