packages feed

glabrous 2.0.6 → 2.0.6.1

raw patch · 3 files changed

+21/−27 lines, 3 filesdep ~aesonPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: aeson

API changes (from Hackage documentation)

- Text.Glabrous.Types: fromJSONString :: (Text, Value) -> (Text, Text)

Files

glabrous.cabal view
@@ -1,5 +1,5 @@ name:                glabrous-version:             2.0.6+version:             2.0.6.1 synopsis:            A template DSL library description:         A minimalistic, Mustache-like syntax, truly logic-less,                      pure Text template DSL library@@ -8,13 +8,13 @@ license-file:        LICENSE author:              Michel Boucey maintainer:          michel.boucey@gmail.com-copyright:           (c) 2016-2022 - Michel Boucey+copyright:           (c) 2016-2023 - Michel Boucey category:            Text, Web build-type:          Simple cabal-version:       >=1.10 extra-source-files:  README.md -Tested-With: GHC ==8.4.4 || ==8.6.5 || ==8.8.4 || ==8.10.7 || ==9.0.1 || ==9.2.1+Tested-With: GHC ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.8 || ==9.4.5 || ==9.6.2  source-repository head   type:     git@@ -25,7 +25,7 @@   exposed-modules:     Text.Glabrous                      , Text.Glabrous.Types   other-modules:       Text.Glabrous.Internal-  build-depends:       aeson >= 0.8.0.2 && < 1.6 || == 2.0.*+  build-depends:       aeson >= 2 && < 2.2                      , aeson-pretty >= 0.7.2 && < 0.9                      , attoparsec >= 0.12.1.6 && < 0.15                      , base >= 4.8.1.0 && < 5
src/Text/Glabrous.hs view
@@ -68,7 +68,7 @@ import           Data.Aeson.Encode.Pretty (encodePretty) import qualified Data.ByteString.Lazy     as L import qualified Data.HashMap.Strict      as H-import           Data.List                (intersperse,intersect,uncons)+import           Data.List                (intersect, intersperse, uncons) import qualified Data.Text                as T import qualified Data.Text.IO             as I @@ -241,7 +241,7 @@ -- | get 'Just' a new 'Template' by inserting a 'Template' -- into another one by replacing the 'Tag', or 'Nothing'. ----- >λ>insert t0 (Tag "template1") t1+-- >λ>insertTemplate t0 (Tag "template1") t1 insertTemplate :: Template       -- ^ The Template to insert in                -> Token          -- ^ The Tag to be replaced                -> Template       -- ^ The Template to be inserted@@ -260,7 +260,7 @@ -- | get 'Just' a new 'Template' by inserting many 'Template's, -- if there is at least one tag correspondence, or 'Nothing'. ----- >λ>insertMany t0 [(Tag "template1",t1),(Tag "template2",t2)]+-- >λ>insertManyTemplates t0 [(Tag "template1",t1),(Tag "template2",t2)] insertManyTemplates :: Template -> [(Token,Template)] -> Maybe Template insertManyTemplates te ttps = do   guard (tagsOf te `intersect` (fst <$> ttps) /= mempty)@@ -294,7 +294,7 @@   foldl trans T.empty content   where     trans o (Literal l) = o `T.append` l-    trans o (Tag _) = o+    trans o (Tag _)     = o  -- | Get the list of 'Tag's in the given 'Template'. tagsOf :: Template -> [Token]@@ -304,10 +304,7 @@ tagsRename ts Template{..} =   Template { content = rename <$> content }   where-    rename t@(Tag n) =-      case lookup n ts of-        Just r  -> Tag r-        Nothing -> t+    rename t@(Tag n)     = maybe t Tag (lookup n ts)     rename l@(Literal _) = l  -- | 'True' if a 'Template' has no more 'Tag'@@ -338,11 +335,8 @@     transTags ts Context{..} =       trans <$> ts       where-        trans i@(Tag k) =-          case H.lookup k variables of-            Just v  -> Literal v-            Nothing -> i-        trans t = t+        trans i@(Tag k) = maybe i Literal (H.lookup k variables)+        trans t         = t  -- | Process a (sub)'Context' present in the given template, and -- get either a 'Final' 'T.Text' or a new 'Template' with its unset
src/Text/Glabrous/Types.hs view
@@ -4,15 +4,15 @@  module Text.Glabrous.Types where +import           Control.Arrow       (second) import           Data.Aeson #if MIN_VERSION_aeson(2,0,0) import qualified Data.Aeson.KeyMap   as KM #endif import qualified Data.HashMap.Strict as H-import qualified Data.Text           as T import           Data.Serialize import           Data.Serialize.Text ()-import           Control.Arrow       (second)+import qualified Data.Text           as T import           GHC.Generics  data Token@@ -43,20 +43,20 @@ #endif  instance FromJSON Context where-  parseJSON (Object o) = return+  parseJSON (Object o) = do #if MIN_VERSION_aeson(2,0,0)-    Context { variables = H.fromList (fromJSONString <$> H.toList (KM.toHashMapText o)) }+    let t = KM.toHashMapText o #else-    Context { variables = H.fromList (fromJSONString <$> H.toList o) }+    let t = o #endif-  parseJSON _          = fail "expected an object"+    pure Context { variables = H.fromList (fromJSONString <$> H.toList t) }+    where+      fromJSONString (k,String v) = (k,v)+      fromJSONString _            = error "Expected a JSON String in second element of pair"+  parseJSON _          = fail "Expected a JSON object"  data Result   = Final !T.Text   | Partial { template :: !Template, context :: !Context }   deriving (Eq, Show)--fromJSONString :: (T.Text,Value) -> (T.Text,T.Text)-fromJSONString (k,String v) = (k,v)-fromJSONString (_,_)        = undefined