packages feed

doctemplates 0.8.1 → 0.8.2

raw patch · 6 files changed

+79/−14 lines, 6 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Text.DocTemplates.Internal: AllButLast :: Pipe
+ Text.DocTemplates.Internal: FirstItem :: Pipe
+ Text.DocTemplates.Internal: LastItem :: Pipe
+ Text.DocTemplates.Internal: Rest :: Pipe

Files

README.md view
@@ -397,6 +397,22 @@   value was an array, the `key` will be the array index,   starting with 1. +- `first`: Returns the first value of an array, if+  applied to a non-empty array; otherwise returns+  the original value.++- `last`: Returns the last value of an array, if+  applied to a non-empty array; otherwise returns+  the original value.++- `rest`: Returns all but the first value of an array, if+  applied to a non-empty array; otherwise returns+  the original value.++- `allbutlast`: Returns all but the last value of an array, if+  applied to a non-empty array; otherwise returns+  the original value.+ - `uppercase`:  Converts text to uppercase.  - `lowercase`:  Converts text to lowercase.
changelog.md view
@@ -1,5 +1,12 @@ # doctemplates +## 0.8.2++  * Add filters: first, rest, last, allbutlast.++  * New constructors for Filter: FirstItem, LastItem, Rest, AllButLast+    [API change].+ ## 0.8.1    * Depend on doclayout 0.3, which adds an additional method
doctemplates.cabal view
@@ -1,5 +1,5 @@ name:                doctemplates-version:             0.8.1+version:             0.8.2 synopsis:            Pandoc-style document templates description:         This is the text templating system used by pandoc.                      It supports variable interpolation, iteration,
src/Text/DocTemplates/Internal.hs view
@@ -92,6 +92,10 @@     | ToLowercase     | ToLength     | Reverse+    | FirstItem+    | LastItem+    | Rest+    | AllButLast     | Chomp     | ToAlpha     | ToRoman@@ -315,6 +319,22 @@   toPair (k, v) = MapVal $ Context $ M.fromList                     [ ("key", SimpleVal $ fromString . T.unpack $ k)                     , ("value", v) ]+applyPipe FirstItem val =+  case val of+    ListVal (x:_) -> x+    _             -> val+applyPipe LastItem val =+  case val of+    ListVal xs@(_:_) -> last xs+    _                -> val+applyPipe Rest val =+  case val of+    ListVal (_:xs) -> ListVal xs+    _              -> val+applyPipe AllButLast val =+  case val of+    ListVal xs@(_:_) -> ListVal (init xs)+    _                -> val applyPipe Reverse val =   case val of     ListVal xs  -> ListVal (reverse xs)
src/Text/DocTemplates/Parser.hs view
@@ -408,19 +408,23 @@   pipeName <- P.many1 P.letter   P.notFollowedBy P.letter   case pipeName of-    "uppercase" -> return ToUppercase-    "lowercase" -> return ToLowercase-    "pairs"     -> return ToPairs-    "length"    -> return ToLength-    "alpha"     -> return ToAlpha-    "roman"     -> return ToRoman-    "reverse"   -> return Reverse-    "chomp"     -> return Chomp-    "nowrap"    -> return NoWrap-    "left"      -> Block LeftAligned <$> pBlockWidth <*> pBlockBorders-    "right"     -> Block RightAligned <$> pBlockWidth <*> pBlockBorders-    "center"    -> Block Centered <$> pBlockWidth <*> pBlockBorders-    _           -> fail $ "Unknown pipe " ++ pipeName+    "uppercase"  -> return ToUppercase+    "lowercase"  -> return ToLowercase+    "pairs"      -> return ToPairs+    "length"     -> return ToLength+    "alpha"      -> return ToAlpha+    "roman"      -> return ToRoman+    "reverse"    -> return Reverse+    "first"      -> return FirstItem+    "rest"       -> return Rest+    "last"       -> return LastItem+    "allbutlast" -> return AllButLast+    "chomp"      -> return Chomp+    "nowrap"     -> return NoWrap+    "left"       -> Block LeftAligned <$> pBlockWidth <*> pBlockBorders+    "right"      -> Block RightAligned <$> pBlockWidth <*> pBlockBorders+    "center"     -> Block Centered <$> pBlockWidth <*> pBlockBorders+    _            -> fail $ "Unknown pipe " ++ pipeName  pBlockWidth :: Monad m => Parser m Int pBlockWidth = P.try (do
test/pipes.test view
@@ -50,6 +50,16 @@ $for(bim/uppercase)$ $it.Zub$ $endfor$++$digits/first$+$digits/last$+$for(digits/rest)$+$it$+$endfor$+$for(digits/allbutlast)$+$it$+$endfor$+$foo/first$ . 0 2@@ -89,3 +99,11 @@ i v xx  SIM++1+20+5+20+1+5+1