Skip to content

Commit

Permalink
Adds Not type class, Fixes sebastiaanvisser#239
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyfold committed Jun 8, 2022
1 parent 92d73d8 commit e3a4996
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/Clay/Pseudo.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE FlexibleInstances #-}
module Clay.Pseudo where

import Data.Text (Text)

import Clay.Render (renderSelector)
import Clay.Render (renderSelector, renderRefinement)
import Clay.Selector

import qualified Data.Text.Lazy as Lazy
Expand Down Expand Up @@ -64,5 +66,19 @@ nthLastChild n = func "nth-last-child" [n]
nthLastOfType n = func "nth-last-of-type" [n]
nthOfType n = func "nth-of-type" [n]

not :: Selector -> Refinement
not r = func "not" [Lazy.toStrict (renderSelector r)]
-- | The 'not' pseudo selector can be applied to both a 'Refinement'
--
-- > input # not checked
--
-- or a 'Selector'
--
-- > not p

class Not a where
not :: a -> Refinement

instance Not Selector where
not r = func "not" [Lazy.toStrict (renderSelector r)]

instance Not Refinement where
not r = func "not" (Lazy.toStrict <$> renderRefinement r)
6 changes: 6 additions & 0 deletions src/Clay/Render.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Clay.Render
, putCss
, renderWith
, renderSelector
, renderRefinement
, withBanner
)
where
Expand Down Expand Up @@ -120,6 +121,11 @@ renderWith cfg top
renderSelector :: Selector -> Lazy.Text
renderSelector = toLazyText . selector compact

-- | Render a CSS `Refinement`.

renderRefinement :: Refinement -> [Lazy.Text]
renderRefinement r = toLazyText . predicate <$> unFilter r

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

renderBanner :: Config -> Lazy.Text -> Lazy.Text
Expand Down

0 comments on commit e3a4996

Please sign in to comment.