Skip to content

Commit ea7f659

Browse files
authored
Merge pull request #14 from cryogenian/10-updates
0.10 updates
2 parents baa98de + d10160a commit ea7f659

File tree

5 files changed

+52
-39
lines changed

5 files changed

+52
-39
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
language: node_js
2+
node_js: stable
23
dist: trusty
34
sudo: required
45
node_js: 5

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"package.json"
2323
],
2424
"dependencies": {
25-
"purescript-css": "^1.1.0",
26-
"purescript-halogen": "^0.11.0"
25+
"purescript-css": "^2.0.0",
26+
"purescript-halogen": "^0.12.0"
2727
}
2828
}

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"private": true,
3+
"license": "Apache-2.0",
34
"scripts": {
4-
"clean": "rimraf output && rimraf .pulp-cache",
5+
"clean": "rm -rf output .pulp-cache",
56
"build": "pulp build --censor-lib --strict"
67
},
78
"devDependencies": {
89
"pulp": "^9.0.1",
9-
"purescript": "^0.9.2",
10-
"purescript-psa": "^0.3.9",
11-
"rimraf": "^2.5.4"
10+
"purescript": "0.10.1",
11+
"purescript-psa": "^0.3.9"
1212
}
1313
}

src/Halogen/HTML/CSS.purs

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,65 @@ module Halogen.HTML.CSS
77

88
import Prelude
99

10-
import Data.Array (mapMaybe)
11-
import Data.Either (Either(), either)
12-
import Data.List (toUnfoldable, fromFoldable)
10+
import CSS.Property (Key, Value)
11+
import CSS.Render (render, renderedSheet, collect)
12+
import CSS.Stylesheet (CSS, Rule(..), runS)
13+
14+
import Data.Array (mapMaybe, concatMap, singleton)
15+
import Data.Either (Either)
16+
import Data.Foldable (foldMap)
1317
import Data.Maybe (Maybe(..), fromMaybe)
14-
import Data.String (joinWith)
18+
import Data.Newtype (class Newtype)
1519
import Data.StrMap as SM
20+
import Data.String (joinWith)
1621
import Data.Tuple (Tuple(..))
1722

18-
import CSS.Property (Key(), Value())
19-
import CSS.Render (render, renderedSheet, collect)
20-
import CSS.Stylesheet (CSS(), Rule(..), runS)
21-
22-
import Halogen.HTML as H
23-
import Halogen.HTML.Core (HTML(), Prop(), class IsProp, prop, propName, attrName)
23+
import Halogen.HTML as HH
24+
import Halogen.HTML.Core (HTML, Prop, class IsProp, prop, propName, attrName)
25+
import Halogen.HTML.Elements as HE
2426
import Halogen.HTML.Properties as P
2527

2628
-- | A newtype for CSS styles
2729
newtype Styles = Styles (SM.StrMap String)
2830

29-
-- | Unpack CSS styles
30-
runStyles :: Styles -> SM.StrMap String
31-
runStyles (Styles m) = m
31+
derive instance newtypeStylesNewtype Styles _
3232

33-
instance stylesIsProp :: IsProp Styles where
34-
toPropString _ _ (Styles m) = joinWith "; " $ (\(Tuple key value) -> key <> ": " <> value) <$> toUnfoldable (SM.toList m)
33+
instance stylesIsPropIsProp Styles where
34+
toPropString _ _ (Styles m) =
35+
joinWith "; " $ SM.foldMap (\key value → [key <> ": " <> value]) m
3536

3637
-- | Render a set of rules as an inline style.
3738
-- |
3839
-- | For example:
3940
-- |
4041
-- | ```purescript
41-
-- | H.div [ CSS.style do color red
42+
-- | HH.div [ CSS.style do color red
4243
-- | display block ]
4344
-- | [ ... ]
4445
-- | ```
45-
style :: forall i. CSS -> Prop i
46-
style = prop (propName "style") (Just $ attrName "style") <<< Styles <<< rules <<< runS
46+
style i. CSS Prop i
47+
style =
48+
prop (propName "style") (Just $ attrName "style")
49+
<<< Styles
50+
<<< rules
51+
<<< runS
4752
where
48-
rules :: Array Rule -> SM.StrMap String
49-
rules rs = SM.fromList (fromFoldable properties)
53+
rules Array Rule SM.StrMap String
54+
rules rs = SM.fromFoldable properties
5055
where
51-
properties :: Array (Tuple String String)
56+
properties Array (Tuple String String)
5257
properties = mapMaybe property rs >>= collect >>> rights
5358

54-
property :: Rule -> Maybe (Tuple (Key Unit) Value)
59+
property Rule Maybe (Tuple (Key Unit) Value)
5560
property (Property k v) = Just (Tuple k v)
5661
property _ = Nothing
5762

58-
rights :: forall a b. Array (Either a b) -> Array b
59-
rights = mapMaybe (either (const Nothing) Just)
63+
rights a b. Array (Either a b) Array b
64+
rights = concatMap $ foldMap singleton
6065

6166
-- | Render a set of rules as a `style` element.
62-
stylesheet :: forall p i. CSS -> HTML p i
63-
stylesheet css = H.style [ P.type_ "text/css" ] [ H.text content ]
67+
stylesheet p i. CSS HTML p i
68+
stylesheet css =
69+
HE.style [ P.type_ "text/css" ] [ HH.text content ]
6470
where
6571
content = fromMaybe "" $ renderedSheet $ render css

src/Halogen/HTML/CSS/Indexed.purs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@ module Halogen.HTML.CSS.Indexed where
22

33
import Unsafe.Coerce (unsafeCoerce)
44

5-
import CSS.Stylesheet (CSS())
5+
import CSS.Stylesheet (CSS)
66

7-
import Halogen.HTML.Elements.Indexed (NoninteractiveNode())
8-
import Halogen.HTML.Properties.Indexed (IProp(), I())
7+
import Halogen.HTML.Elements.Indexed (NoninteractiveNode)
8+
import Halogen.HTML.Properties.Indexed (IProp, I)
99
import Halogen.HTML.CSS as CSS
1010

11-
style :: forall i r. CSS -> IProp (style :: I | r) i
12-
style = unsafeCoerce CSS.style
11+
style
12+
i r. CSS IProp (style I | r) i
13+
style =
14+
unsafeCoerce CSS.style
1315

14-
stylesheet :: forall p i. CSS -> NoninteractiveNode (media :: I, onError :: I, onLoad :: I, scoped :: I, mediaType :: I) p i
15-
stylesheet = unsafeCoerce CSS.stylesheet
16+
stylesheet
17+
p i
18+
. CSS
19+
NoninteractiveNode (media I, onError I, onLoad I, scoped I, mediaType I) p i
20+
stylesheet =
21+
unsafeCoerce CSS.stylesheet

0 commit comments

Comments
 (0)