ginger 0.1.7.0 → 0.1.8.0
raw patch · 4 files changed
+80/−2 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- ginger.cabal +1/−1
- src/Text/Ginger.hs +30/−1
- src/Text/Ginger/Parse.hs +4/−0
- src/Text/Ginger/Run.hs +45/−0
ginger.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: ginger-version: 0.1.7.0+version: 0.1.8.0 synopsis: An implementation of the Jinja2 template language in Haskell description: Ginger is Jinja, minus the most blatant pythonisms. Wants to be feature complete, but isn't quite there yet.
src/Text/Ginger.hs view
@@ -191,6 +191,35 @@ -- a function to a context value on the host side, you can use it just like -- any other function / filter. +-- ** Control Constructs+-- *** Conditionals: `{% if %}`+-- | Simplest form:++-- | > {% if condition %}Hello!{% endif %}++-- | Slightly more elaborate:++-- | > {% if condition %}Hello!{% else %}Goodbye!{% endif %}++-- | Full glory:++-- | > {% if condition %}Hello!{% elseif otherCondition %}Sayonara!{% else %}Goodbye!{% endif %}++-- *** set+-- | TODO+-- *** for+-- | TODO+-- *** include+-- | TODO+-- *** macro+-- | TODO+-- *** block+-- | TODO+-- *** call+-- | TODO+-- *** scope+-- | TODO+ -- * Haskell API -- ** General -- | On the Haskell side of things, executing a template is a two-step process.@@ -208,7 +237,7 @@ -- example implementation for 'IO' would look like this: -- | > loadFile fn = openFile fn ReadMode >>= hGetContents--- > +-- > -- > loadFileMay fn = -- > tryIOError (loadFile fn) >>= \e -> -- > case e of
src/Text/Ginger/Parse.hs view
@@ -473,6 +473,10 @@ additiveExprP [ ("==", "equals") , ("!=", "nequals")+ , (">=", "greaterEquals")+ , ("<=", "lessEquals")+ , (">", "greater")+ , ("<", "less") ] additiveExprP :: Monad m => Parser m Expression
src/Text/Ginger/Run.hs view
@@ -29,6 +29,7 @@ where import Prelude ( (.), ($), (==), (/=)+ , (>), (<), (>=), (<=) , (+), (-), (*), (/), div , (||), (&&) , (++)@@ -140,6 +141,10 @@ , ("difference", fromFunction . variadicNumericFunc 0 $ difference) , ("equals", fromFunction gfnEquals) , ("nequals", fromFunction gfnNEquals)+ , ("greaterEquals", fromFunction gfnGreaterEquals)+ , ("lessEquals", fromFunction gfnLessEquals)+ , ("greater", fromFunction gfnGreater)+ , ("less", fromFunction gfnLess) , ("floor", fromFunction . unaryNumericFunc 0 $ Prelude.fromIntegral . Prelude.floor) , ("int", fromFunction . unaryFunc $ toGVal . (fmap (Prelude.truncate :: Scientific -> Int)) . asNumber) , ("int_ratio", fromFunction . variadicNumericFunc 1 $ fromIntegral . intRatio . Prelude.map Prelude.floor)@@ -215,6 +220,46 @@ -- If either is NULL, the other must be falsy | isNull a || isNull b = asBoolean a == asBoolean b | otherwise = asText a == asText b++ gfnLess :: Function (Run m)+ gfnLess [] = return . toGVal $ False+ gfnLess xs' =+ let xs = fmap snd xs'+ in return . toGVal $+ Prelude.all (== Just True) (Prelude.zipWith less xs (Prelude.tail xs))++ gfnGreater :: Function (Run m)+ gfnGreater [] = return . toGVal $ False+ gfnGreater xs' =+ let xs = fmap snd xs'+ in return . toGVal $+ Prelude.all (== Just True) (Prelude.zipWith greater xs (Prelude.tail xs))++ gfnLessEquals :: Function (Run m)+ gfnLessEquals [] = return . toGVal $ False+ gfnLessEquals xs' =+ let xs = fmap snd xs'+ in return . toGVal $+ Prelude.all (== Just True) (Prelude.zipWith lessEq xs (Prelude.tail xs))++ gfnGreaterEquals :: Function (Run m)+ gfnGreaterEquals [] = return . toGVal $ False+ gfnGreaterEquals xs' =+ let xs = fmap snd xs'+ in return . toGVal $+ Prelude.all (== Just True) (Prelude.zipWith greaterEq xs (Prelude.tail xs))++ less :: GVal (Run m) -> GVal (Run m) -> Maybe Bool+ less a b = (<) <$> asNumber a <*> asNumber b++ greater :: GVal (Run m) -> GVal (Run m) -> Maybe Bool+ greater a b = (>) <$> asNumber a <*> asNumber b++ lessEq :: GVal (Run m) -> GVal (Run m) -> Maybe Bool+ lessEq a b = (<=) <$> asNumber a <*> asNumber b++ greaterEq :: GVal (Run m) -> GVal (Run m) -> Maybe Bool+ greaterEq a b = (>=) <$> asNumber a <*> asNumber b difference :: Prelude.Num a => [a] -> a difference (x:xs) = x - Prelude.sum xs