From 10a6e6345c3ef52a03531ee7ab5f18d56bbe54f7 Mon Sep 17 00:00:00 2001 From: Adrian Cochrane Date: Mon, 9 Sep 2019 16:00:41 +1200 Subject: [PATCH] Fix syntax errors in ConditionalStyles --- src/Data/CSS/Preprocessor/Conditions.hs | 8 ++++++-- test/Test.hs | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Data/CSS/Preprocessor/Conditions.hs b/src/Data/CSS/Preprocessor/Conditions.hs index e1f0a43..8c9fd2b 100644 --- a/src/Data/CSS/Preprocessor/Conditions.hs +++ b/src/Data/CSS/Preprocessor/Conditions.hs @@ -9,20 +9,24 @@ import Data.CSS.Syntax.Tokens(Token(..)) import Data.Text (unpack) import Network.URI (URI(..), URIAuth(..)) +import Data.List + data ConditionalStyles s = ConditionalStyles { hostURL :: URI, mediaDocument :: String, inner :: s } +hostUrlS :: ConditionalStyles s -> String hostUrlS = show . hostURL +parseAtBlock :: StyleSheet t => t -> [Token] -> (t, [Token]) 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 +instance StyleSheet s => StyleSheet (ConditionalStyles s) where setPriority x self = self {inner = setPriority x $ inner self} addRule self rule = self {inner = addRule (inner self) rule} @@ -40,7 +44,7 @@ instance StyleSheet ConditionalStyles where where domain | Just auth <- uriAuthority $ hostURL self = uriRegName auth | otherwise = "" - addAtRule self "document" (Function "media-document":String match:RightParen:toks) = + addAtRule self "document" (Function "media-document":String match:RightParen:toks) | unpack match == mediaDocument self = parseAtBlock self toks | otherwise = addAtRule self "document" toks -- TODO Support regexp() conditions, requires new dependency diff --git a/test/Test.hs b/test/Test.hs index 5e405bb..8d7cc1b 100644 --- a/test/Test.hs +++ b/test/Test.hs @@ -13,6 +13,8 @@ import Data.CSS.Style.Selector.Index import Data.CSS.Style.Selector.Interpret import Data.CSS.Style +import Data.CSS.Preprocessor.Conditions + main :: IO () main = hspec spec -- 2.30.2