git.iko.soy/typeable/xml-conduit-writer
on master help sign in
3 files changed+54−71
since splitsnapshots
unifiedsplit
src/Text/XML/Writer.hs+47−6 stack.yaml+3−62 xml-conduit-writer.cabal+4−3
src/Text/XML/Writer.hs+47−6
@@ -1,4 +1,5 @@
1−{-# LANGUAGE OverloadedStrings, TypeSynonymInstances, FlexibleInstances #-}
1+{-# LANGUAGE OverloadedStrings, TypeSynonymInstances, FlexibleInstances, CPP #-}
2+{-# OPTIONS_GHC -fno-warn-orphans #-} -- IsString for XML
23
34-- | Overcome XML insanity, node by node.
45--
@@ -16,7 +17,11 @@
1617module Text.XML.Writer
1718 (
1819 -- * Documents
19− document, soap
20+ document
21+ , documentA
22+ , documentD
23+ , documentAD
24+ , soap
2025 , pprint
2126 -- * Elements
2227 , XML
@@ -36,15 +41,19 @@ module Text.XML.Writer
3641
3742import Text.XML
3843import Control.Monad.Writer.Strict
44+import Data.Default ()
3945import qualified Data.DList as DL
4046import qualified Data.Map as M
4147
42−import Data.Default ()
4348import Data.Text (Text)
4449import qualified Data.Text as T
4550import qualified Data.Text.Lazy.IO as TL
4651import Data.String (IsString(..))
4752
53+#if MIN_VERSION_mtl(2,3,0)
54+import Control.Monad
55+#endif
56+
4857-- | Node container to be rendered as children nodes.
4958type XML = Writer (DL.DList Node) ()
5059
@@ -57,6 +66,38 @@ document name children = Document { documentPrologue = Prologue def def def
5766 , documentEpilogue = def
5867 }
5968
69+
70+-- | Create a simple Document starting with a root element with attributes.
71+documentA :: Name -- ^ Root node name
72+ -> [(Name, Text)] -- ^ Attributes
73+ -> XML -- ^ Contents
74+ -> Document
75+documentA name attrs children = Document { documentPrologue = Prologue def def def
76+ , documentRoot = Element name (M.fromList attrs) (render children)
77+ , documentEpilogue = def
78+ }
79+
80+-- | Create a simple Document starting with a root element with a doctype.
81+documentD :: Name -- ^ Root node name
82+ -> Maybe Doctype -- ^ DOCTYPE
83+ -> XML -- ^ Contents
84+ -> Document
85+documentD name dt children = Document { documentPrologue = Prologue def dt def
86+ , documentRoot = Element name def (render children)
87+ , documentEpilogue = def
88+ }
89+
90+-- | Create a simple Document starting with a root element with attributes and doctype.
91+documentAD :: Name -- ^ Root node name
92+ -> [(Name, Text)] -- ^ Attributes
93+ -> Maybe Doctype -- ^ DOCTYPE
94+ -> XML -- ^ Contents
95+ -> Document
96+documentAD name attrs dt children = Document { documentPrologue = Prologue def dt def
97+ , documentRoot = Element name (M.fromList attrs) (render children)
98+ , documentEpilogue = def
99+ }
100+
60101-- | Render document using xml-conduit's pretty-printer.
61102pprint :: Document -> IO ()
62103pprint = TL.putStrLn . renderText def { rsPretty = True }
@@ -98,11 +139,11 @@ content :: Text -> XML
98139content = node . NodeContent
99140
100141-- | Mass-convert to nodes.
101−--
142+--
102143-- > let array = element "container" $ many "wrapper" [1..3]
103−--
144+--
104145-- Which gives:
105−--
146+--
106147-- > <container>
107148-- > <wrapper>1</wrapper>
108149-- > <wrapper>2</wrapper>
stack.yaml+3−62
@@ -1,66 +1,7 @@
1−# This file was automatically generated by 'stack init'
2−#
3−# Some commonly used options have been documented as comments in this file.
4−# For advanced use and comprehensive documentation of the format, please see:
5−# https://docs.haskellstack.org/en/stable/yaml_configuration/
1+resolver: lts-22.4
62
7−# Resolver to choose a 'specific' stackage snapshot or a compiler version.
8−# A snapshot resolver dictates the compiler version and the set of packages
9−# to be used for project dependencies. For example:
10−#
11−# resolver: lts-3.5
12−# resolver: nightly-2015-09-21
13−# resolver: ghc-7.10.2
14−# resolver: ghcjs-0.1.0_ghc-7.10.2
15−# resolver:
16−# name: custom-snapshot
17−# location: "./custom-snapshot.yaml"
18−resolver: lts-9.6
19−
20−# User packages to be built.
21−# Various formats can be used as shown in the example below.
22−#
23−# packages:
24−# - some-directory
25−# - https://example.com/foo/bar/baz-0.0.2.tar.gz
26−# - location:
27−# git: https://github.com/commercialhaskell/stack.git
28−# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
29−# - location: https://github.com/commercialhaskell/stack/commit/e7b331f14bcffb8367cd58fbfc8b40ec7642100a
30−# extra-dep: true
31−# subdirs:
32−# - auto-update
33−# - wai
34−#
35−# A package marked 'extra-dep: true' will only be built if demanded by a
36−# non-dependency (i.e. a user package), and its test suites and benchmarks
37−# will not be run. This is useful for tweaking upstream packages.
383packages:
394- .
40−# Dependency packages to be pulled from upstream that are not in the resolver
41−# (e.g., acme-missiles-0.3)
42−extra-deps: []
43−
44−# Override default flag values for local packages and extra-deps
45−flags: {}
46−
47−# Extra package databases containing global packages
48−extra-package-dbs: []
495
50−# Control whether we use the GHC we find on the path
51−# system-ghc: true
52−#
53−# Require a specific version of stack, using version ranges
54−# require-stack-version: -any # Default
55−# require-stack-version: ">=1.5"
56−#
57−# Override the architecture used by stack, especially useful on Windows
58−# arch: i386
59−# arch: x86_64
60−#
61−# Extra directories used by stack for building
62−# extra-include-dirs: [/path/to/dir]
63−# extra-lib-dirs: [/path/to/dir]
64−#
65−# Allow a newer minor version of GHC than the snapshot specifies
66−# compiler-check: newer-minor
6+nix:
7+ packages: [zlib]
xml-conduit-writer.cabal+4−3
@@ -1,5 +1,6 @@
1+cabal-version: 3.0
12name: xml-conduit-writer
2−version: 0.1.1.0
3+version: 0.1.1.3
34synopsis: Warm and fuzzy creation of XML documents.
45description:
56 “It can scarcely be denied that the supreme goal of
@@ -18,14 +19,13 @@ author: Alexander Bondarenko
1819maintainer: aenor.realm@gmail.com
1920category: Text
2021build-type: Simple
21−cabal-version: >=1.8
2222
2323source-repository head
2424 type: git
2525 location: https://bitbucket.org/dpwiz/xml-conduit-writer
2626
2727library
28− ghc-options: -Wall -O2
28+ default-language: Haskell2010
2929 hs-source-dirs: src
3030 exposed-modules:
3131 Text.XML.Writer
@@ -38,6 +38,7 @@ library
3838 data-default
3939
4040test-suite tests
41+ default-language: Haskell2010
4142 type: exitcode-stdio-1.0
4243 main-is: Main.hs
4344 hs-source-dirs: test/