lucid-svg 0.3 → 0.4
raw patch · 3 files changed
+44/−14 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Lucid.Svg: prettyText :: Svg a -> Text
Files
- README.md +2/−2
- lucid-svg.cabal +6/−6
- src/Lucid/Svg.hs +36/−6
README.md view
@@ -16,9 +16,9 @@ contents :: Svg () contents = do- rect_ [width_ "100%", height_ "100%", fill_ "red"]+ rect_ [width_ "100%", height_ "100%", fill_ "red"] circle_ [cx_ "150", cy_ "100", r_ "80", fill_ "green"]- text_ [x_ "150", y_ "125", fontSize_ "60", textAnchor_ "middle", fill_ "white"] "SVG"+ text_ [x_ "150", y_ "125", font_size_ "60", text_anchor_ "middle", fill_ "white"] "SVG" main :: IO ()
lucid-svg.cabal view
@@ -1,5 +1,5 @@ name: lucid-svg-version: 0.3+version: 0.4 synopsis: DSL for SVG using lucid for HTML homepage: http://github.com/jeffreyrosenbluth/lucid-svg.git license: BSD3@@ -18,10 +18,10 @@ Lucid.Svg.Path, Lucid.Svg.Elements, Lucid.Svg.Attributes- build-depends: base >=4.7 && <4.8,- blaze-builder >= 0.3 && < 0.4,- transformers >= 0.4 && < 0.5,- text >= 1.2 && < 1.3,- lucid >=2.8.1 && < 2.9+ build-depends: base >= 4.7 && < 4.8,+ blaze-builder >= 0.3 && < 0.4,+ transformers >= 0.4 && < 0.5,+ text >= 1.2 && < 1.3,+ lucid >= 2.8.1 && < 2.9 hs-source-dirs: src default-language: Haskell2010
src/Lucid/Svg.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE OverloadedStrings #-}+ {-# OPTIONS -fno-warn-unused-imports #-} -------------------------------------------------------------------------------@@ -15,6 +17,8 @@ -- $intro -- * Types Svg+ -- * Rendering+ , prettyText -- * Re-exports , module Lucid.Svg.Path , module Lucid.Svg.Elements@@ -39,15 +43,41 @@ , With(..) ) where -import Data.Functor.Identity-import Lucid.Base-import qualified Lucid.Svg.Attributes as A-import Lucid.Svg.Attributes hiding (colorProfile_, cursor_, filter_, path_, style_)-import Lucid.Svg.Elements-import Lucid.Svg.Path+import Data.Functor.Identity+import Data.Int (Int64)+import Data.Monoid+import Data.Text.Lazy+import Data.Text.Lazy as LT+import Data.Text.Lazy.Builder as B+import Lucid.Base+import qualified Lucid.Svg.Attributes as A+import Lucid.Svg.Attributes hiding (colorProfile_, cursor_, filter_, path_, style_)+import Lucid.Svg.Elements+import Lucid.Svg.Path type Svg = SvgT Identity +prettyText :: Svg a -> Text+prettyText svg = B.toLazyText $ go (-1) text+ where+ text = renderText svg+ go :: Int64 -> Text -> B.Builder+ go n t+ | isPrefixOf "<?" t = "<?" <> go n (LT.drop 2 t)+ | isPrefixOf "<!" t = "<!" <> go n (LT.drop 2 t)+ | isPrefixOf "</" t = "\n" <> (B.fromLazyText $ LT.replicate n " ")+ <> "</"+ <> go (n - 1) (LT.drop 2 t)++ | isPrefixOf "<" t = "\n" <> (B.fromLazyText $ LT.replicate (n + 1) " ")+ <> B.singleton '<'+ <> go (n + 1) (LT.drop 1 t)++ | isPrefixOf "/>" t = "/>" <> go (n - 1) (LT.drop 2 t)++ | not . LT.null $ t = (B.singleton $ LT.head t) <> go n (LT.drop 1 t)+ | otherwise = mempty+ -- $intro -- -- SVG elements and attributes in Lucid-Svg are written with a postfix ‘@_@’.