packages feed

clevercss 0.2 → 0.2.1

raw patch · 4 files changed

+37/−23 lines, 4 files

Files

CCMain.hs view
@@ -1,7 +1,10 @@ --------------------------------------------------------------------------------------------- CleverCSS in Haskell, (c) 2007, 2008 Georg Brandl. Licensed under the BSD license.+-- |+-- Module      :  CCMain+-- Copyright   :  (c) 2007-2010 Georg Brandl+-- License     :  BSD (see the file LICENSE) ----- CCMain module: command-line interface.+-- Command-line interface for CleverCSS. ------------------------------------------------------------------------------------------  module Main (main) where
Text/CSS/CleverCSS.hs view
@@ -1,10 +1,14 @@ --------------------------------------------------------------------------------------------- CleverCSS in Haskell, (c) 2007, 2008 Georg Brandl. Licensed under the BSD license.------ Text.CSS.CleverCSS module: main parsing and evaluation.+-- |+-- Module      :  Text.CSS.CleverCSS+-- Copyright   :  (c) 2007-2010 Georg Brandl+-- License     :  BSD (see the file LICENSE) ----- TODO: properly parse selectors before splitting them+-- Main parsing and evaluation module for CleverCSS. ------------------------------------------------------------------------------------------++-- TODO: properly parse selectors before splitting them+ {-# LANGUAGE PatternGuards, TypeSynonymInstances, CPP #-}  module Text.CSS.CleverCSS (cleverCSSConvert) where@@ -14,7 +18,6 @@ import Control.Monad.RWS import Data.Char (toUpper, toLower) import Data.List (findIndex)-import Data.Ratio import Data.Sequence (Seq, singleton) import Text.Printf (printf) import Text.ParserCombinators.Parsec hiding (newline)@@ -60,7 +63,7 @@           | ExprList [Expr]                          -- x, y, z           | Subseq [Expr]                            -- x y z           | Call Expr !String (Maybe Expr)           -- x.y([z])-          | Var !String                              -- $x+          | Var !String                              -- \$x           | Bare !String                             -- x           | String !String                           -- "x"           | CSSFunc !String Expr                     -- url(x)@@ -109,8 +112,8 @@   show (ExprList l)        = joinShow ", " l   show (Subseq l)          = joinShow " " l   show (String s)          = cssShow s-  show (Number n)          = showRational n-  show (Dim (n, u))        = showRational n ++ u+  show (Number n)          = showRat n+  show (Dim (n, u))        = showRat n ++ u   show (CSSFunc name args) = name ++ "(" ++ show args ++ ")"   show (Color (Left n))    = n   show (Color (Right (r,g,b))) = case Map.lookup (r,g,b) reverse_colors of@@ -118,12 +121,6 @@                                    Nothing -> printf "#%02x%02x%02x" r g b   show (Bare s)            = s -showRational r | rest == 0 = show whole-               | otherwise = show (fromRational r)-  where d = denominator r-        n = numerator r-        (whole, rest) = n `divMod` d- ------------------------------------------------------------------------------------------ -- the tokenizer and parser @@ -553,6 +550,7 @@ findError2 cons xs = head $ [Error e | Error e <- xs] ++ [cons xs]  -- evaluate a string+evalString :: Dict Expr -> SourceName -> String -> Expr evalString varmap source string = case runParser exprseq [] "" string of   Left err  -> Error $ showWithoutPos ("in " ++ source ++ ":") err   Right []  -> String ""@@ -581,7 +579,13 @@   formatProp (Property _ _ _) = error "property has not exactly one value"   formatProp _ = error "remaining subitems in block" -cleverCSSConvert :: SourceName -> String -> [(String, String)] -> IO (Either String String)+-- | Convert CleverCSS source to CSS.+--   For documentation of available syntax and command line use, see+--   <http://sandbox.pocoo.org/clevercss-hs/>.+cleverCSSConvert :: SourceName                 -- ^ source (file) name+                 -> String                     -- ^ CleverCSS input+                 -> [(String, String)]         -- ^ initial variable assignments+                 -> IO (Either String String)  -- ^ CSS output cleverCSSConvert name input initial_map =   case runParser parser [0] name (preprocess input) of       Left err    -> return . Left $ "Parse error " ++ show err
Text/CSS/CleverCSSUtil.hs view
@@ -1,7 +1,10 @@---------------------------------------------------------------------------------------------- CleverCSS in Haskell, (c) 2007, 2008 Georg Brandl. Licensed under the BSD license.+-----------------------------------------------------------------------------------------+-- |+-- Module      :  Text.CSS.CleverCSSUtil+-- Copyright   :  (c) 2007-2010 Georg Brandl+-- License     :  BSD (see the file LICENSE) ----- Text.CSS.CleverCSSUtil module: utilities.+-- CleverCSS utilities. ------------------------------------------------------------------------------------------  module Text.CSS.CleverCSSUtil (@@ -11,12 +14,11 @@              unitconv, inrange, readNum, readDim,              trim, ltrim, rtrim, split, joinStr, joinShow,              preprocess, hexToString, cssShow, showWithoutPos,-             ratMod, roundRat,+             ratMod, roundRat, showRat             ) where  import Control.Arrow ((&&&)) import Control.Monad (msum)-import Data.Char import Data.List hiding (partition) import Data.Ratio ((%), numerator, denominator) import Numeric (readFloat)@@ -344,3 +346,8 @@ roundRat num places =     let exp = round places :: Integer in     (round (num * (10^exp))) % (10^exp) -- XXX todo++showRat :: Rational -> String+showRat r | rest == 0 = show whole+          | otherwise = printf "%f" (fromRational r :: Double)+  where (whole, rest) = (denominator r) `divMod` (numerator r)
clevercss.cabal view
@@ -1,6 +1,6 @@ cabal-version: >=1.2 Name: clevercss-Version: 0.2+Version: 0.2.1 Category: Text Synopsis: A CSS preprocessor Description: CleverCSS is a CSS preprocessing library that allows defining variables and nesting selectors so that you don't need to Repeat Yourself.