Skip to content

Switch to purescript-nonempty #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"tests"
],
"dependencies": {
"purescript-nonempty-arrays": "garyb/purescript-nonempty-array#0.7-updates",
"purescript-nonempty": "^0.1.1",
"purescript-profunctor": "^0.3.0",
"purescript-strings": "^0.5.2",
"purescript-these": "^0.3.0",
Expand Down
6 changes: 3 additions & 3 deletions src/Css/Font.purs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Css.Property
import Css.Size
import Css.String
import Css.Stylesheet
import qualified Data.Array.NonEmpty as NEL
import Data.NonEmpty

color :: Color -> Css
color = key $ fromString "color"
Expand All @@ -19,8 +19,8 @@ instance valGenericFontFamily :: Val GenericFontFamily where
sansSerif :: GenericFontFamily
sansSerif = GenericFontFamily $ fromString "sans-serif"

fontFamily :: Array String -> NEL.NonEmpty GenericFontFamily -> Css
fontFamily a b = key (fromString "font-family") <<< value $ (value <<< quote <$> a) <> NEL.toArray (value <$> b)
fontFamily :: Array String -> NonEmpty Array GenericFontFamily -> Css
fontFamily a b = key (fromString "font-family") <<< value $ (value <<< quote <$> a) <> oneOf (value <$> b)

fontSize :: forall a. Size a -> Css
fontSize = key $ fromString "font-size"
Expand Down
4 changes: 2 additions & 2 deletions src/Css/FontFace.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Css.Property
import Css.String
import Css.Stylesheet
import Data.Maybe
import qualified Data.Array.NonEmpty as NEL
import Data.NonEmpty

fontFaceFamily :: String -> Css
fontFaceFamily = key (fromString "font-family") <<< Literal
Expand All @@ -32,5 +32,5 @@ instance valFontFaceSrc :: Val FontFaceSrc where
value (FontFaceSrcUrl u f) = fromString $ "url(" <> quote u <> ")" <> maybe "" (\f' -> " format(" <> formatName f' <> ")") f
value (FontFaceSrcLocal l) = fromString $ "local(" <> quote l <> ")"

fontFaceSrc :: NEL.NonEmpty FontFaceSrc -> Css
fontFaceSrc :: NonEmpty Array FontFaceSrc -> Css
fontFaceSrc = key $ fromString "src"
6 changes: 3 additions & 3 deletions src/Css/Property.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Data.Maybe
import Data.Monoid
import Data.Profunctor.Strong
import Data.Tuple
import qualified Data.Array.NonEmpty as NEL
import Data.NonEmpty

data Prefixed = Prefixed (Array (Tuple String String))
| Plain String
Expand Down Expand Up @@ -74,8 +74,8 @@ instance valNumber :: Val Number where
instance valList :: (Val a) => Val (Array a) where
value = intercalate (fromString ", ") <<< (value <$>)

instance valNonEmpty :: (Val a) => Val (NEL.NonEmpty a) where
value = value <<< NEL.toArray
instance valNonEmpty :: (Val a) => Val (NonEmpty Array a) where
value = value <<< oneOf

noCommas :: forall a. (Val a) => Array a -> Value
noCommas = intercalate (fromString " ") <<< (value <$>)
16 changes: 8 additions & 8 deletions src/Css/Render.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Data.Maybe
import Data.Monoid
import Data.These
import Data.Tuple
import qualified Data.Array.NonEmpty as NEL
import Data.NonEmpty

newtype Inline = Inline String

Expand Down Expand Up @@ -58,7 +58,7 @@ query' :: MediaQuery -> Array App -> Array Rule -> Rendered
query' q sel rs = Just <<< That <<< Sheet $ mediaQuery q <> " { " <> fromMaybe "" (renderedSheet $ rules sel rs) <> " }\n"

mediaQuery :: MediaQuery -> String
mediaQuery (MediaQuery no ty fs) = "@media " <> mediaType ty <> NEL.sconcat ((" and " <>) <<< feature <$> fs)
mediaQuery (MediaQuery no ty fs) = "@media " <> mediaType ty <> foldl1 (<>) ((" and " <>) <<< feature <$> fs)

mediaType :: MediaType -> String
mediaType (MediaType (Value s)) = plain s
Expand Down Expand Up @@ -97,7 +97,7 @@ imp t = Just <<< That <<< Sheet <<< fromString $ "@import url(" <> t <> ");\n"
rule' :: forall a. Array App -> Array (Tuple (Key a) Value) -> Rendered
rule' sel props = maybe q o $ nel sel
where p = props >>= collect
q = (This <<< Inline <<< properties <<< NEL.toArray) <$> nel p
q = (This <<< Inline <<< properties <<< oneOf) <$> nel p
o sel' = Just <<< That <<< Sheet $ intercalate " " [selector (merger sel'), "{", properties p, "}"]

