packages feed

glabrous 1.0.1 → 2.0.0

raw patch · 2 files changed

+30/−12 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Text.Glabrous: insert :: Template -> Token -> Template -> Maybe Template
- Text.Glabrous: insertMany :: Template -> [(Token, Template)] -> Maybe Template
+ Text.Glabrous: addTag :: Template -> Text -> Text -> Maybe Template
+ Text.Glabrous: insertManyTemplates :: Template -> [(Token, Template)] -> Maybe Template
+ Text.Glabrous: insertTemplate :: Template -> Token -> Template -> Maybe Template

Files

glabrous.cabal view
@@ -1,5 +1,5 @@ name:                glabrous-version:             1.0.1+version:             2.0.0 synopsis:            A template DSL library description:         A minimalistic, Mustache-like syntax, truly logic-less,                      pure Text template DSL library
src/Text/Glabrous.hs view
@@ -21,6 +21,7 @@   , readTemplateFile    -- ** 'Template' operations+  , addTag   , tagsOf   , tagsRename   , isFinal@@ -28,8 +29,8 @@   , toFinalText   , compress   , writeTemplateFile-  , insert-  , insertMany+  , insertTemplate+  , insertManyTemplates    -- * 'Context'   , Context (..)@@ -67,13 +68,30 @@ import           Data.Aeson.Encode.Pretty (encodePretty) import qualified Data.ByteString.Lazy     as L import qualified Data.HashMap.Strict      as H-import           Data.List                (intersect,uncons)+import           Data.List                (intersperse,intersect,uncons) import qualified Data.Text                as T import qualified Data.Text.IO             as I  import           Text.Glabrous.Internal import           Text.Glabrous.Types ++-- | Get 'Just' a new 'Template' with new tag(s) inside, or 'Nothing'.+addTag :: Template       -- ^ The template to work on+       -> T.Text         -- ^ Text to be replaced by the new tag+       -> T.Text         -- ^ New tag's name+       -> Maybe Template -- ^ Just a new template or nothing+addTag Template{..} r n = do+  let nc = concatMap (insertTag r n) content+  guard (length nc > length content)+  return Template { content = nc }+  where+    insertTag t t' (Literal l) =+      filter+        (/= (Literal T.empty))+        (intersperse (Tag t') $ (\x -> Literal x) <$> T.splitOn t l)+    insertTag _ _ t@(Tag _) = [t]+ -- | Optimize a 'Template' content after (many) 'partialProcess'(') rewriting(s). compress :: Template -> Template compress Template{..} =@@ -220,12 +238,12 @@ -- into another one by replacing the 'Tag', or 'Nothing'. -- -- >λ>insert t0 (Tag "template1") t1-insert :: Template       -- ^ The Template to insert in-       -> Token          -- ^ The Tag to be replaced-       -> Template       -- ^ The Template to be inserted-       -> Maybe Template -- ^ Just the new Template, or Nothing-insert _ (Literal _) _ = Nothing-insert te t te' = do+insertTemplate :: Template       -- ^ The Template to insert in+               -> Token          -- ^ The Tag to be replaced+               -> Template       -- ^ The Template to be inserted+               -> Maybe Template -- ^ Just the new Template, or Nothing+insertTemplate _ (Literal _) _ = Nothing+insertTemplate te t te' = do   guard (t `elem` content te)   return Template { content = foldl trans [] (content te) }   where@@ -239,8 +257,8 @@ -- if there is at least one tag correspondence, or 'Nothing'. -- -- >λ>insertMany t0 [(Tag "template1",t1),(Tag "template2",t2)]-insertMany :: Template -> [(Token,Template)] -> Maybe Template-insertMany te ttps = do+insertManyTemplates :: Template -> [(Token,Template)] -> Maybe Template+insertManyTemplates te ttps = do   guard (tagsOf te `intersect` (fst <$> ttps) /= mempty)   return Template { content = foldl trans [] (content te) }   where