Skip to content

Commit 5982ad6

Browse files
Merge pull request jeffreyrosenbluth#6 from jeffreyrosenbluth/new
Drop lucid dependency
2 parents 9f48e06 + 0adc65e commit 5982ad6

File tree

10 files changed

+1036
-1335
lines changed

10 files changed

+1036
-1335
lines changed

.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Example executables
2+
examples/Explode
3+
examples/LineStyles
4+
examples/Pentaflake
5+
examples/AttrTest
6+
examples/FillRule
7+
examples/Temp
8+
examples/Opacity
9+
examples/Clipping
10+
examples/Text
11+
examples/TextScaling
12+
examples/TextSize
13+
# This is just used as scratch space
14+
examples/Temp.hs
15+
16+
dist
17+
cabal-dev
18+
*.o
19+
*.hi
20+
*.chi
21+
*.chs.h
22+
.virthualenv
23+
*~
24+
.hsenv_*
25+
dist_*
26+
history
27+
TAGS
28+
.cabal-sandbox
29+
cabal.sandbox.config

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
lucid-svg [![Hackage](https://img.shields.io/hackage/v/lucid-svg.svg?style=flat)](https://hackage.haskell.org/package/lucid-svg)
22
=========
3-
Simple DSL for writing SVG, based on lucid
3+
Simple DSL for writing SVG, in the spirit of lucid.
44

55
## Example
66

77
``` haskell
88
{-# LANGUAGE OverloadedStrings #-}
99

1010
import Lucid.Svg
11-
12-
svg :: Svg () -> Svg ()
13-
svg content = do
14-
doctype_
15-
with (svg11_ content) [width_ "300" , height_ "200"]
1611

17-
contents :: Svg ()
18-
contents = do
19-
rect_ [width_ "100%", height_ "100%", fill_ "red"]
20-
circle_ [cx_ "150", cy_ "100", r_ "80", fill_ "green"]
21-
text_ [x_ "150", y_ "125", font_size_ "60", text_anchor_ "middle", fill_ "white"] "SVG"
12+
svg :: Element -> Element
13+
svg content =
14+
doctype
15+
<> with (svg11_ content) [Version_ <<- "1.1", Width_ <<- "300", Height_ <<- "200"]
2216

17+
contents :: Element
18+
contents =
19+
rect_ [ Width_ <<- "100%", Height_ <<- "100%", "red" ->> Fill_]
20+
<> circle_ [ Cx_ <<- "150", Cy_ <<- "100", R_ <<- "80", Fill_ <<- "green"]
21+
<> text_ [ X_ <<- "150", Y_ <<- "125", Font_size_ <<- "60"
22+
, Text_anchor_ <<- "middle", Fill_ <<- "white"] "SVG"
2323

2424
main :: IO ()
2525
main = do

examples/path.hs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
import Lucid.Svg
44
import Data.Monoid
5+
import Data.Text.Lazy as T
56

6-
svg :: Svg () -> Svg ()
7-
svg content = do
8-
doctype_
9-
with (svg11_ content) [width_ "325" , height_ "325"]
7+
svg :: Element -> Element
8+
svg content =
9+
doctype
10+
<> with (svg11_ content) [Width_ <<- "325", Height_ <<- "325"]
1011

11-
contents :: Svg ()
12-
contents = do
13-
path_ (
14-
[ d_ (mA 10 80 <> qA 52.5 10 95 80 <> tA 180 80 <> z)
15-
, stroke_ "blue"
16-
, fill_ "orange"
17-
])
12+
contents :: Element
13+
contents =
14+
path_
15+
[ D_ <<- (mA 10 80 <> qA 52.5 10 95 80 <> tA 180 80 <> z)
16+
, Stroke_ <<- "blue"
17+
, Fill_ <<- "orange"
18+
]
1819

1920
main :: IO ()
2021
main = do

examples/simple.hs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
import Lucid.Svg
44

5-
svg :: Svg () -> Svg ()
6-
svg content = do
7-
doctype_
8-
with (svg11_ content) [version_ "1.1", width_ "300" , height_ "200"]
9-
10-
contents :: Svg ()
11-
contents = do
12-
rect_ [width_ "100%", height_ "100%", fill_ "red"]
13-
circle_ [cx_ "150", cy_ "100", r_ "80", fill_ "green"]
14-
text_ [x_ "150", y_ "125", font_size_ "60", text_anchor_ "middle", fill_ "white"] "SVG"
5+
svg :: Element -> Element
6+
svg content =
7+
doctype
8+
<> with (svg11_ content) [Version_ <<- "1.1", Width_ <<- "300", Height_ <<- "200"]
159

10+
contents :: Element
11+
contents =
12+
rect_ [ Width_ <<- "100%", Height_ <<- "100%", "red" ->> Fill_]
13+
<> circle_ [ Cx_ <<- "150", Cy_ <<- "100", R_ <<- "80", Fill_ <<- "green"]
14+
<> text_ [ X_ <<- "150", Y_ <<- "125", Font_size_ <<- "60"
15+
, Text_anchor_ <<- "middle", Fill_ <<- "white"] "SVG"
1616

1717
main :: IO ()
1818
main = do

lucid-svg.cabal

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: lucid-svg
2-
version: 0.6.0.0
3-
synopsis: DSL for SVG using lucid for HTML
4-
description: Easy to write SVG in the syle of lucid.
2+
version: 0.7.0.0
3+
synopsis: DSL for composing SVG.
4+
description: Easy to write SVG.
55
homepage: http://github.com/jeffreyrosenbluth/lucid-svg.git
66
license: BSD3
77
license-file: LICENSE
@@ -16,13 +16,15 @@ cabal-version: >=1.10
1616
library
1717
ghc-options: -Wall -rtsopts -O2
1818
exposed-modules: Lucid.Svg,
19+
Lucid.Svg.Core,
1920
Lucid.Svg.Path,
2021
Lucid.Svg.Elements,
2122
Lucid.Svg.Attributes
22-
build-depends: base >= 4.5 && < 4.10,
23-
blaze-builder >= 0.2 && < 0.5,
24-
transformers >= 0.2 && < 0.6,
25-
text >= 0.11 && < 1.3,
26-
lucid >= 2.9.2 && < 3.0
23+
build-depends: base >= 4.5 && < 4.10,
24+
blaze-builder >= 0.4 && < 0.5,
25+
bytestring >= 0.10 && < 0.11,
26+
hashable >= 1.1 && < 1.3,
27+
text >= 0.11 && < 1.3,
28+
unordered-containers >= 0.2 && < 0.2.7
2729
hs-source-dirs: src
2830
default-language: Haskell2010

src/Lucid/Svg.hs

Lines changed: 43 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -15,55 +15,33 @@
1515
module Lucid.Svg
1616
( -- * Intro
1717
-- $intro
18-
-- * Types
19-
Svg
20-
-- * Rendering
21-
, prettyText
2218
-- * Re-exports
19+
module Lucid.Svg.Core
2320
, module Lucid.Svg.Path
2421
, module Lucid.Svg.Elements
2522
, module Lucid.Svg.Attributes
26-
-- * From Lucid.Base
27-
, renderText
28-
, renderBS
29-
, renderTextT
30-
, renderBST
31-
, renderToFile
32-
-- ** Running
33-
-- $running
34-
, execHtmlT
35-
, evalHtmlT
36-
, runHtmlT
37-
-- ** Types
38-
, Attribute(..)
39-
-- ** Classes
40-
-- $overloaded
41-
, Term(..)
42-
, ToHtml(..)
43-
, With(..)
23+
, (<>)
24+
-- * Rendering
25+
, prettyText
4426
) where
4527

4628
import Data.Functor.Identity
4729
import Data.Int (Int64)
4830
import Data.Monoid
49-
import Data.Text.Lazy
5031
import Data.Text.Lazy as LT
5132
import Data.Text.Lazy.Builder as B
52-
import Lucid.Base
53-
import qualified Lucid.Svg.Attributes as A
54-
import Lucid.Svg.Attributes hiding (cursor_, filter_, path_, style_)
33+
import Lucid.Svg.Core
34+
import Lucid.Svg.Attributes
5535
import Lucid.Svg.Elements
5636
import Lucid.Svg.Path
5737

58-
type Svg = SvgT Identity
59-
60-
prettyText :: Svg a -> Text
38+
prettyText :: Element -> Text
6139
prettyText svg = B.toLazyText $ LT.foldr go mempty text Nothing (-1)
62-
where
40+
where
6341
text = renderText svg
64-
go c f Nothing n
42+
go c f Nothing n
6543
| c == '<' || c == '/' = f (Just c) n
66-
go c f (Just '<') n
44+
go c f (Just '<') n
6745
| c == '?' = "<?" <> f Nothing n
6846
| c == '!' = "<!" <> f Nothing n
6947
| c == '/' = "\n"
@@ -78,81 +56,63 @@ prettyText svg = B.toLazyText $ LT.foldr go mempty text Nothing (-1)
7856
go '>' f (Just _) n = "/>" <> f Nothing (n-1)
7957
go c f s n = s' <> B.singleton c <> f Nothing n
8058
where s' = maybe mempty B.singleton s
81-
59+
8260
-- $intro
8361
--
84-
-- SVG elements and attributes in Lucid-Svg are written with a postfix ‘@_@’.
62+
-- SVG elements in Lucid-Svg are written with a postfix ‘@_@’.
8563
-- Some examples:
8664
--
8765
-- 'path_', 'circle_', 'color_', 'scale_'
8866
--
89-
-- Note: If you're testing in the REPL you need to add a type annotation to
90-
-- indicate that you want SVG. In normal code your top-level
91-
-- declaration signatures handle that.
92-
--
93-
-- Plain text is written using the @OverloadedStrings@ and
94-
-- @ExtendedDefaultRules@ extensions, and is automatically escaped:
67+
-- Plain text is written using the @OverloadedStrings@
68+
-- extension, and is automatically escaped:
9569
--
96-
-- As in Lucid, elements nest by function application:
70+
-- As in Lucid, elements nest by function application (unlike Lucid, there
71+
-- is no Monad instance for 'Element's and an 'Attribute' list is always required):
9772
--
98-
-- >>> g_ (text_ "Hello SVG") :: Svg ()
73+
-- >>> g_ [] (text_ [] "Hello SVG")
9974
-- <g><text>Hello SVG</text></g>
10075
--
101-
-- and elements are juxtaposed via monoidal append or monadic sequencing:
76+
-- and elements are juxtaposed via monoidal append:
10277
--
103-
-- >>> text_ "Hello" <> text_ "SVG" :: Svg ()
78+
-- >>> text_ [] "Hello" <> text_ [] "SVG"
10479
-- <text>Hello</text><text>SVG</text>
10580
--
106-
-- >>> do text_ "Hello"; text_ "SVG" :: Svg ()
107-
-- <text>Hello</text><text>SVG</text>
81+
-- Attributes are set by providing an argument list. Each argument is set
82+
-- using the 'bindAttr' function or operators, '<<-' and '->>'.
10883
--
109-
-- Attributes are set by providing an argument list. In contrast to HTML
110-
-- many SVG elements have no content, only attributes.
111-
--
112-
-- >>> rect_ [width_ "100%", height_ "100%", fill_ "red"] :: Svg ()
84+
-- >>> rect_ [Width_ <<- "100%", Height_ <<- "100%", "red" ->> Fill_] nil
11385
-- <rect height="100%" width="100%" fill="red"></rect>
11486
--
115-
-- Attributes and elements that share the same name are not conflicting
116-
-- unless they appear on the list in the note below:
117-
--
118-
-- >>> mask_ [mask_ "attribute"] "element" :: Svg ()
119-
-- <mask mask="attribute">element</mask>
120-
--
121-
-- Note: The following element and attribute names overlap and cannot be
122-
-- handled polymorphically since doing so would create conflicting functional
123-
-- dependencies. The unqualifed name refers to the element.
124-
-- We qualify the attribute name as @A@. For example, 'path_' and 'A.path_'.
125-
--
126-
-- 'colorProfile_', 'cursor_', 'filter_', 'path_', and 'style_'
127-
--
12887
-- Path data can be constructed using the functions in 'Lucid.Svg.Path'
12988
-- and combined monoidally:
13089
--
13190
-- @
132-
-- path_ (
133-
-- [ d_ (mA 10 80 <> qA 52.5 10 95 80 <> tA 180 80 <> z)
134-
-- , stroke_ "blue"
135-
-- , fill_ "orange"
136-
-- ])
91+
-- path_
92+
-- [ D <<- (mA 10 80 <> qA 52.5 10 95 80 <> tA 180 80 <> z)
93+
-- , Stroke_ <<- "blue"
94+
-- , Fill_ <<- "orange"
95+
-- ]
13796
-- @
138-
-- > <path d="M 10,80 Q 52.5,10 95,80 T 180,80 Z" stroke="blue" fill="orange"></path>
97+
-- > <path d="M 10,80 Q 52.5,10 95,80 T 180,80 Z" stroke="blue" fill="orange"/>
13998
--
14099
-- __A slightly longer example__:
141-
--
100+
--
142101
-- > import Lucid.Svg
143-
-- >
144-
-- > svg :: Svg () -> Svg ()
145-
-- > svg content = do
146-
-- > doctype_
147-
-- > with (svg11_ content) [version_ "1.1", width_ "300" , height_ "200"]
148-
-- >
149-
-- > contents :: Svg ()
150-
-- > contents = do
151-
-- > rect_ [width_ "100%", height_ "100%", fill_ "red"]
152-
-- > circle_ [cx_ "150", cy_ "100", r_ "80", fill_ "green"]
153-
-- > text_ [x_ "150", y_ "125", fontSize_ "60", textAnchor_ "middle", fill_ "white"] "SVG"
154-
-- >
155-
-- >
102+
-- >
103+
-- > svg :: Element -> Element
104+
-- > svg content =
105+
-- > doctype
106+
-- > <> with (svg11_ content) [Version_ <<- "1.1", Width_ <<- "300" , Height_ <<- "200"]
107+
-- >
108+
-- > contents :: Element
109+
-- > contents =
110+
-- > rect_ [Width_ <<- "100%", Height_ <<- "100%", Fill_ <<- "red"]
111+
-- > <> circle_ [Cx_ <<- "150", Cy_ <<- "100", R_ <<- "80", Fill_ <<- "green"]
112+
-- > <> text_ [ X_ <<- "150", Y_ <<- "125", FontSize_ <<- "60"
113+
-- > , TextAnchor_ <<- "middle", Fill_ <<- "white" ] "SVG"
114+
-- >
115+
-- >
156116
-- > main :: IO ()
157117
-- > main = do
158118
-- > print $ svg contents

0 commit comments

Comments
 (0)