~alcinnz/haskell-stylist

4435ce007d34a8f0488a6a7634c91f0e84fe236a — Adrian Cochrane 5 years ago 8f54582
Switch @document from conjunctive conditions to disjunctive conditions.
1 files changed, 8 insertions(+), 6 deletions(-)

M src/Data/CSS/Preprocessor/Conditions.hs
M src/Data/CSS/Preprocessor/Conditions.hs => src/Data/CSS/Preprocessor/Conditions.hs +8 -6
@@ 17,7 17,10 @@ data ConditionalStyles s = ConditionalStyles {

hostUrlS = show . hostURL

parseAtBlock self toks = let (block, toks') = scanBlock toks in (parse' self block, toks')
parseAtBlock self (LeftCurlyBracket:toks) =
    let (block, toks') = scanBlock toks in (parse' self block, toks')
parseAtBlock self (_:toks) = parseAtBlock self toks
parseAtBlock self [] = (self, [])

instance StyleSheet ConditionalStyles where
    setPriority x self = self {inner = setPriority x $ inner self}


@@ 25,19 28,18 @@ instance StyleSheet ConditionalStyles where

    addAtRule self "document" (Comma:toks) = addAtRule self "document" toks
    addAtRule self "document" (Url match:toks) | unpack match == hostUrlS self =
        addAtRule self "document" toks
        parseAtBlock self toks
    addAtRule self "document" (Function "url-prefix":String match:RightParen:toks) =
        | unpack match `isPrefixOf` hostUrlS self = addAtRule self "document" toks
        | unpack match `isPrefixOf` hostUrlS self = parseAtBlock self toks
    addAtRule self "document" (Function "domain":String match:RightParen:toks)
        | unpack match == domain || ('.':unpack match) `isSuffixOf` domain =
            addAtRule self "document" toks
            parseAtBlock self toks
        where
            domain | Just auth <- uriAuthority $ hostURL self = uriRegName auth
                | otherwise = ""
    addAtRule self "document" (Function "media-document":String match:RightParen:toks) =
        | unpack match == mediaDocument self = addAtRule self "document" toks
        | unpack match == mediaDocument self = parseAtBlock self toks
    -- TODO Support regexp() conditions, requires new dependency
    addAtRule self "document" (LeftCurlyBracket:toks) = parseAtBlock self toks
    addAtRule self "document" tokens = (self, skipAtRule tokens)

    addAtRule self rule tokens =