Skip to content

Commit

Permalink
Merge pull request #49 from alexmingoia/topic/list-style-rule
Browse files Browse the repository at this point in the history
Add list-style rule
  • Loading branch information
garyb authored Feb 7, 2017
2 parents 70eb12d + 50f2a23 commit 411cc2c
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/CSS/Common.purs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class Visible a where visible :: a
class Hidden a where hidden :: a
class Initial a where initial :: a
class Unset a where unset :: a

class Top a where top :: a
class Middle a where middle :: a
class Bottom a where bottom :: a
class URL a where url :: String -> a

-- | The other type class is used to escape from the type safety introduced by
-- embedding CSS properties into the typed world of purescript-css.
Expand All @@ -50,10 +50,10 @@ instance hiddenValue :: Hidden Value where hidden = fromString "hidden"
instance otherValue :: Other Value where other = id
instance initialValue :: Initial Value where initial = fromString "initial"
instance unsetValue :: Unset Value where unset = fromString "unset"

instance topValue :: Top Value where top = fromString "top"
instance middleValue :: Middle Value where middle = fromString "middle"
instance bottomValue :: Bottom Value where bottom = fromString "bottom"
instance urlValue :: URL Value where url s = fromString ("url(\"" <> s <> "\")")

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

Expand Down
17 changes: 17 additions & 0 deletions src/CSS/ListStyle.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module CSS.ListStyle where

import CSS.ListStyle.Image (ListStyleImage)
import CSS.ListStyle.Position (ListStylePosition)
import CSS.ListStyle.Type (ListStyleType)
import CSS.Property (class Val, value)
import CSS.String (fromString)
import CSS.Stylesheet (CSS, key)
import Data.Tuple.Nested (tuple3)

data ListStyle = ListStyle ListStyleType ListStylePosition ListStyleImage

instance valueListStyle :: Val ListStyle where
value (ListStyle t p i) = value (tuple3 t p i)

listStyle :: ListStyleType -> ListStylePosition -> ListStyleImage -> CSS
listStyle t p i = key (fromString "list-style") (ListStyle t p i)
51 changes: 51 additions & 0 deletions src/CSS/ListStyle/Image.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module CSS.ListStyle.Image where

import CSS.Common (class Inherit, class Initial, class None, class Unset, class URL)
import CSS.Property (class Val)
import CSS.String (fromString)
import CSS.Stylesheet (CSS, key)
import Data.Eq (class Eq)
import Data.Function (($))
import Data.Generic (class Generic, gShow)
import Data.Ord (class Ord)
import Data.Semigroup ((<>))
import Data.Show (class Show)

data ListStyleImage
= ListStyleImage String
| Initial
| Inherit
| Unset
| None

derive instance eqListStyleImage :: Eq ListStyleImage
derive instance ordListStyleImage :: Ord ListStyleImage
derive instance genericListStyleImage :: Generic ListStyleImage

instance showListStyleImage :: Show ListStyleImage where
show = gShow

instance valListStyleImage :: Val ListStyleImage where
value (Initial) = fromString "initial"
value (Inherit) = fromString "inherit"
value (Unset) = fromString "unset"
value (None) = fromString "none"
value (ListStyleImage url) = fromString ("url('" <> url <> "')")

instance initialListStyleImage :: Initial ListStyleImage where
initial = Initial

instance inheritListStyleImage :: Inherit ListStyleImage where
inherit = Inherit

instance unsetListStyleImage :: Unset ListStyleImage where
unset = Unset

instance noneListImageImage :: None ListStyleImage where
none = None

instance urlListStyleImage :: URL ListStyleImage where
url s = ListStyleImage s

listStyleImage :: ListStyleImage -> CSS
listStyleImage = key $ fromString "list-style-image"
50 changes: 50 additions & 0 deletions src/CSS/ListStyle/Position.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module CSS.ListStyle.Position where

