Skip to content

Commit

Permalink
Merge ../clay
Browse files Browse the repository at this point in the history
  • Loading branch information
ddssff committed Jul 7, 2023
2 parents 42ad693 + d6dfa00 commit be7a661
Show file tree
Hide file tree
Showing 28 changed files with 470 additions and 86 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
on: [pull_request]
name: build
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
ghc: ['8.4.4', '8.6.5', '8.8.4', '8.10.7', '9.0.2', '9.2.2', '9.4.2']
name: Haskell GHC ${{ matrix.ghc }} cabal
env:
cabal_project_freeze: cabal.project.${{ matrix.ghc }}.freeze
steps:
- uses: actions/checkout@v2
- uses: haskell/actions/setup@v2
id: setup-haskell-build
with:
ghc-version: ${{ matrix.ghc }}
- name: Cache Cabal build artifacts
uses: actions/cache@v2
with:
path: |
${{ steps.setup-haskell-build.outputs.cabal-store }}
dist-newstyle
key: ${{ runner.os }}-cabal-${{ matrix.ghc }}-${{ hashFiles(env.cabal_project_freeze) }}
restore-keys: |
${{ runner.os }}-cabal-${{ matrix.ghc }}
- name: Cabal build dependencies
run: |
cabal build all --enable-tests --only-dependencies --project-file=cabal.project.${{ matrix.ghc }}
- name: Cabal build packages
run: |
cabal build all --enable-tests --project-file=cabal.project.${{ matrix.ghc }}
- name: Cabal test
run: |
cabal test all --enable-tests --test-show-details=Always --project-file=cabal.project.${{ matrix.ghc }}
8 changes: 7 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
CHANGELOG

Unreleased:
- Add `all` media type.
- Support `prefers-color-scheme` media feature.

0.14.0:
- Drop support for GHC 8.2
- Added `text-align-last`
- Fix typo in `stepsStart`
Thanks to Vasiliy Yorkin and Florian Grignon.
- Added clay-examples
- Fix `cubicBezier` and other issues
Thanks to Vasiliy Yorkin, Florian Grignon, Nick Saunders, David Fox, Ben Sima, Murakami Kennzo, Owen Shepherd, Anton Gushcha, Temur Saidkhodjaev, Rob Bassi, Alex Sayers, and further contributors.

0.13.3:
- Improve README
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Clay

