Skip to content

updated for purescript v0.9.1 #33

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 4 commits into from
Jun 21, 2016
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
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
language: node_js
sudo: false
dist: trusty
sudo: required
node_js:
- 4
install:
Expand Down
17 changes: 9 additions & 8 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@
"tests"
],
"dependencies": {
"purescript-generics": "^0.7.0",
"purescript-nonempty": "^0.1.2",
"purescript-profunctor": "^0.3.1",
"purescript-strings": "^0.7.0",
"purescript-these": "^0.3.0",
"purescript-transformers": "^0.8.1",
"purescript-colors": "^0.4.3"
"purescript-generics": "^1.0.0",
"purescript-nonempty": "^1.0.0",
"purescript-profunctor": "^1.0.0",
"purescript-strings": "^1.0.0",
"purescript-these": "^1.0.0",
"purescript-transformers": "^1.0.0",
"purescript-colors": "^1.0.0",
"purescript-console": "^1.0.0"
},
"devDependencies": {
"purescript-exceptions": "^0.3.0"
"purescript-exceptions": "^1.0.0"
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"gulp": "^3.8.11",
"gulp-jscs": "^1.6.0",
"gulp-jshint": "^1.11.2",
"gulp-purescript": "^0.7.0",
"gulp-purescript": "^1.0.0",
"gulp-run": "^1.6.8",
"purescript": "^0.8.2"
"purescript": "^0.9.1"
}
}
2 changes: 1 addition & 1 deletion src/CSS/Background.purs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ module CSS.Background
, angular

, Location
, Loc
, class Loc
, location
)
where
Expand Down
15 changes: 6 additions & 9 deletions src/CSS/Property.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Prelude

import Data.Foldable (intercalate)
import Data.Maybe (fromMaybe)
import Data.Monoid (Monoid, mempty)
import Data.Monoid (class Monoid, mempty)
import Data.NonEmpty (NonEmpty(), oneOf)
import Data.Profunctor.Strong (second)
import Data.Tuple (Tuple(..), lookup)
Expand All @@ -21,8 +21,8 @@ instance isStringPrefixed :: IsString Prefixed where

instance semigroupPrefixed :: Semigroup Prefixed where
append (Plain x) (Plain y) = Plain $ x <> y
append (Plain x) (Prefixed ys) = Prefixed $ second (x <>) <$> ys
append (Prefixed xs) (Plain y) = Prefixed $ second (y <>) <$> xs
append (Plain x) (Prefixed ys) = Prefixed $ second (x <> _) <$> ys
append (Prefixed xs) (Plain y) = Prefixed $ second (y <> _) <$> xs
append (Prefixed xs) (Prefixed ys) = Prefixed $ xs <> ys

instance monoidPrefixed :: Monoid Prefixed where
Expand Down Expand Up @@ -76,7 +76,7 @@ instance valNumber :: Val Number where
value = fromString <<< show

instance valList :: (Val a) => Val (Array a) where
value = intercalate (fromString ", ") <<< (value <$>)
value = intercalate (fromString ", ") <<< (value <$> _)

instance valNonEmpty :: (Val a) => Val (NonEmpty Array a) where
value = value <<< oneOf
Expand All @@ -85,9 +85,6 @@ instance valColor :: Val Color where
value = fromString <<< cssStringHSLA

noCommas :: forall a. (Val a) => Array a -> Value
noCommas = intercalate (fromString " ") <<< (value <$>)
noCommas = intercalate (fromString " ") <<< (value <$> _)

infixr 9 !

(!) :: forall a b. a -> b -> Tuple a b
(!) = Tuple
infixr 9 Tuple as !
18 changes: 9 additions & 9 deletions src/CSS/Render.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (log, CONSOLE)
import Data.Array (null, (:), drop, sort, uncons, mapMaybe)
import Data.Either (Either(..), either)
import Data.Foldable (fold, foldMap, intercalate, mconcat)
import Data.Foldable (fold, foldMap, intercalate)
import Data.Maybe (Maybe(..), fromMaybe, maybe)
import Data.Monoid (Monoid, mempty)
import Data.Monoid (class Monoid, mempty)
import Data.NonEmpty (NonEmpty(..), (:|), foldl1, oneOf)
import Data.These (These(..), theseLeft, theseRight)
import Data.Tuple (Tuple(..), lookup, uncurry)
Expand Down Expand Up @@ -42,10 +42,10 @@ instance monoidFile :: Monoid Sheet where
type Rendered = Maybe (These Inline Sheet)

renderedInline :: Rendered -> Maybe String
renderedInline = (>>= (map getInline <<< theseLeft))
renderedInline = (_ >>= (map getInline <<< theseLeft))

renderedSheet :: Rendered -> Maybe String
renderedSheet = (>>= (map getSheet <<< theseRight))
renderedSheet = (_ >>= (map getSheet <<< theseRight))