selector :: Selector -> String
Expand Down Expand Up @@ -131,13 +131,13 @@ properties :: Array (Either String (Tuple String String)) -> String
properties xs = intercalate "; " $ sheetRules <$> xs
where sheetRules = either (\_ -> mempty) (\(Tuple k v) -> mconcat [k, ": ", v])

merger :: NEL.NonEmpty App -> Selector
merger (NEL.NonEmpty x xs) =
merger :: NonEmpty Array App -> Selector
merger (NonEmpty x xs) =
case x of
Child s -> maybe s (\xs' -> merger xs' |> s) $ nel xs
Sub s -> maybe s (\xs' -> merger xs' ** s) $ nel xs
Root s -> maybe s (\xs' -> s ** merger xs') $ nel xs
Pop i -> maybe (element "TODO") merger <<< nel <<< NEL.drop i $ x NEL.:| xs
Pop i -> maybe (element "TODO") merger <<< nel <<< drop i $ x : xs
Self sheetRules -> maybe (star `with` sheetRules) (\xs' -> merger xs' `with` sheetRules) $ nel xs

predicate :: Predicate -> String
Expand All @@ -153,6 +153,6 @@ predicate (AttrHyph a v) = "[" <> a <> "|='" <> v <> "']"
predicate (Pseudo a ) = ":" <> a
predicate (PseudoFunc a p) = ":" <> a <> "(" <> intercalate "," p <> ")"

nel :: forall a. Array a -> Maybe (NEL.NonEmpty a)
nel :: forall a. Array a -> Maybe (NonEmpty Array a)
nel [] = Nothing
nel xs = (\{ head: head, tail: tail } -> head NEL.:| tail) <$> uncons xs
nel xs = (\{ head: head, tail: tail } -> head :| tail) <$> uncons xs
12 changes: 6 additions & 6 deletions src/Css/Stylesheet.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import Data.Array (singleton)
import Data.Maybe
import Data.Profunctor.Strong
import Data.Tuple
import qualified Data.Array.NonEmpty as NEL
import Data.NonEmpty

newtype MediaType = MediaType Value

data NotOrOnly = Not | Only

data MediaQuery = MediaQuery (Maybe NotOrOnly) MediaType (NEL.NonEmpty Feature)
data MediaQuery = MediaQuery (Maybe NotOrOnly) MediaType (NonEmpty Array Feature)

data Feature = Feature String (Maybe Value)

Expand All @@ -25,7 +25,7 @@ data App = Self Refinement
| Child Selector
| Sub Selector

data Keyframes = Keyframes String (NEL.NonEmpty (Tuple Number (Array Rule)))
data Keyframes = Keyframes String (NonEmpty Array (Tuple Number (Array Rule)))

data Rule = Property (Key Unit) Value
| Nested App (Array Rule)
Expand Down Expand Up @@ -65,14 +65,14 @@ infixr 5 ?
(?) :: Selector -> Css -> Css
(?) sel rs = rule $ Nested (Sub sel) (runS rs)

query :: MediaType -> NEL.NonEmpty Feature -> Css -> Css
query :: MediaType -> NonEmpty Array Feature -> Css -> Css
query ty fs = rule <<< Query (MediaQuery Nothing ty fs) <<< runS

keyframes :: String -> NEL.NonEmpty (Tuple Number Css) -> Css
keyframes :: String -> NonEmpty Array (Tuple Number Css) -> Css
keyframes n xs = rule $ Keyframe (Keyframes n (second runS <$> xs))

keyframesFromTo :: String -> Css -> Css -> Css
keyframesFromTo n a b = keyframes n $ Tuple 0.0 a NEL.:| [Tuple 100.0 b]
keyframesFromTo n a b = keyframes n $ Tuple 0.0 a :| [Tuple 100.0 b]

fontFace :: Css -> Css
fontFace = rule <<< Face <<< runS
Expand Down