atom-basic 0.0.1.1 → 0.2.0
raw patch · 3 files changed
+92/−10 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Web.Atom: unsafeURI :: String -> URI
Files
- CHANGELOG +9/−0
- atom-basic.cabal +16/−8
- src/Web/Atom.hs +67/−2
+ CHANGELOG view
@@ -0,0 +1,9 @@+- 0.2.0+ * Export unsafeURI convenience function.+ * Add usage examples.++- 0.1.1+ * Loosen constraint on base.++- 0.1.0+ * First release.
atom-basic.cabal view
@@ -1,22 +1,30 @@ name: atom-basic-version: 0.0.1.1+version: 0.2.0 synopsis: Basic Atom feed construction description: - This library provides a type for an Atom feed- (http://tools.ietf.org/html/rfc4287) and a way to produce its XML. XML is- constructed with the help of a record of construction functions (`XMLGen`)- that you provide. This allows you to easily use this with the XML library- of your choice.+ <https://hackage.haskell.org/package/atom-basic atom-basic> aims to provide+ a type-safe <http://tools.ietf.org/html/rfc4287> Atom feed for the XML+ package of your choice. Constructors for the 'Feed' and 'Entry' data types+ are provided. You pass values of these types to the 'feedXML' or 'entryXML'+ to generate XML. You provide an 'XMLGen' record of generator functions+ using your preferred XML package. license: BSD3 license-file: LICENSE-author: Carl Baatz-maintainer: carl.baatz@gmail.com+bug-reports: https://github.com/cbaatz/atom-basic/issues+maintainer: Carl Baatz <carl.baatz@gmail.com>+author: Carl Baatz <carl.baatz@gmail.com> copyright: (c) 2015 Carl Baatz category: Web build-type: Simple cabal-version: >=1.10+Extra-source-files:+ CHANGELOG++source-repository head+ type: git+ location: https://github.com/cbaatz/atom-basic flag network-uri description: Get Network.URI from the network-uri package
src/Web/Atom.hs view
@@ -1,3 +1,64 @@+-- | You use this package by specifying 'XMLGen' generator functions,+-- constructing a 'Feed', and then using the 'feedXML' function to generate the+-- XML.+--+-- For example, using the <http://hackage.haskell.org/package/xml xml>+-- package to generate our XML could look like this:+--+-- > {-# LANGUAGE OverloadedStrings #-}+-- >+-- > import qualified Data.Text as T+-- > import Data.Time (UTCTime (..), fromGregorian)+-- > import Text.XML.Light+-- > import qualified Web.Atom as Atom+-- >+-- > xmlgen :: Atom.XMLGen Element Content QName Attr+-- > xmlgen = Atom.XMLGen+-- > { Atom.xmlElem = \n as ns -> Element n as ns Nothing+-- > , Atom.xmlName = \nsMay name -> QName (T.unpack name)+-- > (fmap T.unpack nsMay) Nothing+-- > , Atom.xmlAttr = \k v -> Attr k (T.unpack v)+-- > , Atom.xmlTextNode = \t -> Text $ CData CDataText (T.unpack t) Nothing+-- > , Atom.xmlElemNode = Elem+-- > }+-- >+-- > feed :: Atom.Feed Element+-- > feed = Atom.makeFeed+-- > (Atom.unsafeURI "https://haskell.org/")+-- > (Atom.TextHTML "The <em>Title</em>")+-- > (UTCTime (fromGregorian 2015 7 8) 0)+-- >+-- > main = putStrLn $ showTopElement $ Atom.feedXML xmlgen feed+--+-- Or you might want to use the <http://hackage.haskell.org/package/xml-conduit xml-conduit> package:+--+-- > {-# LANGUAGE OverloadedStrings #-}+-- >+-- > import Data.Map.Lazy (fromList)+-- > import qualified Data.Text as T+-- > import qualified Data.Text.Lazy.IO as TL+-- > import Data.Time (UTCTime (..), fromGregorian)+-- > import Text.XML+-- > import qualified Web.Atom as Atom+-- >+-- > xmlgen :: Atom.XMLGen Element Node Name (Name, T.Text)+-- > xmlgen = Atom.XMLGen+-- > { Atom.xmlElem = \n as ns -> Element n (fromList as) ns+-- > , Atom.xmlName = \nsMay name -> Name name nsMay Nothing+-- > , Atom.xmlAttr = \k v -> (k, v)+-- > , Atom.xmlTextNode = NodeContent+-- > , Atom.xmlElemNode = NodeElement+-- > }+-- >+-- > feed :: Atom.Feed Element+-- > feed = Atom.makeFeed+-- > (Atom.unsafeURI "https://haskell.org/")+-- > (Atom.TextHTML "The <em>Title</em>")+-- > (UTCTime (fromGregorian 2015 7 8) 0)+-- >+-- > main = TL.putStrLn $ renderText def (Document (Prologue [] Nothing []) xml [])+-- > where xml = Atom.feedXML xmlgen feed+ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE OverloadedStrings #-}@@ -23,18 +84,19 @@ , LanguageTag(..) , MediaType(..) , UTCTime+ , unsafeURI , URI(..) ) where import Data.ByteString (ByteString) import qualified Data.ByteString.Base64 as B64 import qualified Data.ByteString.Char8 as BC-import Data.Maybe (catMaybes)+import Data.Maybe (catMaybes, fromJust) import Data.String (IsString (..)) import qualified Data.Text as T import qualified Data.Text.Encoding as T (decodeUtf8) import Data.Time (UTCTime, formatTime)-import Network.URI (URI (..))+import Network.URI (URI (..), parseURI) import System.Locale (defaultTimeLocale) -- ------------------------@@ -73,6 +135,9 @@ , entryCategories = [] , entryLinks = [] }++unsafeURI :: String -> URI+unsafeURI = fromJust . parseURI -- ------------------------- -- External XML construction