burrito 2.0.0.0 → 2.0.1.0
raw patch · 5 files changed
+42/−6 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Burrito: expandTH :: [(String, Value)] -> Template -> Q Exp
+ Burrito.Internal.TH: expandTH :: [(String, Value)] -> Template -> Q Exp
Files
- CHANGELOG.markdown +4/−0
- burrito.cabal +2/−2
- source/library/Burrito.hs +3/−2
- source/library/Burrito/Internal/Expand.hs +1/−1
- source/library/Burrito/Internal/TH.hs +32/−1
+ CHANGELOG.markdown view
@@ -0,0 +1,4 @@+# Change log++Burrito follows the [Package Versioning Policy](https://pvp.haskell.org).+You can find release notes [on GitHub](https://github.com/tfausak/burrito/releases).
burrito.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.2 name: burrito-version: 2.0.0.0+version: 2.0.1.0 synopsis: Parse and render URI templates. description:@@ -23,7 +23,7 @@ build-type: Simple category: Network-extra-source-files: README.markdown+extra-source-files: CHANGELOG.markdown README.markdown license-file: LICENSE.markdown license: MIT maintainer: Taylor Fausak
source/library/Burrito.hs view
@@ -2,8 +2,8 @@ -- -- According to [RFC 6570](https://tools.ietf.org/html/rfc6570): "A URI -- Template is a compact sequence of characters for describing a range of- -- Uniform Resource Identifiers through variable expansion." Burrito- -- implements URI templates according to the specification in that RFC.+-- Uniform Resource Identifiers through variable expansion." Burrito+-- implements URI templates according to the specification in that RFC. -- -- The term "uniform resource identifiers" (URI) is often used interchangeably -- with other related terms like "internationalized resource identifier" (IRI),@@ -33,6 +33,7 @@ , Expand.expandWith , Match.match , TH.uriTemplate+ , TH.expandTH , Template.Template , Value.Value , stringValue
source/library/Burrito/Internal/Expand.hs view
@@ -50,7 +50,7 @@ -- | This is like @expand@ except that it gives you more control over how -- variables are expanded. If you can, use @expand@. It's simpler. ----- Instead of passing in a static mapping form names to+-- Instead of passing in a static mapping from names to -- values, you pass in a function that is used to look up values on the fly. -- This can be useful if computing values takes a while or requires some impure -- actions.
source/library/Burrito/Internal/TH.hs view
@@ -1,10 +1,41 @@ module Burrito.Internal.TH- ( uriTemplate+ ( expandTH+ , uriTemplate ) where +import qualified Burrito.Internal.Expand as Expand import qualified Burrito.Internal.Parse as Parse+import qualified Burrito.Internal.Type.Template as Template+import qualified Burrito.Internal.Type.Value as Value+import qualified Data.Bifunctor as Bifunctor+import qualified Data.Map as Map+import qualified Data.Text as Text+import qualified Data.Text.Lazy as LazyText+import qualified Data.Text.Lazy.Builder as Builder import qualified Language.Haskell.TH.Quote as TH import qualified Language.Haskell.TH.Syntax as TH++-- | This can be used together with the @TemplateHaskell@ language extension to+-- expand a URI template at compile time. This is slightly different from+-- 'Expand.expand' in that missing variables will throw an exception. This is+-- convenient because it allows you to verify that all of the variables have+-- been supplied at compile time.+--+-- >>> :set -XQuasiQuotes -XTemplateHaskell+-- >>> import Burrito+-- >>> $( expandTH [("foo", stringValue "bar")] [uriTemplate|l-{foo}-r|] )+-- "l-bar-r"+expandTH :: [(String, Value.Value)] -> Template.Template -> TH.Q TH.Exp+expandTH xs t = do+ let+ m = Map.fromList $ fmap (Bifunctor.first Text.pack) xs+ f k =+ maybe (Left $ "missing variable: " <> show k) (Right . Just)+ $ Map.lookup k m+ x <-+ either fail (pure . LazyText.unpack . Builder.toLazyText)+ $ Expand.expandWith f t+ TH.lift x -- | This can be used together with the @QuasiQuotes@ language extension to -- parse a URI template at compile time. This is convenient because it allows