render :: forall a. StyleM a -> Rendered
render = rules [] <<< runS
Expand All @@ -71,7 +71,7 @@ kframe (Keyframes ident xs) =
, "@-o-keyframes"
]
allKeywordsWithContent =
mconcat $ map (_ <> renderContent) keywords
fold $ map (_ <> renderContent) keywords

frame :: Number -> Array Rule -> String
frame p rs = show p <> "% " <> "{ " <> x <> " }"
Expand All @@ -81,7 +81,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 <> foldl1 (<>) ((" 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 @@ -130,7 +130,7 @@ selector :: Selector -> String
selector = intercalate ", " <<< selector'

selector' :: Selector -> Array String
selector' (Selector (Refinement ft) p) = (<> (foldMap predicate (sort ft))) <$> selector'' ft p
selector' (Selector (Refinement ft) p) = (_ <> (foldMap predicate (sort ft))) <$> selector'' ft p

selector'' :: Array Predicate -> Path Selector -> Array String
selector'' [] Star = ["*"]
Expand All @@ -151,11 +151,11 @@ collect' :: Prefixed -> Prefixed -> Array (Either String (Tuple String String))
collect' (Plain k) (Plain v) = [Right (Tuple k v)]
collect' (Prefixed ks) (Plain v) = (\(Tuple p k) -> Right $ Tuple (p <> k) v) <$> ks
collect' (Plain k) (Prefixed vs) = (\(Tuple p v) -> Right $ Tuple k (p <> v)) <$> vs
collect' (Prefixed ks) (Prefixed vs) = (\(Tuple p k) -> maybe (Left (p <> k)) (Right <<< Tuple (p <> k) <<< (p <>)) $ lookup p vs) <$> ks
collect' (Prefixed ks) (Prefixed vs) = (\(Tuple p k) -> maybe (Left (p <> k)) (Right <<< Tuple (p <> k) <<< (p <> _)) $ lookup p vs) <$> ks

properties :: Array (Either String (Tuple String String)) -> String
properties xs = intercalate "; " $ sheetRules <$> xs
where sheetRules = either (\_ -> mempty) (\(Tuple k v) -> mconcat [k, ": ", v])
where sheetRules = either (\_ -> mempty) (\(Tuple k v) -> fold [k, ": ", v])

merger :: NonEmpty Array App -> Selector
merger (NonEmpty x xs) =
Expand Down
16 changes: 5 additions & 11 deletions src/CSS/Selector.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module CSS.Selector where

import Prelude

import Data.Generic (Generic, gEq, gCompare)
import Data.Generic (class Generic, gEq, gCompare)
import Data.String (take, drop)

import CSS.String
Expand Down Expand Up @@ -61,18 +61,12 @@ element e = Selector (Refinement []) (Elem e)

deep :: Selector -> Selector -> Selector
deep a b = Selector (Refinement []) (Deep a b)

(**) :: Selector -> Selector -> Selector
(**) = deep
infix 0 deep as **

child :: Selector -> Selector -> Selector
child a b = Selector (Refinement []) (PathChild a b)

(|>) :: Selector -> Selector -> Selector
(|>) = child
infix 0 child as |>

with :: Selector -> Refinement -> Selector
with (Selector (Refinement fs) e) (Refinement ps) = Selector (Refinement (fs ++ ps)) e

(##) :: Selector -> Refinement -> Selector
(##) = with
with (Selector (Refinement fs) e) (Refinement ps) = Selector (Refinement (fs <> ps)) e
infix 0 child as ##
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would probably be better to work out some sensible fixities for these operators based on the way they combine rather than trying to emulate the previous situation of unspecified fixities.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't used it enough to understand what the best fixities are..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise 😄

Ok, I'll open a new issue for that and address it before releasing the new version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, haha 😄

8 changes: 4 additions & 4 deletions src/CSS/Stylesheet.purs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Data.NonEmpty (NonEmpty(), (:|))
import Data.Profunctor.Strong (second)
import Data.Tuple (Tuple(..))

import CSS.Property (Val, Key(Key), Prefixed, Value(), cast, value)
import CSS.Property (class Val, Key(Key), Prefixed, Value(), cast, value)
import CSS.Selector (Selector(), Refinement())

newtype MediaType = MediaType Value
Expand Down Expand Up @@ -71,9 +71,9 @@ key k v = rule $ Property (cast k) (value v)
prefixed :: forall a. Val a => Prefixed -> a -> CSS
prefixed xs = key (Key xs)

infixr 5 ?
(?) :: Selector -> CSS -> CSS
(?) sel rs = rule $ Nested (Sub sel) (runS rs)
infixr 5 select as ?
select :: Selector -> CSS -> CSS
select sel rs = rule $ Nested (Sub sel) (runS rs)

query :: MediaType -> NonEmpty Array Feature -> CSS -> CSS
query ty fs = rule <<< Query (MediaQuery Nothing ty fs) <<< runS
Expand Down