Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
servant-xml-conduit
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
servant-xml-conduit
Commits
27d6c2f8
Verified
Commit
27d6c2f8
authored
Nov 23, 2023
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[0.1.0.3] no overlapping instances, mimeUnrenderXML
parent
2561631f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
7 deletions
+66
-7
CHANGELOG.md
CHANGELOG.md
+13
-0
cabal.project
cabal.project
+6
-0
servant-xml-conduit.cabal
servant-xml-conduit.cabal
+9
-2
Conduit.hs
src/Servant/XML/Conduit.hs
+38
-5
No files found.
CHANGELOG.md
View file @
27d6c2f8
# Revision history for servant-xml-conduit
## [0.1.0.3] - 2023-11-23
### Fixed
-
documentation generation (add
`cabal.project`
with
`allow-newer`
for
`base`
)
-
fix overlapping instances
## [0.1.0.2] - 2023-11-23
### Added
-
`.cabal`
: added homepage, bug-reports, source-repository
## [0.1.0.1] - 2023-11 23
### Fixed
...
...
cabal.project
0 → 100644
View file @
27d6c2f8
with-compiler: ghc-8.10.7
allow-newer: base
packages:
./
servant-xml-conduit.cabal
View file @
27d6c2f8
...
...
@@ -20,14 +20,14 @@ name: servant-xml-conduit
-- PVP summary: +-+------- breaking API changes
-- | | +----- non-breaking API additions
-- | | | +--- code changes with no API change
version: 0.1.0.
1
version: 0.1.0.
3
-- A short (one-line) description of the package.
synopsis: Servant XML content-type with support for xml-conduit
-- A longer description of the package.
description: This is similar in spirit to `servant-xml` but uses `xml-conduit` instead of `xmlbf`.
-- The license under which the package is released.
license: AGPL-3.0-or-later
...
...
@@ -40,6 +40,9 @@ author: Gargantext
-- An email address to which users can send suggestions, bug reports, and patches.
maintainer: pk@intrepidus.pl
homepage: https://gitlab.iscpif.fr/gargantext/servant-xml-conduit
bug-reports: https://gitlab.iscpif.fr/gargantext/servant-xml-conduit/issues
-- A copyright notice.
-- copyright:
category: Web
...
...
@@ -51,6 +54,10 @@ extra-doc-files: CHANGELOG.md
-- Extra source files to be distributed with the package, such as examples, or a tutorial module.
-- extra-source-files:
source-repository head
type: git
location: https://gitlab.iscpif.fr/gargantext/servant-xml-conduit
common warnings
ghc-options: -Wall
...
...
src/Servant/XML/Conduit.hs
View file @
27d6c2f8
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-|
Module : Servant.XML.Conduit
Description : Servant bindings for XML using xml-conduit
...
...
@@ -14,6 +11,7 @@ Portability : POSIX
module
Servant.XML.Conduit
where
import
Data.Bifunctor
(
first
)
import
Data.ByteString.Lazy
qualified
as
BSL
import
Network.HTTP.Media
qualified
as
M
import
Servant.API
import
Text.XML
qualified
as
XML
...
...
@@ -24,7 +22,42 @@ data XML
instance
Accept
XML
where
contentType
_
=
"application"
M
.//
"xml"
M
./:
(
"charset"
,
"utf-8"
)
instance
{-# OVERLAPPING #-}
MimeUnrender
XML
XML
.
Document
where
mimeUnrender
_
bs
=
first
show
$
XML
.
parseLBS
XML
.
def
bs
instance
MimeRender
XML
XML
.
Document
where
mimeRender
_
doc
=
XML
.
renderLBS
XML
.
def
doc
{-| Function to decode a lazy `ByteString' into 'XML.Document'. The
reason we don't privde a @'MimeUnrender' 'XML' 'XML.Document'@ instance is
that we don't want to force users with a predefined 'FromXML'
typeclass.
If we added
@
instance 'MimeUnrender' 'XML' 'XML.Document' where
mimeUnrender _ bs = first show $ 'XML.parseLBS' 'XML.def' bs
@
we immediately arrive at overlapping instances problem when we try to define
@
instance FromXML a => 'MimeUnrender' 'XML' a ...
@
So, just define this in your code:
@
data ParseError =
ErrorNoElementFound Text
| ...
class FromXML a where
fromXML :: (Functor m, Applicative m, MonadError ParseError m) => 'Text.XML.Cursor.Cursor' -> m a
instance (FromXML a) => 'MimeUnrender' 'XML' a where
mimeUnrender _ctype bs = case 'mimeUnrenderXML' bs of
Left err -> Left err
Right doc -> first show $ fromXML ('Text.XML.Cursor.fromDocument' doc)
@
-}
mimeUnrenderXML
::
BSL
.
ByteString
->
Either
String
XML
.
Document
mimeUnrenderXML
bs
=
first
show
$
XML
.
parseLBS
XML
.
def
bs
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment