packages feed

ginger 0.1.0.0 → 0.1.1.0

raw patch · 2 files changed

+53/−11 lines, 2 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Text.Ginger.AST: blockBody :: Block -> Statement
- Text.Ginger.AST: instance Show Block
- Text.Ginger.AST: instance Show Expression
- Text.Ginger.AST: instance Show Macro
- Text.Ginger.AST: instance Show Statement
- Text.Ginger.AST: instance Show Template
- Text.Ginger.AST: macroArgs :: Macro -> [VarName]
- Text.Ginger.AST: macroBody :: Macro -> Statement
- Text.Ginger.AST: templateBlocks :: Template -> HashMap VarName Block
- Text.Ginger.AST: templateBody :: Template -> Statement
- Text.Ginger.AST: templateParent :: Template -> Maybe Template
- Text.Ginger.GVal: asBoolean :: GVal m -> Bool
- Text.Ginger.GVal: asDictItems :: GVal m -> Maybe [(Text, GVal m)]
- Text.Ginger.GVal: asFunction :: GVal m -> Maybe (Function m)
- Text.Ginger.GVal: asHtml :: GVal m -> Html
- Text.Ginger.GVal: asList :: GVal m -> Maybe [GVal m]
- Text.Ginger.GVal: asLookup :: GVal m -> Maybe (Text -> Maybe (GVal m))
- Text.Ginger.GVal: asNumber :: GVal m -> Maybe Scientific
- Text.Ginger.GVal: asText :: GVal m -> Text
- Text.Ginger.GVal: instance Default (GVal m)
- Text.Ginger.GVal: instance IsString (GVal m)
- Text.Ginger.GVal: instance Show (GVal m)
- Text.Ginger.GVal: instance ToGVal m (GVal m)
- Text.Ginger.GVal: instance ToGVal m Bool
- Text.Ginger.GVal: instance ToGVal m Html
- Text.Ginger.GVal: instance ToGVal m Int
- Text.Ginger.GVal: instance ToGVal m Integer
- Text.Ginger.GVal: instance ToGVal m Scientific
- Text.Ginger.GVal: instance ToGVal m Text
- Text.Ginger.GVal: instance ToGVal m Value
- Text.Ginger.GVal: instance ToGVal m v => ToGVal m (HashMap Text v)
- Text.Ginger.GVal: instance ToGVal m v => ToGVal m (Maybe v)
- Text.Ginger.GVal: instance ToGVal m v => ToGVal m [v]
- Text.Ginger.GVal: instance ToHtml (GVal m)
- Text.Ginger.GVal: isNull :: GVal m -> Bool
- Text.Ginger.GVal: length :: GVal m -> Maybe Int
- Text.Ginger.Html: instance Eq Html
- Text.Ginger.Html: instance Monoid Html
- Text.Ginger.Html: instance Ord Html
- Text.Ginger.Html: instance Show Html
- Text.Ginger.Html: instance ToHtml Html
- Text.Ginger.Html: instance ToHtml Text
- Text.Ginger.Html: instance ToHtml [Char]
- Text.Ginger.Parse: instance Show ParserError
- Text.Ginger.Parse: peErrorMessage :: ParserError -> String
- Text.Ginger.Parse: peSourceColumn :: ParserError -> Maybe Int
- Text.Ginger.Parse: peSourceLine :: ParserError -> Maybe Int
- Text.Ginger.Parse: peSourceName :: ParserError -> Maybe SourceName
+ Text.Ginger.AST: [blockBody] :: Block -> Statement
+ Text.Ginger.AST: [macroArgs] :: Macro -> [VarName]
+ Text.Ginger.AST: [macroBody] :: Macro -> Statement
+ Text.Ginger.AST: [templateBlocks] :: Template -> HashMap VarName Block
+ Text.Ginger.AST: [templateBody] :: Template -> Statement
+ Text.Ginger.AST: [templateParent] :: Template -> Maybe Template
+ Text.Ginger.AST: instance GHC.Show.Show Text.Ginger.AST.Block
+ Text.Ginger.AST: instance GHC.Show.Show Text.Ginger.AST.Expression
+ Text.Ginger.AST: instance GHC.Show.Show Text.Ginger.AST.Macro
+ Text.Ginger.AST: instance GHC.Show.Show Text.Ginger.AST.Statement
+ Text.Ginger.AST: instance GHC.Show.Show Text.Ginger.AST.Template
+ Text.Ginger.GVal: [asBoolean] :: GVal m -> Bool
+ Text.Ginger.GVal: [asDictItems] :: GVal m -> Maybe [(Text, GVal m)]
+ Text.Ginger.GVal: [asFunction] :: GVal m -> Maybe (Function m)
+ Text.Ginger.GVal: [asHtml] :: GVal m -> Html
+ Text.Ginger.GVal: [asList] :: GVal m -> Maybe [GVal m]
+ Text.Ginger.GVal: [asLookup] :: GVal m -> Maybe (Text -> Maybe (GVal m))
+ Text.Ginger.GVal: [asNumber] :: GVal m -> Maybe Scientific
+ Text.Ginger.GVal: [asText] :: GVal m -> Text
+ Text.Ginger.GVal: [isNull] :: GVal m -> Bool
+ Text.Ginger.GVal: [length] :: GVal m -> Maybe Int
+ Text.Ginger.GVal: instance Data.Default.Class.Default (Text.Ginger.GVal.GVal m)
+ Text.Ginger.GVal: instance Data.String.IsString (Text.Ginger.GVal.GVal m)
+ Text.Ginger.GVal: instance GHC.Show.Show (Text.Ginger.GVal.GVal m)
+ Text.Ginger.GVal: instance Text.Ginger.GVal.ToGVal m (Text.Ginger.GVal.GVal m)
+ Text.Ginger.GVal: instance Text.Ginger.GVal.ToGVal m Data.Aeson.Types.Internal.Value
+ Text.Ginger.GVal: instance Text.Ginger.GVal.ToGVal m Data.Scientific.Scientific
+ Text.Ginger.GVal: instance Text.Ginger.GVal.ToGVal m Data.Text.Internal.Lazy.Text
+ Text.Ginger.GVal: instance Text.Ginger.GVal.ToGVal m Data.Text.Internal.Text
+ Text.Ginger.GVal: instance Text.Ginger.GVal.ToGVal m GHC.Integer.Type.Integer
+ Text.Ginger.GVal: instance Text.Ginger.GVal.ToGVal m GHC.Types.Bool
+ Text.Ginger.GVal: instance Text.Ginger.GVal.ToGVal m GHC.Types.Int
+ Text.Ginger.GVal: instance Text.Ginger.GVal.ToGVal m Text.Ginger.Html.Html
+ Text.Ginger.GVal: instance Text.Ginger.GVal.ToGVal m v => Text.Ginger.GVal.ToGVal m (Data.HashMap.Base.HashMap Data.Text.Internal.Text v)
+ Text.Ginger.GVal: instance Text.Ginger.GVal.ToGVal m v => Text.Ginger.GVal.ToGVal m (GHC.Base.Maybe v)
+ Text.Ginger.GVal: instance Text.Ginger.GVal.ToGVal m v => Text.Ginger.GVal.ToGVal m [v]
+ Text.Ginger.GVal: instance Text.Ginger.Html.ToHtml (Text.Ginger.GVal.GVal m)
+ Text.Ginger.Html: instance GHC.Base.Monoid Text.Ginger.Html.Html
+ Text.Ginger.Html: instance GHC.Classes.Eq Text.Ginger.Html.Html
+ Text.Ginger.Html: instance GHC.Classes.Ord Text.Ginger.Html.Html
+ Text.Ginger.Html: instance GHC.Show.Show Text.Ginger.Html.Html
+ Text.Ginger.Html: instance Text.Ginger.Html.ToHtml Data.Text.Internal.Text
+ Text.Ginger.Html: instance Text.Ginger.Html.ToHtml Text.Ginger.Html.Html
+ Text.Ginger.Html: instance Text.Ginger.Html.ToHtml [GHC.Types.Char]
+ Text.Ginger.Parse: [peErrorMessage] :: ParserError -> String
+ Text.Ginger.Parse: [peSourceColumn] :: ParserError -> Maybe Int
+ Text.Ginger.Parse: [peSourceLine] :: ParserError -> Maybe Int
+ Text.Ginger.Parse: [peSourceName] :: ParserError -> Maybe SourceName
+ Text.Ginger.Parse: instance GHC.Show.Show Text.Ginger.Parse.ParserError