import CSS.Common (class Inherit, class Initial, class Unset)
import CSS.Property (class Val)
import CSS.String (fromString)
import CSS.Stylesheet (CSS, key)
import Data.Eq (class Eq)
import Data.Function (($))
import Data.Generic (class Generic, gShow)
import Data.Ord (class Ord)
import Data.Show (class Show)

data ListStylePosition
= Inside
| Outside
| Inherit
| Initial
| Unset

derive instance eqListStylePosition :: Eq ListStylePosition
derive instance ordListStylePosition :: Ord ListStylePosition
derive instance genericListStylePosition :: Generic ListStylePosition

instance showListStylePosition :: Show ListStylePosition where
show = gShow

instance valListStylePosition :: Val ListStylePosition where
value (Inside) = fromString "inside"
value (Outside) = fromString "outside"
value (Inherit) = fromString "inherit"
value (Initial) = fromString "initial"
value (Unset) = fromString "unset"

instance initialListStylePosition :: Initial ListStylePosition where
initial = Initial

instance inheritListStylePosition :: Inherit ListStylePosition where
inherit = Inherit

instance unsetListStylePosition :: Unset ListStylePosition where
unset = Unset

inside :: ListStylePosition
inside = Inside

outside :: ListStylePosition
outside = Outside

listStylePosition :: ListStylePosition -> CSS
listStylePosition = key $ fromString "list-style-position"
91 changes: 91 additions & 0 deletions src/CSS/ListStyle/Type.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
module CSS.ListStyle.Type where

import CSS.Common (class Inherit, class Initial, class None, class Unset)
import CSS.Property (class Val)
import CSS.String (fromString)
import CSS.Stylesheet (CSS, key)
import Data.Eq (class Eq)
import Data.Function (($))
import Data.Generic (class Generic, gShow)
import Data.Ord (class Ord)
import Data.Semigroup ((<>))
import Data.Show (class Show)

data ListStyleType
= Disc
| Circle
| Square
| Decimal
| Georgian
| CJKIdeographic
| Kannada
| None
| Inherit
| Initial
| Unset
| CustomStyleType String
| StringStyleType String

derive instance eqListStyleType :: Eq ListStyleType
derive instance ordListStyleType :: Ord ListStyleType
derive instance genericListStyleType :: Generic ListStyleType

instance showListStyleType :: Show ListStyleType where
show = gShow

instance valListStyleType :: Val ListStyleType where
value (Disc) = fromString "disc"
value (Circle) = fromString "circle"
value (Square) = fromString "square"
value (Decimal) = fromString "decimal"
value (Georgian) = fromString "georgian"
value (CJKIdeographic) = fromString "cjk-ideographic"
value (Kannada) = fromString "kannada"
value (None) = fromString "none"
value (Initial) = fromString "initial"
value (Inherit) = fromString "inherit"
value (Unset) = fromString "unset"
value (CustomStyleType s) = fromString ("custom-" <> s)
value (StringStyleType s) = fromString s

instance initialListStyleType :: Initial ListStyleType where
initial = Initial

instance inheritListStyleType :: Inherit ListStyleType where
inherit = Inherit

instance unsetListStyleType :: Unset ListStyleType where
unset = Unset

instance noneListTypeType :: None ListStyleType where
none = None

disc :: ListStyleType
disc = Disc

circle :: ListStyleType
circle = Circle

square :: ListStyleType
square = Square

decimal :: ListStyleType
decimal = Decimal

georgian :: ListStyleType
georgian = Georgian

cjkIdeographic :: ListStyleType
cjkIdeographic = CJKIdeographic

kannada :: ListStyleType
kannada = Kannada

customListStyleType :: String -> ListStyleType
customListStyleType s = CustomStyleType s

stringListStyleType :: String -> ListStyleType
stringListStyleType s = StringStyleType s

listStyleType :: ListStyleType -> CSS
listStyleType = key $ fromString "list-style-type"

0 comments on commit 411cc2c

Please sign in to comment.