network-uri-static 0.1.0.0 → 0.1.1.0
raw patch · 3 files changed
+74/−11 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Network.URI.Static: instance Lift URI
- Network.URI.Static: instance Lift URIAuth
+ Network.URI.Static: instance Language.Haskell.TH.Syntax.Lift Network.URI.URI
+ Network.URI.Static: instance Language.Haskell.TH.Syntax.Lift Network.URI.URIAuth
+ Network.URI.Static: relativeReference :: QuasiQuoter
+ Network.URI.Static: staticRelativeReference :: String -> TExpQ URI
Files
- CHANGELOG.md +7/−0
- network-uri-static.cabal +3/−1
- src/Network/URI/Static.hs +64/−10
+ CHANGELOG.md view
@@ -0,0 +1,7 @@+# 0.1.1.0++* Added `relativeReference`.++# 0.1.0.0++First release.
network-uri-static.cabal view
@@ -1,5 +1,5 @@ name: network-uri-static-version: 0.1.0.0+version: 0.1.1.0 synopsis: A small utility to declare type-safe static URIs description: This library helps you declare type-safe static URIs by parsing URIs at compile time.@@ -23,6 +23,8 @@ copyright: 2015 Satoshi Nakamura category: Network build-type: Simple+extra-source-files:+ CHANGELOG.md cabal-version: >= 1.10 bug-reports: https://github.com/snakamura/network-uri-static/issues
src/Network/URI/Static.hs view
@@ -1,20 +1,29 @@ {-# LANGUAGE RecordWildCards, TemplateHaskell, ViewPatterns #-} module Network.URI.Static- ( staticURI- , uri+ (+ -- * Absolute URIs+ uri+ , staticURI+ -- * Relative URIs+ , relativeReference+ , staticRelativeReference ) where import Language.Haskell.TH (unType) import Language.Haskell.TH.Lib (TExpQ) import Language.Haskell.TH.Quote (QuasiQuoter(..)) import Language.Haskell.TH.Syntax (Lift(..))-import Network.URI (URI(..), URIAuth(..), parseURI)+import Network.URI (URI(..), URIAuth(..), parseURI, parseRelativeReference) -- $setup -- >>> :set -XTemplateHaskell -- >>> :set -XQuasiQuotes +----------------------------------------------------------------------------+-- Absolute URIs+----------------------------------------------------------------------------+ -- | 'staticURI' parses a specified string at compile time -- and return an expression representing the URI when it's a valid URI. -- Otherwise, it emits an error.@@ -32,12 +41,6 @@ staticURI (parseURI -> Just uri) = [|| uri ||] staticURI uri = fail $ "Invalid URI: " ++ uri -instance Lift URI where- lift (URI {..}) = [| URI {..} |]--instance Lift URIAuth where- lift (URIAuth {..}) = [| URIAuth {..} |]- -- | 'uri' is a quasi quoter for 'staticURI'. -- -- >>> [uri|http://www.google.com/|]@@ -45,7 +48,9 @@ -- -- >>> [uri|http://www.google.com/##|] -- <BLANKLINE>--- <interactive>... Invalid URI: http://www.google.com/##+-- <interactive>...+-- ... Invalid URI: http://www.google.com/##+-- ... uri :: QuasiQuoter uri = QuasiQuoter { quoteExp = fmap unType . staticURI,@@ -53,3 +58,52 @@ quoteType = undefined, quoteDec = undefined }++----------------------------------------------------------------------------+-- Relative URIs+----------------------------------------------------------------------------++-- | 'staticRelativeReference' parses a specified string at compile time and+-- return an expression representing the URI when it's a valid relative+-- reference. Otherwise, it emits an error.+--+-- >>> $$(staticRelativeReference "/foo?bar=baz#quux")+-- /foo?bar=baz#quux+--+-- >>> $$(staticRelativeReference "http://www.google.com/")+-- <BLANKLINE>+-- <interactive>...+-- ... Invalid relative reference: http://www.google.com/+-- ...+staticRelativeReference :: String -- ^ String representation of a reference+ -> TExpQ URI -- ^ Refererence+staticRelativeReference (parseRelativeReference -> Just ref) = [|| ref ||]+staticRelativeReference ref = fail $ "Invalid relative reference: " ++ ref++-- | 'relativeReference' is a quasi quoter for 'staticRelativeReference'.+--+-- >>> [relativeReference|/foo?bar=baz#quux|]+-- /foo?bar=baz#quux+--+-- >>> [relativeReference|http://www.google.com/|]+-- <BLANKLINE>+-- <interactive>...+-- ... Invalid relative reference: http://www.google.com/+-- ...+relativeReference :: QuasiQuoter+relativeReference = QuasiQuoter {+ quoteExp = fmap unType . staticRelativeReference,+ quotePat = undefined,+ quoteType = undefined,+ quoteDec = undefined+}++----------------------------------------------------------------------------+-- Instances and helpers+----------------------------------------------------------------------------++instance Lift URI where+ lift (URI {..}) = [| URI {..} |]++instance Lift URIAuth where+ lift (URIAuth {..}) = [| URIAuth {..} |]