By | Chris Done |
At | 2011-06-14 |
Title | Switch to `css' library. |
Description |
Edit file amelie.cabal 33188 → 33188
39 39 ,blaze-builder >= 0.2
40 40 ,ConfigFile >= 1.0
41 41 ,feed >= 0.3
42 42 ,download-curl >= 0.1
43 43 ,Diff >= 0.1
+ 44 ,css >= 0.1
… … … … Remove file src/Text/CSS.hs 33188
- 1 {-# OPTIONS -Wall #-} - 2 {-# LANGUAGE OverloadedStrings #-} - 3 {-# LANGUAGE GeneralizedNewtypeDeriving #-} - 4 {-# LANGUAGE NamedFieldPuns #-} - 5 {-# LANGUAGE FlexibleInstances #-} - 6 -- | CSS generation. - 7 - 8 module Text.CSS - 9 (module Text.CSS.Types - 10 ,module Text.CSS.Properties - 11 ,runCSS - 12 ,renderCSS - 13 ,renderPrettyCSS - 14 ,rules - 15 ,rule) - 16 where - 17 - 18 import Text.CSS.Properties - 19 import Text.CSS.Types - 20 - 21 import Control.Monad.Writer (MonadWriter,runWriter,tell) - 22 import Data.Either (lefts,rights) - 23 import Data.Monoid (Monoid(..)) - 24 import Data.Monoid.Operator ((++)) - 25 import Data.Text.Lazy (Text) - 26 import qualified Data.Text.Lazy as T - 27 import Prelude hiding ((++)) - 28 - 29 -- | Generate CSS rules. - 30 runCSS :: CSS Rule -> [Rule] - 31 runCSS = snd . runWriter . unCSS - 32 - 33 -- | Generate CSS properties. - 34 runBody :: CSS (Either Property Rule) -> [(Either Property Rule)] - 35 runBody = snd . runWriter . unCSS - 36 - 37 -- | Render a CSS AST to text, flat. - 38 renderCSS :: [Rule] -> Text - 39 renderCSS = mconcat . map renderRule where - 40 renderRule (Rule _name [] []) = "" - 41 renderRule (Rule name props sub) = - 42 parent ++ - 43 renderCSS (map prefix sub) - 44 where parent | null props = "" - 45 | otherwise = name ++ "{" ++ renderProps props ++ "}" - 46 prefix subr@Rule{ruleExpr} = - 47 subr { ruleExpr = name ++ " " ++ ruleExpr } - 48 renderProps = T.intercalate ";" . map renderProp - 49 renderProp (Property name value) = name ++ ":" ++ value - 50 - 51 -- | Render a CSS AST to text, pretty. - 52 renderPrettyCSS :: [Rule] -> Text - 53 renderPrettyCSS = mconcat . map renderRule where - 54 renderRule (Rule name props sub) = - 55 name ++ "{\n" ++ renderProps props ++ "\n}" ++ "\n" ++ - 56 renderPrettyCSS (map prefix sub) - 57 where prefix subr@Rule{ruleExpr} = - 58 subr { ruleExpr = name ++ " " ++ ruleExpr } - 59 renderProps = T.intercalate ";\n" . map ((" "++) . renderProp) - 60 renderProp (Property name value) = name ++ ": " ++ value - 61 - 62 class Ruleable a where - 63 rule :: Text -> CSS (Either Property Rule) -> CSS a - 64 rules :: [Text] -> CSS (Either Property Rule) -> CSS a - 65 rules rs body = mapM_ (`rule` body) rs - 66 - 67 instance Ruleable Rule where - 68 rule name getProps = do - 69 let body = runBody getProps - 70 tell $ [Rule name (lefts body) (rights body)] - 71 - 72 instance Ruleable (Either Property Rule) where - 73 rule name getProps = do - 74 let body = runBody getProps - 75 tell $ [Right $ Rule name (lefts body) (rights body)] Remove file src/Text/CSS/Properties.hs 33188
- 1 {-# OPTIONS -Wall #-} - 2 {-# LANGUAGE OverloadedStrings #-} - 3 {-# LANGUAGE GeneralizedNewtypeDeriving #-} - 4 {-# LANGUAGE NamedFieldPuns #-} - 5 -- | CSS generation. - 6 - 7 module Text.CSS.Properties where - 8 - 9 import Text.CSS.Types (CSS,Rule,Property(..)) - 10 - 11 import Control.Monad.Writer (MonadWriter,tell) - 12 import Data.Text.Lazy (Text) - 13 - 14 -- | Make a CSS property. - 15 prop :: Text -> Text -> CSS (Either Property Rule) - 16 prop name value = tell [Left $ Property name value] - 17 - 18 -- Additional ones from CSS3 - 19 - 20 -- | CSS property: border-radius - 21 borderRadius :: Text -> CSS (Either Property Rule) - 22 borderRadius = prop "border-radius" - 23 - 24 -- Generated from http://www.w3.org/TR/CSS21/propidx.html - 25 - 26 -- | CSS property: azimuth - 27 azimuth :: Text -> CSS (Either Property Rule) - 28 azimuth = prop "azimuth" - 29 - 30 -- | CSS property: background-color - 31 backgroundColor :: Text -> CSS (Either Property Rule) - 32 backgroundColor = prop "background-color" - 33 - 34 -- | CSS property: background-image - 35 backgroundImage :: Text -> CSS (Either Property Rule) - 36 backgroundImage = prop "background-image" - 37 - 38 -- | CSS property: background-position - 39 backgroundPosition :: Text -> CSS (Either Property Rule) - 40 backgroundPosition = prop "background-position" - 41 - 42 -- | CSS property: background-repeat - 43 backgroundRepeat :: Text -> CSS (Either Property Rule) - 44 backgroundRepeat = prop "background-repeat" - 45 - 46 -- | CSS property: background - 47 background :: Text -> CSS (Either Property Rule) - 48 background = prop "background" - 49 - 50 -- | CSS property: border-collapse - 51 borderCollapse :: Text -> CSS (Either Property Rule) - 52 borderCollapse = prop "border-collapse" - 53 - 54 -- | CSS property: border-color - 55 borderColor :: Text -> CSS (Either Property Rule) - 56 borderColor = prop "border-color" - 57 - 58 -- | CSS property: border-spacing - 59 borderSpacing :: Text -> CSS (Either Property Rule) - 60 borderSpacing = prop "border-spacing" - 61 - 62 -- | CSS property: border-style - 63 borderStyle :: Text -> CSS (Either Property Rule) - 64 borderStyle = prop "border-style" - 65 - 66 -- | CSS property: border-top - 67 borderTop :: Text -> CSS (Either Property Rule) - 68 borderTop = prop "border-top" - 69 - 70 -- | CSS property: border-top-color - 71 borderTopColor :: Text -> CSS (Either Property Rule) - 72 borderTopColor = prop "border-top-color" - 73 - 74 -- | CSS property: border-top-style - 75 borderTopStyle :: Text -> CSS (Either Property Rule) - 76 borderTopStyle = prop "border-top-style" - 77 - 78 -- | CSS property: border-top-width - 79 borderTopWidth :: Text -> CSS (Either Property Rule) - 80 borderTopWidth = prop "border-top-width" - 81 - 82 -- | CSS property: border-width - 83 borderWidth :: Text -> CSS (Either Property Rule) - 84 borderWidth = prop "border-width" - 85 - 86 -- | CSS property: border - 87 border :: Text -> CSS (Either Property Rule) - 88 border = prop "border" - 89 - 90 -- | CSS property: bottom - 91 bottom :: Text -> CSS (Either Property Rule) - 92 bottom = prop "bottom" - 93 - 94 -- | CSS property: caption-side - 95 captionSide :: Text -> CSS (Either Property Rule) - 96 captionSide = prop "caption-side" - 97 - 98 -- | CSS property: clear - 99 clear :: Text -> CSS (Either Property Rule) - 100 clear = prop "clear" - 101 - 102 -- | CSS property: clip - 103 clip :: Text -> CSS (Either Property Rule) - 104 clip = prop "clip" - 105 - 106 -- | CSS property: color - 107 color :: Text -> CSS (Either Property Rule) - 108 color = prop "color" - 109 - 110 -- | CSS property: content - 111 content :: Text -> CSS (Either Property Rule) - 112 content = prop "content" - 113 - 114 -- | CSS property: counter-increment - 115 counterIncrement :: Text -> CSS (Either Property Rule) - 116 counterIncrement = prop "counter-increment" - 117 - 118 -- | CSS property: counter-reset - 119 counterReset :: Text -> CSS (Either Property Rule) - 120 counterReset = prop "counter-reset" - 121 - 122 -- | CSS property: cue-after - 123 cueAfter :: Text -> CSS (Either Property Rule) - 124 cueAfter = prop "cue-after" - 125 - 126 -- | CSS property: cue-before - 127 cueBefore :: Text -> CSS (Either Property Rule) - 128 cueBefore = prop "cue-before" - 129 - 130 -- | CSS property: cue - 131 cue :: Text -> CSS (Either Property Rule) - 132 cue = prop "cue" - 133 - 134 -- | CSS property: cursor - 135 cursor :: Text -> CSS (Either Property Rule) - 136 cursor = prop "cursor" - 137 - 138 -- | CSS property: direction - 139 direction :: Text -> CSS (Either Property Rule) - 140 direction = prop "direction" - 141 - 142 -- | CSS property: display - 143 display :: Text -> CSS (Either Property Rule) - 144 display = prop "display" - 145 - 146 -- | CSS property: elevation - 147 elevation :: Text -> CSS (Either Property Rule) - 148 elevation = prop "elevation" - 149 - 150 -- | CSS property: empty-cells - 151 emptyCells :: Text -> CSS (Either Property Rule) - 152 emptyCells = prop "empty-cells" - 153 - 154 -- | CSS property: float - 155 float :: Text -> CSS (Either Property Rule) - 156 float = prop "float" - 157 - 158 -- | CSS property: font-family - 159 fontFamily :: Text -> CSS (Either Property Rule) - 160 fontFamily = prop "font-family" - 161 - 162 -- | CSS property: font-size - 163 fontSize :: Text -> CSS (Either Property Rule) - 164 fontSize = prop "font-size" - 165 - 166 -- | CSS property: font-style - 167 fontStyle :: Text -> CSS (Either Property Rule) - 168 fontStyle = prop "font-style" - 169 - 170 -- | CSS property: font-variant - 171 fontVariant :: Text -> CSS (Either Property Rule) - 172 fontVariant = prop "font-variant" - 173 - 174 -- | CSS property: font-weight - 175 fontWeight :: Text -> CSS (Either Property Rule) - 176 fontWeight = prop "font-weight" - 177 - 178 -- | CSS property: font - 179 font :: Text -> CSS (Either Property Rule) - 180 font = prop "font" - 181 - 182 -- | CSS property: height - 183 height :: Text -> CSS (Either Property Rule) - 184 height = prop "height" - 185 - 186 -- | CSS property: left - 187 left :: Text -> CSS (Either Property Rule) - 188 left = prop "left" - 189 - 190 -- | CSS property: letter-spacing - 191 letterSpacing :: Text -> CSS (Either Property Rule) - 192 letterSpacing = prop "letter-spacing" - 193 - 194 -- | CSS property: line-height - 195 lineHeight :: Text -> CSS (Either Property Rule) - 196 lineHeight = prop "line-height" - 197 - 198 -- | CSS property: list-style-image - 199 listStyleImage :: Text -> CSS (Either Property Rule) - 200 listStyleImage = prop "list-style-image" - 201 - 202 -- | CSS property: list-style-position - 203 listStylePosition :: Text -> CSS (Either Property Rule) - 204 listStylePosition = prop "list-style-position" - 205 - 206 -- | CSS property: list-style-type - 207 listStyleType :: Text -> CSS (Either Property Rule) - 208 listStyleType = prop "list-style-type" - 209 - 210 -- | CSS property: list-style - 211 listStyle :: Text -> CSS (Either Property Rule) - 212 listStyle = prop "list-style" - 213 - 214 -- | CSS property: margin-right - 215 marginRight :: Text -> CSS (Either Property Rule) - 216 marginRight = prop "margin-right" - 217 - 218 -- | CSS property: margin-top - 219 marginTop :: Text -> CSS (Either Property Rule) - 220 marginTop = prop "margin-top" - 221 - 222 -- | CSS property: margin - 223 margin :: Text -> CSS (Either Property Rule) - 224 margin = prop "margin" - 225 - 226 -- | CSS property: max-height - 227 maxHeight :: Text -> CSS (Either Property Rule) - 228 maxHeight = prop "max-height" - 229 - 230 -- | CSS property: max-width - 231 maxWidth :: Text -> CSS (Either Property Rule) - 232 maxWidth = prop "max-width" - 233 - 234 -- | CSS property: min-height - 235 minHeight :: Text -> CSS (Either Property Rule) - 236 minHeight = prop "min-height" - 237 - 238 -- | CSS property: min-width - 239 minWidth :: Text -> CSS (Either Property Rule) - 240 minWidth = prop "min-width" - 241 - 242 -- | CSS property: orphans - 243 orphans :: Text -> CSS (Either Property Rule) - 244 orphans = prop "orphans" - 245 - 246 -- | CSS property: outline-color - 247 outlineColor :: Text -> CSS (Either Property Rule) - 248 outlineColor = prop "outline-color" - 249 - 250 -- | CSS property: outline-style - 251 outlineStyle :: Text -> CSS (Either Property Rule) - 252 outlineStyle = prop "outline-style" - 253 - 254 -- | CSS property: outline-width - 255 outlineWidth :: Text -> CSS (Either Property Rule) - 256 outlineWidth = prop "outline-width" - 257 - 258 -- | CSS property: outline - 259 outline :: Text -> CSS (Either Property Rule) - 260 outline = prop "outline" - 261 - 262 -- | CSS property: overflow - 263 overflow :: Text -> CSS (Either Property Rule) - 264 overflow = prop "overflow" - 265 - 266 -- | CSS property: padding-top - 267 paddingTop :: Text -> CSS (Either Property Rule) - 268 paddingTop = prop "padding-top" - 269 - 270 -- | CSS property: padding - 271 padding :: Text -> CSS (Either Property Rule) - 272 padding = prop "padding" - 273 - 274 -- | CSS property: page-break-after - 275 pageBreakAfter :: Text -> CSS (Either Property Rule) - 276 pageBreakAfter = prop "page-break-after" - 277 - 278 -- | CSS property: page-break-before - 279 pageBreakBefore :: Text -> CSS (Either Property Rule) - 280 pageBreakBefore = prop "page-break-before" - 281 - 282 -- | CSS property: page-break-inside - 283 pageBreakInside :: Text -> CSS (Either Property Rule) - 284 pageBreakInside = prop "page-break-inside" - 285 - 286 -- | CSS property: pause-after - 287 pauseAfter :: Text -> CSS (Either Property Rule) - 288 pauseAfter = prop "pause-after" - 289 - 290 -- | CSS property: pause-before - 291 pauseBefore :: Text -> CSS (Either Property Rule) - 292 pauseBefore = prop "pause-before" - 293 - 294 -- | CSS property: pause - 295 pause :: Text -> CSS (Either Property Rule) - 296 pause = prop "pause" - 297 - 298 -- | CSS property: pitch-range - 299 pitchRange :: Text -> CSS (Either Property Rule) - 300 pitchRange = prop "pitch-range" - 301 - 302 -- | CSS property: pitch - 303 pitch :: Text -> CSS (Either Property Rule) - 304 pitch = prop "pitch" - 305 - 306 -- | CSS property: play-during - 307 playDuring :: Text -> CSS (Either Property Rule) - 308 playDuring = prop "play-during" - 309 - 310 -- | CSS property: position - 311 position :: Text -> CSS (Either Property Rule) - 312 position = prop "position" - 313 - 314 -- | CSS property: quotes - 315 quotes :: Text -> CSS (Either Property Rule) - 316 quotes = prop "quotes" - 317 - 318 -- | CSS property: richness - 319 richness :: Text -> CSS (Either Property Rule) - 320 richness = prop "richness" - 321 - 322 -- | CSS property: right - 323 right :: Text -> CSS (Either Property Rule) - 324 right = prop "right" - 325 - 326 -- | CSS property: speak-header - 327 speakHeader :: Text -> CSS (Either Property Rule) - 328 speakHeader = prop "speak-header" - 329 - 330 -- | CSS property: speak-numeral - 331 speakNumeral :: Text -> CSS (Either Property Rule) - 332 speakNumeral = prop "speak-numeral" - 333 - 334 -- | CSS property: speak-punctuation - 335 speakPunctuation :: Text -> CSS (Either Property Rule) - 336 speakPunctuation = prop "speak-punctuation" - 337 - 338 -- | CSS property: speak - 339 speak :: Text -> CSS (Either Property Rule) - 340 speak = prop "speak" - 341 - 342 -- | CSS property: speech-rate - 343 speechRate :: Text -> CSS (Either Property Rule) - 344 speechRate = prop "speech-rate" - 345 - 346 -- | CSS property: stress - 347 stress :: Text -> CSS (Either Property Rule) - 348 stress = prop "stress" - 349 - 350 -- | CSS property: table-layout - 351 tableLayout :: Text -> CSS (Either Property Rule) - 352 tableLayout = prop "table-layout" - 353 - 354 -- | CSS property: text-align - 355 textAlign :: Text -> CSS (Either Property Rule) - 356 textAlign = prop "text-align" - 357 - 358 -- | CSS property: text-decoration - 359 textDecoration :: Text -> CSS (Either Property Rule) - 360 textDecoration = prop "text-decoration" - 361 - 362 -- | CSS property: text-indent - 363 textIndent :: Text -> CSS (Either Property Rule) - 364 textIndent = prop "text-indent" - 365 - 366 -- | CSS property: text-transform - 367 textTransform :: Text -> CSS (Either Property Rule) - 368 textTransform = prop "text-transform" - 369 - 370 -- | CSS property: top - 371 top :: Text -> CSS (Either Property Rule) - 372 top = prop "top" - 373 - 374 -- | CSS property: unicode-bidi - 375 unicodeBidi :: Text -> CSS (Either Property Rule) - 376 unicodeBidi = prop "unicode-bidi" - 377 - 378 -- | CSS property: vertical-align - 379 verticalAlign :: Text -> CSS (Either Property Rule) - 380 verticalAlign = prop "vertical-align" - 381 - 382 -- | CSS property: visibility - 383 visibility :: Text -> CSS (Either Property Rule) - 384 visibility = prop "visibility" - 385 - 386 -- | CSS property: voice-family - 387 voiceFamily :: Text -> CSS (Either Property Rule) - 388 voiceFamily = prop "voice-family" - 389 - 390 -- | CSS property: volume - 391 volume :: Text -> CSS (Either Property Rule) - 392 volume = prop "volume" - 393 - 394 -- | CSS property: white-space - 395 whiteSpace :: Text -> CSS (Either Property Rule) - 396 whiteSpace = prop "white-space" - 397 - 398 -- | CSS property: widows - 399 widows :: Text -> CSS (Either Property Rule) - 400 widows = prop "widows" - 401 - 402 -- | CSS property: width - 403 width :: Text -> CSS (Either Property Rule) - 404 width = prop "width" - 405 - 406 -- | CSS property: word-spacing - 407 wordSpacing :: Text -> CSS (Either Property Rule) - 408 wordSpacing = prop "word-spacing" - 409 - 410 -- | CSS property: z-index - 411 zIndex :: Text -> CSS (Either Property Rule) - 412 zIndex = prop "z-index" Remove file src/Text/CSS/Types.hs 33188
- 1 {-# OPTIONS -Wall #-} - 2 {-# LANGUAGE GeneralizedNewtypeDeriving #-} - 3 -- | CSS generation. - 4 - 5 module Text.CSS.Types where - 6 - 7 import Control.Applicative (Applicative) - 8 import Control.Monad.Writer (Writer,MonadWriter) - 9 import Data.Text.Lazy (Text) - 10 - 11 -- | The CSS writer. - 12 newtype CSSM x a = CSSM { unCSS :: Writer [x] a } - 13 deriving (Functor,Applicative,Monad,MonadWriter [x]) - 14 - 15 type CSS x = CSSM x () - 16 - 17 -- | A CSS rule. - 18 data Rule = Rule { ruleExpr :: Text - 19 , ruleProperties :: [Property] - 20 , ruleRules :: [Rule] - 21 } - 22 deriving Show - 23 - 24 -- | A CSS property. - 25 data Property = Property { propertyName :: Text - 26 , propertyValue :: Text - 27 } - 28 deriving Show Edit file src/Amelie/View/Style.hs 33188 → 33188
8 8 where
9 9 10 10 import Data.Monoid.Operator ((++))
11 11 import Data.Text.Lazy (Text)
12 12 import Prelude hiding ((++))
- 13 import Text.CSS
+ 13 import Language.CSS
14 14 15 15 -- | Side-wide style sheet.
16 16 style :: Text
17 17 style = renderCSS $ runCSS $ do
18 18 layout
… … … … Add file lib/css 40960
+ 1 /home/chris/Projects/me/css/