Skip to content

Commit

Permalink
Fix rendering of the Number type (#256)
Browse files Browse the repository at this point in the history
Do not use the the Show instance of Clay.Property.Number for
rendering, use cssNumberText instead. Adds a test case to
spec/Clay/MediaSpec.hs that demonstrates the resulting output of the
keyframes function.

---------

Co-authored-by: Manuel Bärenz <[email protected]>
  • Loading branch information
ddssff and turion authored Nov 15, 2023
1 parent f87f864 commit 6994e9f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
13 changes: 11 additions & 2 deletions spec/Clay/MediaSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

module Clay.MediaSpec (spec) where

import Clay (Css, em, query)
import Clay (compact, Css, em, opacity, query, renderWith)
import Clay.Media
import Clay.Stylesheet (Feature, MediaType)
import Clay.Stylesheet (Feature, keyframes, MediaType)
import Common
import Data.Text.Lazy (Text, unpack)
import Test.Hspec
Expand Down Expand Up @@ -73,6 +73,15 @@ spec = do
"prefers-color-scheme: light" `shouldRenderFromFeature` prefersColorScheme light
"prefers-color-scheme: dark" `shouldRenderFromFeature` prefersColorScheme dark

describe "keyframes tests" $ do
it "keyframes test 1" $
(renderWith compact [] $ keyframes "blink-animation" [(0, opacity 0), (100, opacity 1)])
`shouldBe` ("@-webkit-keyframes blink-animation{0% {opacity:0}100% {opacity:1}}" <>
"@-moz-keyframes blink-animation{0% {opacity:0}100% {opacity:1}}" <>
"@-ms-keyframes blink-animation{0% {opacity:0}100% {opacity:1}}" <>
"@-o-keyframes blink-animation{0% {opacity:0}100% {opacity:1}}" <>
"@keyframes blink-animation{0% {opacity:0}100% {opacity:1}}")

-- | Empty CSS for when CSS is needed but we don't care about it.
emptyStyle :: Css
emptyStyle = pure ()
Expand Down
4 changes: 2 additions & 2 deletions src/Clay/Render.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Control.Applicative
import Control.Monad.Writer
import Data.List (sort)
import Data.Maybe
import Data.Text (Text, pack)
import Data.Text (Text)
import Data.Text.Lazy.Builder
import Prelude hiding ((**))

Expand Down Expand Up @@ -150,7 +150,7 @@ kframe cfg (Keyframes ident xs) =
frame :: Config -> (Number, [Rule]) -> Builder
frame cfg (p, rs) =
mconcat
[ fromText (pack (show p))
[ fromText (cssNumberText p)
, "% "
, rules cfg [] rs
]
Expand Down

0 comments on commit 6994e9f

Please sign in to comment.