Skip to content
Browse files

keyframes (#63)

  • Loading branch information...
1 parent be6ed30 commit 3c34753110d7f8e8b8e9b5b650755c60da092b8d @snoyberg snoyberg committed Jun 7, 2012
Showing with 36 additions and 2 deletions.
  1. +14 −2 shakespeare-css/Text/Lucius.hs
  2. +22 −0 shakespeare-css/test/ShakespeareCssTest.hs
View
16 shakespeare-css/Text/Lucius.hs
@@ -28,9 +28,10 @@ import Text.Css
import Data.Char (isSpace, toLower, toUpper)
import Numeric (readHex)
import Control.Applicative ((<$>))
-import Control.Monad (when)
+import Control.Monad (when, unless)
import Data.Either (partitionEithers)
import Data.Monoid (mconcat)
+import Data.List (isSuffixOf)
-- |
--
@@ -172,7 +173,7 @@ parseTopLevels =
ignore = many (whiteSpace1 <|> string' "<!--" <|> string' "-->")
>> return ()
ignore
- tl <- ((charset <|> media <|> impor <|> var <|> fmap TopBlock parseBlock) >>= \x -> go (front . (:) x))
+ tl <- ((charset <|> media <|> impor <|> topAtBlock <|> var <|> fmap TopBlock parseBlock) >>= \x -> go (front . (:) x))
<|> (return $ map compressTopLevel $ front [])
ignore
return tl
@@ -204,6 +205,17 @@ parseTopLevels =
_ <- char ';'
let trimS = reverse . dropWhile isSpace . reverse . dropWhile isSpace
return $ TopVar (trimS k) (trimS v)
+ topAtBlock = do
+ (name, selector) <- try $ do
+ _ <- char '@'
+ name <- many1 $ noneOf " \t"
+ _ <- many1 $ oneOf " \t"
+ unless ("keyframes" `isSuffixOf` name) $ fail "only accepting keyframes"
+ selector <- parseContents "{"
+ _ <- char '{'
+ return (name, selector)
+ b <- parseBlocks id
+ return $ TopAtBlock name selector b
parseBlocks front = do
whiteSpace
(char '}' >> return (map compressBlock $ front []))
View
22 shakespeare-css/test/ShakespeareCssTest.hs
@@ -348,6 +348,28 @@ foo { foo:X#{bar}Y; }
"@charset mycharset;" [lucius|
@charset #{charset};
|]
+ , it "keyframes" $ celper
+ "@keyframes mymove {from{top:0px}to{top:200px}}" [lucius|
+@keyframes mymove {
+ from {
+ top: 0px;
+ }
+ to {
+ top: 200px;
+ }
+}
+|]
+ , it "prefixed keyframes" $ celper
+ "@-webkit-keyframes mymove {from{top:0px}to{top:200px}}" [lucius|
+@-webkit-keyframes mymove {
+ from {
+ top: 0px;
+ }
+ to {
+ top: 200px;
+ }
+}
+|]
]
data Url = Home | Sub SubUrl

0 comments on commit 3c34753

Please sign in to comment.
Something went wrong with that request. Please try again.