css-text (empty) → 0.0.0
raw patch · 5 files changed
+150/−0 lines, 5 filesdep +HUnitdep +attoparsec-textdep +basesetup-changed
Dependencies added: HUnit, attoparsec-text, base, hspec, text
Files
- LICENSE +25/−0
- Setup.lhs +7/−0
- Text/CSS/Parse.hs +57/−0
- Text/CSS/Render.hs +28/−0
- css-text.cabal +33/−0
+ LICENSE view
@@ -0,0 +1,25 @@+The following license covers this documentation, and the source code, except+where otherwise indicated.++Copyright 2010, Michael Snoyman. All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++* Redistributions of source code must retain the above copyright notice, this+ list of conditions and the following disclaimer.++* Redistributions in binary form must reproduce the above copyright notice,+ this list of conditions and the following disclaimer in the documentation+ and/or other materials provided with the distribution.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO+EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.lhs view
@@ -0,0 +1,7 @@+#!/usr/bin/env runhaskell++> module Main where+> import Distribution.Simple++> main :: IO ()+> main = defaultMain
+ Text/CSS/Parse.hs view
@@ -0,0 +1,57 @@+{-# LANGUAGE OverloadedStrings #-}+module Text.CSS.Parse+ ( parseAttr+ , parseAttrs+ , parseBlock+ , parseBlocks+ ) where++import Prelude hiding (takeWhile)+import Data.Attoparsec.Text+import Data.Text (Text, strip)+import Data.Char (isSpace)+import Control.Applicative ((<|>))++skipWS :: Parser ()+skipWS = (string "/*" >> endComment >> skipWS)+ <|> (satisfy isSpace >> skipSpace >> skipWS)+ <|> return ()+ where+ endComment = do+ skipWhile (/= '*')+ (do+ _ <- char '*'+ (char '/' >> return ()) <|> endComment+ ) <|> fail "Missing end comment"++parseAttr :: Parser (Text, Text)+parseAttr = do+ skipWS+ key <- takeWhile1 (not . flip elem ":{}")+ _ <- char ':' <|> fail "Missing colon in attribute"+ value <- (takeWhile (not . flip elem ";}"))+ return (strip key, strip value)++parseAttrs :: Parser [(Text, Text)]+parseAttrs =+ go id+ where+ go front = (do+ a <- parseAttr+ (char ';' >> return ()) <|> return ()+ skipWS+ go $ front . (:) a+ ) <|> return (front [])++parseBlock :: Parser (Text, [(Text, Text)])+parseBlock = do+ skipWS+ sel <- takeWhile (/= '{')+ _ <- char '{'+ attrs <- parseAttrs+ skipWS+ _ <- char '}'+ return (strip sel, attrs)++parseBlocks :: Parser [(Text, [(Text, Text)])]+parseBlocks = many parseBlock
+ Text/CSS/Render.hs view
@@ -0,0 +1,28 @@+{-# LANGUAGE OverloadedStrings #-}+module Text.CSS.Render+ ( renderAttr+ , renderAttrs+ , renderBlock+ , renderBlocks+ ) where++import Data.Text (Text)+import Data.Text.Lazy.Builder (Builder, fromText, singleton)+import Data.Monoid (mappend, mempty, mconcat)++(<>) = mappend++renderAttr :: (Text, Text) -> Builder+renderAttr (k, v) = fromText k <> singleton ':' <> fromText v++renderAttrs :: [(Text, Text)] -> Builder+renderAttrs [] = mempty+renderAttrs [x] = renderAttr x+renderAttrs (x:xs) = renderAttr x <> singleton ';' <> renderAttrs xs++renderBlock :: (Text, [(Text, Text)]) -> Builder+renderBlock (sel, attrs) =+ fromText sel <> singleton '{' <> renderAttrs attrs <> singleton '}'++renderBlocks :: [(Text, [(Text, Text)])] -> Builder+renderBlocks = mconcat . map renderBlock
+ css-text.cabal view
@@ -0,0 +1,33 @@+name: css-text+version: 0.0.0+license: BSD3+license-file: LICENSE+author: Michael Snoyman <michael@snoyman.com>+maintainer: Michael Snoyman <michael@snoyman.com>+synopsis: CSS parser and renderer.+category: Web, Yesod+stability: Stable+cabal-version: >= 1.8+build-type: Simple+homepage: http://www.yesodweb.com/++library+ build-depends: base >= 4 && < 5+ , text >= 0.11 && < 0.12+ , attoparsec-text >= 0.8.5.1 && < 0.9+ exposed-modules: Text.CSS.Parse+ Text.CSS.Render+ ghc-options: -Wall++test-suite runtests+ type: exitcode-stdio-1.0+ main-is: runtests.hs+ build-depends: base >= 4 && < 5+ , text >= 0.11 && < 0.12+ , attoparsec-text >= 0.8.5.1 && < 0.9+ , HUnit >= 1.2 && < 1.3+ , hspec >= 0.6.1 && < 0.7++source-repository head+ type: git+ location: git://github.com/snoyberg/css-text.git