Files

ginger.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/  name:                ginger-version:             0.1.0.0+version:             0.1.1.0 synopsis:            An implementation of the Jinja2 template language in Haskell -- description:          homepage:            https://bitbucket.org/tdammers/ginger
src/Text/Ginger/Run.hs view
@@ -85,6 +85,15 @@         args' :: [Scientific]         args' = Prelude.map (fromMaybe zero . asNumber . snd) args +unaryNumericFunc :: Monad m => Scientific -> (Scientific -> Scientific) -> [(Maybe Text, GVal (Run m))] -> Run m (GVal (Run m))+unaryNumericFunc zero f args =+    return . toGVal . f $ args'+    where+        args' :: Scientific+        args' = case args of+                    [] -> 0+                    (arg:_) -> fromMaybe zero . asNumber . snd $ arg+ variadicStringFunc :: Monad m => ([Text] -> Text) -> [(Maybe Text, GVal (Run m))] -> Run m (GVal (Run m)) variadicStringFunc f args =     return . toGVal . f $ args'@@ -104,20 +113,29 @@         scope :: [(Text, GVal (Run m))]         scope =             [ ("raw", fromFunction gfnRawHtml)-            , ("length", fromFunction . unaryFunc $ toGVal . length)-            , ("str", fromFunction . unaryFunc $ toGVal . asText)-            , ("num", fromFunction . unaryFunc $ toGVal . asNumber)-            , ("iterable", fromFunction . unaryFunc $ toGVal . (\x -> isList x || isDict x))-            , ("show", fromFunction . unaryFunc $ fromString . show)+            , ("abs", fromFunction . unaryNumericFunc 0 $ Prelude.abs)+            -- TODO: batch+            , ("ceil", fromFunction . unaryNumericFunc 0 $ Prelude.fromIntegral . Prelude.ceiling)+            , ("capitalize", fromFunction . variadicStringFunc $ mconcat . Prelude.map capitalize)+            , ("center", fromFunction gfnCenter)+            , ("concat", fromFunction . variadicStringFunc $ mconcat)             , ("default", fromFunction gfnDefault)-            , ("sum", fromFunction . variadicNumericFunc 0 $ Prelude.sum)             , ("difference", fromFunction . variadicNumericFunc 0 $ difference)-            , ("concat", fromFunction . variadicStringFunc $ mconcat)-            , ("product", fromFunction . variadicNumericFunc 1 $ Prelude.product)-            , ("ratio", fromFunction . variadicNumericFunc 1 $ Scientific.fromFloatDigits . ratio . Prelude.map Scientific.toRealFloat)+            , ("equals", fromFunction gfnEquals)+            , ("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)+            , ("iterable", fromFunction . unaryFunc $ toGVal . (\x -> isList x || isDict x))+            , ("length", fromFunction . unaryFunc $ toGVal . length)             , ("modulo", fromFunction . variadicNumericFunc 1 $ fromIntegral . modulo . Prelude.map Prelude.floor)-            , ("equals", fromFunction gfnEquals)+            , ("num", fromFunction . unaryFunc $ toGVal . asNumber)+            , ("product", fromFunction . variadicNumericFunc 1 $ Prelude.product)+            , ("ratio", fromFunction . variadicNumericFunc 1 $ Scientific.fromFloatDigits . ratio . Prelude.map Scientific.toRealFloat)+            , ("round", fromFunction . unaryNumericFunc 0 $ Prelude.fromIntegral . Prelude.round)+            , ("show", fromFunction . unaryFunc $ fromString . show)+            , ("str", fromFunction . unaryFunc $ toGVal . asText)+            , ("sum", fromFunction . variadicNumericFunc 0 $ Prelude.sum)+            , ("truncate", fromFunction . unaryNumericFunc 0 $ Prelude.fromIntegral . Prelude.truncate)             ]          gfnRawHtml :: Function (Run m)@@ -161,6 +179,30 @@         modulo :: (Prelude.Integral a, Prelude.Num a) => [a] -> a         modulo (x:xs) = x `Prelude.mod` Prelude.product xs         modulo [] = 0++        capitalize :: Text -> Text+        capitalize txt = Text.toUpper (Text.take 1 txt) <> Text.drop 1 txt++        gfnCenter :: Function (Run m)+        gfnCenter [] = gfnCenter [(Nothing, toGVal ("" :: Text))]+        gfnCenter (x:[]) = gfnCenter [x, (Nothing, toGVal (80 :: Int))]+        gfnCenter (x:y:[]) = gfnCenter [x, y, (Nothing, toGVal (" " :: Text))]+        gfnCenter ((_, s):(_, w):(_, pad):_) =+            return . toGVal $ center (asText s) (fromMaybe 80 $ Prelude.truncate <$> asNumber w) (asText pad)++        center :: Text -> Prelude.Int -> Text -> Text+        center str width pad =+            if Text.length str Prelude.>= width+                then str+                else paddingL <> str <> paddingR+            where+                chars = width - Text.length str+                charsL = chars `div` 2+                charsR = chars - charsL+                repsL = Prelude.succ charsL `div` Text.length pad+                paddingL = Text.take charsL . Text.replicate repsL $ pad+                repsR = Prelude.succ charsR `div` Text.length pad+                paddingR = Text.take charsR . Text.replicate repsR $ pad  -- | Create an execution context for runGingerT. -- Takes a lookup function, which returns ginger values into the carrier monad