[![Build Status](https://travis-ci.org/sebastiaanvisser/clay.png)](https://travis-ci.org/sebastiaanvisser/clay)
[![build](https://github.com/sebastiaanvisser/clay/actions/workflows/ci.yml/badge.svg)](https://github.com/sebastiaanvisser/clay/actions/workflows/ci.yml)
[![Hackage](https://img.shields.io/hackage/v/clay.svg)](https://hackage.haskell.org/package/clay)

Clay is a CSS preprocessor like LESS and Sass, but implemented as an embedded
Expand Down
2 changes: 2 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages: clay.cabal
tests: true
1 change: 1 addition & 0 deletions cabal.project.8.10.7
1 change: 1 addition & 0 deletions cabal.project.8.4.4
1 change: 1 addition & 0 deletions cabal.project.8.6.5
1 change: 1 addition & 0 deletions cabal.project.8.8.4
1 change: 1 addition & 0 deletions cabal.project.9.0.2
1 change: 1 addition & 0 deletions cabal.project.9.2.2
1 change: 1 addition & 0 deletions cabal.project.9.4.2
30 changes: 18 additions & 12 deletions clay.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Name: clay
Version: 0.14.0
Version: 0.15.0
Synopsis: CSS preprocessor as embedded Haskell.
Description:
Clay is a CSS preprocessor like LESS and Sass, but implemented as an embedded
Expand All @@ -20,7 +20,7 @@ Bug-Reports: http://github.com/sebastiaanvisser/clay/issues
License: BSD3
License-File: LICENSE
Category: Web, Graphics
Cabal-Version: >= 1.8
Cabal-Version: >= 1.10
Build-Type: Simple

Extra-Source-Files:
Expand All @@ -29,7 +29,11 @@ Extra-Source-Files:
Tested-With:
GHC==8.4.4,
GHC==8.6.5,
GHC==8.8.1
GHC==8.8.4,
GHC==8.10.7,
GHC==9.0.2,
GHC==9.2.2,
GHC==9.4.2

Source-Repository head
Type: git
Expand Down Expand Up @@ -57,7 +61,7 @@ Library
Clay.FontFace
Clay.Geometry
Clay.Gradient
Clay.Grid
Clay.Grid
Clay.List
Clay.Media
Clay.Mask
Expand All @@ -73,20 +77,22 @@ Library
Clay.Transition

Build-Depends:
base >= 4.11 && < 5,
mtl >= 1 && < 2.3,
text >= 0.11 && < 1.3
base >= 4.11 && < 4.18,
mtl >= 1,
text >= 0.11
GHC-Options: -Wall -Wcompat
Default-Language: Haskell2010

Test-Suite Test-Clay
Type: exitcode-stdio-1.0
HS-Source-Dirs: spec, src
Build-Tools: hspec-discover
main-is: Spec.hs
Build-Depends:
base >= 4.11 && < 5,
mtl >= 1 && < 2.3,
text >= 0.11 && < 1.3,
hspec >= 2.2.0 && < 2.8,
hspec-discover >= 2.2.0 && < 2.8
base >= 4.11 && < 4.18,
mtl >= 1,
text >= 0.11,
hspec >= 2.2.0,
hspec-discover >= 2.2.0
GHC-Options: -Wall -Wcompat
Default-Language: Haskell2010
4 changes: 2 additions & 2 deletions examples/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ main :: IO ()
main = putCss logo

where
s = 80 :: Double
m = 30 :: Double
s = 80 :: Number
m = 30 :: Number
cs = [ "#78e700"
, "#00b454"
, "#ff3900"
Expand Down
98 changes: 98 additions & 0 deletions spec/Clay/MediaSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{-# LANGUAGE OverloadedStrings #-}

module Clay.MediaSpec (spec) where

import Clay (Css, em, query)
import Clay.Media
import Clay.Stylesheet (Feature, MediaType)
import Common
import Data.Text.Lazy (Text, unpack)
import Test.Hspec
import Prelude hiding (all, print)

spec :: Spec
spec = do
describe "media types" $ do
"all" `shouldRenderFromMediaType` all
"screen" `shouldRenderFromMediaType` screen
"print" `shouldRenderFromMediaType` print

context "with deprecated types" $ do
"aural" `shouldRenderFromMediaType` aural
"braille" `shouldRenderFromMediaType` braille
"handheld" `shouldRenderFromMediaType` handheld
"projection" `shouldRenderFromMediaType` projection
"tty" `shouldRenderFromMediaType` tty
"tv" `shouldRenderFromMediaType` tv
"embossed" `shouldRenderFromMediaType` embossed

describe "geometrical features" $ do
"width: 11em" `shouldRenderFromFeature` width (em 11)
"min-width: 12em" `shouldRenderFromFeature` minWidth (em 12)
"max-width: 13em" `shouldRenderFromFeature` maxWidth (em 13)
"height: 14em" `shouldRenderFromFeature` height (em 14)
"min-height: 15em" `shouldRenderFromFeature` minHeight (em 15)
"max-height: 16em" `shouldRenderFromFeature` maxHeight (em 16)
"device-width: 17em" `shouldRenderFromFeature` deviceWidth (em 17)
"min-device-width: 18em" `shouldRenderFromFeature` minDeviceWidth (em 18)
"max-device-width: 19em" `shouldRenderFromFeature` maxDeviceWidth (em 19)
"device-height: 20em" `shouldRenderFromFeature` deviceHeight (em 20)
"min-device-height: 21em" `shouldRenderFromFeature` minDeviceHeight (em 21)
"max-device-height: 22em" `shouldRenderFromFeature` maxDeviceHeight (em 22)

describe "aspect ratio features" $ do
"aspect-ratio: 2/3" `shouldRenderFromFeature` aspectRatio (2, 3)
"min-aspect-ratio: 4/5" `shouldRenderFromFeature` minAspectRatio (4, 5)
"max-aspect-ratio: 6/7" `shouldRenderFromFeature` maxAspectRatio (6, 7)
"device-aspect-ratio: 2/3" `shouldRenderFromFeature` deviceAspectRatio (2, 3)
"min-device-aspect-ratio: 4/5" `shouldRenderFromFeature` minDeviceAspectRatio (4, 5)
"max-device-aspect-ratio: 6/7" `shouldRenderFromFeature` maxDeviceAspectRatio (6, 7)

describe "color features" $ do
"color" `shouldRenderFromFeature` color
"monochrome" `shouldRenderFromFeature` monochrome
"scan" `shouldRenderFromFeature` scan
"grid" `shouldRenderFromFeature` grid
"min-color: 23" `shouldRenderFromFeature` minColor 23
"max-color: 25" `shouldRenderFromFeature` maxColor 25
"color-index: 15" `shouldRenderFromFeature` colorIndex 15
"min-color-index: 17" `shouldRenderFromFeature` minColorIndex 17
"max-color-index: 19" `shouldRenderFromFeature` maxColorIndex 19
"min-monochrome: 77" `shouldRenderFromFeature` minMonochrome 77
"max-monochrome: 99" `shouldRenderFromFeature` maxMonochrome 99

describe "resolution features" $ do
"resolution: 45dpi" `shouldRenderFromFeature` resolution (dpi 45)
"resolution: 74dppx" `shouldRenderFromFeature` resolution (dppx 74)
"min-resolution: 45dpi" `shouldRenderFromFeature` minResolution (dpi 45)
"min-resolution: 74dppx" `shouldRenderFromFeature` minResolution (dppx 74)
"max-resolution: 45dpi" `shouldRenderFromFeature` maxResolution (dpi 45)
"max-resolution: 74dppx" `shouldRenderFromFeature` maxResolution (dppx 74)

describe "preference features" $ do
"prefers-color-scheme: light" `shouldRenderFromFeature` prefersColorScheme light
"prefers-color-scheme: dark" `shouldRenderFromFeature` prefersColorScheme dark

-- | Empty CSS for when CSS is needed but we don't care about it.
emptyStyle :: Css
emptyStyle = pure ()

-- | The text should be rendered from the media type.
shouldRenderFromMediaType :: Text -> MediaType -> SpecWith ()
shouldRenderFromMediaType text mediaType =
shouldRenderAsFrom (unpack text) fullText css
where
fullText = "@media " <> text <> "{}"
css = query mediaType [] emptyStyle

-- | The text should be rendered from the feature.
shouldRenderFromFeature :: Text -> Feature -> SpecWith ()
shouldRenderFromFeature text feature =
shouldRenderAsFrom (unpack text) fullText css
where
fullText = "@media all and (" <> text <> "){}"
css = query all [feature] emptyStyle

infixr 0 `shouldRenderFromMediaType`

infixr 0 `shouldRenderFromFeature`
4 changes: 4 additions & 0 deletions spec/Clay/SizeSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import Data.Text
import Data.Text.Lazy (toStrict)
import Data.List

Check warning on line 16 in spec/Clay/SizeSpec.hs

View workflow job for this annotation

GitHub Actions / Haskell GHC 8.10.7 cabal

To ensure compatibility with future core libraries changes

Check warning on line 16 in spec/Clay/SizeSpec.hs

View workflow job for this annotation

GitHub Actions / Haskell GHC 9.0.2 cabal

To ensure compatibility with future core libraries changes

Check warning on line 16 in spec/Clay/SizeSpec.hs

View workflow job for this annotation

GitHub Actions / Haskell GHC 9.2.2 cabal

To ensure compatibility with future core libraries changes

Check warning on line 16 in spec/Clay/SizeSpec.hs

View workflow job for this annotation

GitHub Actions / Haskell GHC 9.4.2 cabal

To ensure compatibility with future core libraries changes

import Prelude hiding (rem)

sizeRepr :: Size a -> Text
sizeRepr = plain . unValue . value

Expand Down Expand Up @@ -42,6 +44,8 @@ spec = do
sizeRepr (px 1) `shouldBe` "1px"
it "return 50% for (pct 50)" $
sizeRepr (pct 50) `shouldBe` "50%"
it "returns 0.6rem for (rem 0.6)" $
sizeRepr (rem 0.6) `shouldBe` "0.6rem"
describe "calc addition" $ do
it "returns proper calc for simple sum" $
sizeRepr (em 2 @+@ px 1) `shouldBe` "calc(2em + 1px)"
Expand Down
40 changes: 40 additions & 0 deletions spec/Clay/TextSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,43 @@ spec = do
textIndent initial
"{text-indent:unset}" `shouldRenderFrom`
textIndent unset

describe "hyphens" $ do
"{hyphens:none}" `shouldRenderFrom`
hyphens none
"{hyphens:manual}" `shouldRenderFrom`
hyphens manual
"{hyphens:auto}" `shouldRenderFrom`
hyphens auto
"{hyphens:initial}" `shouldRenderFrom`
hyphens initial
"{hyphens:inherit}" `shouldRenderFrom`
hyphens inherit
"{hyphens:unset}" `shouldRenderFrom`
hyphens unset
"{hyphens:nonsense}" `shouldRenderFrom`
hyphens (other "nonsense")

describe "hyphenate-character" $ do
"{hyphenate-character:\"hyphen\"}" `shouldRenderFrom`
hyphenateCharacter "hyphen"
"{hyphenate-character:\"\\\"quoted\\\"\"}" `shouldRenderFrom`
hyphenateCharacter "\"quoted\""
"{hyphenate-character:auto}" `shouldRenderFrom`
hyphenateCharacter auto
"{hyphenate-character:initial}" `shouldRenderFrom`
hyphenateCharacter initial
"{hyphenate-character:inherit}" `shouldRenderFrom`
hyphenateCharacter inherit
"{hyphenate-character:unset}" `shouldRenderFrom`
hyphenateCharacter unset
"{hyphenate-character:nonsense}" `shouldRenderFrom`
hyphenateCharacter (other "nonsense")

describe "hyphenate-limit-chars" $ do
"{hyphenate-limit-chars:10 11 12}" `shouldRenderFrom`
hyphenateLimitChars 10 11 12
"{hyphenate-limit-chars:auto 11 unset}" `shouldRenderFrom`
hyphenateLimitChars auto 11 unset
"{hyphenate-limit-chars:nonsense initial inherit}" `shouldRenderFrom`
hyphenateLimitChars (other "nonsense") initial inherit
5 changes: 2 additions & 3 deletions spec/Clay/TransitionSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ module Clay.TransitionSpec where

import Test.Hspec
import Clay
import Common

spec :: Spec
spec = do
describe "transition" $ do
describe "generates proper code" $ do
it "renders cubic-bezier" $
(plain (unValue (value (cubicBezier 1.0 2.0 3.0 4.0))))
it "renders cubic-bezier" $
plain (unValue (value (cubicBezier 1.0 2.0 3.0 4.0)))
`shouldBe`
"cubic-bezier(1,2,3,4)"
2 changes: 1 addition & 1 deletion src/Clay/Animation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ animationIterationCounts = prefixed (browsers <> "animation-iteration-count")
infinite :: IterationCount
infinite = IterationCount "infinite"

iterationCount :: Double -> IterationCount
iterationCount :: Number -> IterationCount
iterationCount = IterationCount . value

-------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/Clay/Display.hs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ overflowY = key "overflow-y"
-------------------------------------------------------------------------------

newtype Visibility = Visibility Value
deriving (Val, Other, Auto, Inherit, Hidden, Visible)
deriving (Val, Other, Inherit, Hidden, Unset, Visible)

separate, collapse :: Visibility

Expand All @@ -209,7 +209,7 @@ rect t r b l = Clip (mconcat ["rect(", value t, ",", value r, ",", value b, ",",

-------------------------------------------------------------------------------

opacity :: Double -> Css
opacity :: Number -> Css
opacity = key "opacity"

zIndex :: Integer -> Css
Expand Down
2 changes: 1 addition & 1 deletion src/Clay/Filter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ url u = Filter ("url(" <> value u <> ")")
blur :: Size LengthUnit -> Filter
blur i = Filter ("blur(" <> value i <> ")")

brightness :: Double -> Filter
brightness :: Number -> Filter
brightness i = Filter ("brightness(" <> value i <> ")")

contrast :: Size Percentage -> Filter
Expand Down
Loading

0 comments on commit be7a661

Please sign in to comment.