packages feed

ngx-export-tools-extra 0.2.1.0 → 0.2.2.0

raw patch · 3 files changed

+84/−15 lines, 3 filesdep +prettyprinterdep +trifectaPVP ok

version bump matches the API change (PVP)

Dependencies added: prettyprinter, trifecta

API changes (from Hackage documentation)

Files

Changelog.md view
@@ -1,3 +1,10 @@+### 0.2.2.0++- Added Cabal flag *EDE* to detect automatically if EDE module can be built.+- Added manual Cabal flag *ExperimentalEDE* to compile against patched *ede*+  package where package *ansi-wl-pprint* was replaced with *prettyprinter*.+- The EDE example was enhanced to show how to parse free JSON values.+ ### 0.2.1.0  - Improved treatment of quoted string values in *b64* and *uenc* EDE filters.
NgxExport/Tools/EDE.hs view
@@ -1,4 +1,4 @@-{-# LANGUAGE TemplateHaskell, OverloadedStrings #-}+{-# LANGUAGE CPP, TemplateHaskell, OverloadedStrings #-}  ----------------------------------------------------------------------------- -- |@@ -28,7 +28,11 @@  import           Text.EDE import           Text.EDE.Filters+#if EDE_USE_PRETTYPRINTER+import           Data.Text.Prettyprint.Doc (unAnnotate)+#else import           Text.PrettyPrint.ANSI.Leijen.Internal (plain)+#endif import qualified Data.HashMap.Strict as HM import           Data.HashMap.Strict (HashMap) import qualified Data.ByteString as B@@ -45,7 +49,6 @@ import           Network.HTTP.Types.URI (urlEncode) import           Control.Exception (Exception, throwIO) import           System.IO.Unsafe-import           System.IO (FilePath)  -- $renderingEDETemplates --@@ -61,16 +64,36 @@ -- -- ==== File /test_tools_extra_ede.hs/ -- @--- {-\# OPTIONS_GHC -Wno-unused-imports \#-}+-- {-\# LANGUAGE TemplateHaskell \#-} -- -- module TestToolsExtraEDE where ----- import NgxExport.Tools.EDE+-- import           NgxExport+-- import           NgxExport.Tools.EDE+--+-- import           Data.Char+-- import           Data.ByteString (ByteString)+-- import qualified Data.ByteString.Char8 as C8+-- import qualified Data.ByteString.Lazy as L+-- import qualified Network.HTTP.Types.URI as URI+-- import           Control.Arrow+--+-- renderEDETemplateFromFreeValue :: ByteString -> IO L.ByteString+-- __/renderEDETemplateFromFreeValue/__ = uncurry (flip renderEDETemplate) .+--     second (L.fromStrict . C8.tail) . C8.break (== \'|\')+--+-- 'ngxExportIOYY' \'renderEDETemplateFromFreeValue+--+-- urlDecode :: ByteString -> L.ByteString+-- __/urlDecode/__ = L.fromStrict . URI.urlDecode False+--+-- 'ngxExportYY' \'urlDecode -- @ ----- This file does not contain any significant declarations as soon as we do not--- require anything besides the two exporters. As soon as imported entities are--- not used, option /-Wno-unused-imports/ was added on the top of the file.+-- Besides the two exporters imported from the EDE module, two additional+-- exporters were defined here: /renderEDETemplateFromFreeValue/ and+-- /urlDecode/. We are going to use them for parsing JSON values from HTTP+-- cookies. -- -- ==== File /nginx.conf/ -- @@@ -119,6 +142,13 @@ --             echo_status 404; --             echo \"Unexpected input: $1\"; --         }+--+--         location \/cookie {+--             haskell_run __/urlDecode/__ $hs_cookie_user $cookie_user;+--             haskell_run __/renderEDETemplateFromFreeValue/__ $hs_user_from_cookie+--                     user|$hs_cookie_user;+--             rewrite ^ \/internal\/user\/$hs_user_from_cookie last;+--         } --     } -- } -- @@@ -170,6 +200,11 @@ -- -- Now the variable will always be empty on errors, while the errors will still -- be logged by Nginx in the error log.+--+-- Let's read user data encoded in HTTP cookie /user/.+--+-- > $ curl -b 'user=%7B%22user%22%3A%20%7B%22id%22%20%3A%20%22user1%22%2C%20%22ops%22%3A%20%5B%22op1%22%2C%20%22op2%22%5D%7D%2C%20%22resources%22%3A%20%7B%22path%22%3A%20%22%2Fopt%2Fusers%22%7D%7D' 'http://localhost:8010/cookie'+-- > User id: user1, options: WyJvcDEiLCJvcDIiXQ==, path: %2Fopt%2Fusers  type InputTemplates = (FilePath, [(ByteString, ByteString)]) type Templates = HashMap B.ByteString (Result Template)@@ -203,7 +238,7 @@           applyToValue f (String t) = f $ T.encodeUtf8 t           applyToValue f v = f $ L.toStrict $ encode v --- | Render an EDE template from a JSON object.+-- | Renders an EDE template from a JSON object. -- -- This is the core function of the /renderEDETemplate/ exporter. Accepts a -- JSON object written in a 'L.ByteString' and a key to find a compiled EDE@@ -213,7 +248,7 @@                   -> IO L.ByteString renderEDETemplate = renderEDETemplateWith decode --- | Render an EDE template with a custom decoding function.+-- | Renders an EDE template with a custom decoding function. -- -- This function can be used for templating from any configuration language -- which is translatable to Aeson's 'Value'.@@ -236,7 +271,12 @@                     case renderWith filters tpl obj of                         Failure msg -> throwIO $ EDERenderError $ showPlain msg                         Success r -> return $ LT.encodeUtf8 r-    where showPlain = show . plain+    where showPlain = show .+#if EDE_USE_PRETTYPRINTER+              unAnnotate+#else+              plain+#endif  ngxExportAsyncOnReqBody 'renderEDETemplate 
ngx-export-tools-extra.cabal view
@@ -1,9 +1,9 @@ name:                       ngx-export-tools-extra-version:                    0.2.1.0+version:                    0.2.2.0 synopsis:                   More extra tools for Nginx haskell module description:                More extra tools for-        <http://github.com/lyokha/nginx-haskell-module Nginx haskell module>.-homepage:                   http://github.com/lyokha/ngx-export-tools-extra+        <https://github.com/lyokha/nginx-haskell-module Nginx haskell module>.+homepage:                   https://github.com/lyokha/ngx-export-tools-extra license:                    BSD3 license-file:               LICENSE extra-source-files:         Changelog.md@@ -15,6 +15,19 @@ build-type:                 Simple cabal-version:              >= 1.8 +source-repository head+    Type: git+    Location: https://github.com/lyokha/ngx-export-tools-extra++flag EDE+  description:              Build EDE module.++flag ExperimentalEDE+  description:              Build EDE module migrated from @ansi-wl-pprint@ to+                            @prettyprinter@.+  default:                  False+  manual:                   True+ library   build-depends:            base >= 4.8 && < 5                           , template-haskell >= 2.11.0.0@@ -30,10 +43,19 @@                           , enclosed-exceptions                           , snap-core                           , snap-server-                          , ede-                          , ansi-wl-pprint                           , text                           , time++  if flag(EDE)+    if flag(ExperimentalEDE)+      build-depends:        ede+                          , prettyprinter+                          , trifecta >= 2.1+      cpp-options:         -DEDE_USE_PRETTYPRINTER+    else+      build-depends:        ede+                          , ansi-wl-pprint+                          , trifecta <= 2    exposed-modules:          NgxExport.Tools.Aggregate                             NgxExport.Tools.EDE