Safe Haskell | None |
---|---|
Language | Haskell2010 |
GVal is a generic unitype value, representing the kind of values that Ginger can understand.
Most of the types in this module are parametrized over an m
type, which
is the host monad for template execution, as passed to runGingerT
.
- type Function m = [(Maybe Text, GVal m)] -> m (GVal m)
- matchFuncArgs :: [Text] -> [(Maybe Text, GVal m)] -> (HashMap Text (GVal m), [GVal m], HashMap Text (GVal m))
- data GVal m = GVal {}
- isList :: GVal m -> Bool
- isDict :: GVal m -> Bool
- class ToGVal m a where
- lookupIndex :: Int -> GVal m -> Maybe (GVal m)
- lookupIndexMay :: Maybe Int -> GVal m -> Maybe (GVal m)
- lookupKey :: Text -> GVal m -> Maybe (GVal m)
- lookupLoose :: GVal m -> GVal m -> Maybe (GVal m)
- keys :: GVal m -> Maybe [Text]
- toNumber :: GVal m -> Maybe Scientific
- toInt :: GVal m -> Maybe Int
- toBoolean :: GVal m -> Bool
- toFunction :: GVal m -> Maybe (Function m)
- fromFunction :: Function m -> GVal m
- scientificToText :: Scientific -> Text
Documentation
type Function m = [(Maybe Text, GVal m)] -> m (GVal m) Source
A function that can be called from within a template execution context.
matchFuncArgs :: [Text] -> [(Maybe Text, GVal m)] -> (HashMap Text (GVal m), [GVal m], HashMap Text (GVal m)) Source
Match arguments passed to a function at runtime against a list of declared
argument names.
matchFuncArgs argNames argsPassed
returns (matchedArgs, positionalArgs, namedArgs)
,
where matchedArgs
is a list of arguments matched against declared names
(by name or by position), positionalArgs
are the unused positional
(unnamed) arguments, and namedArgs
are the unused named arguments.
Ginger value.
ToGVal m (GVal m) Source | Trivial instance for |
Show (GVal m) Source | For convenience, |
IsString (GVal m) Source | |
Default (GVal m) Source | The default |
ToHtml (GVal m) Source | Converting to HTML hooks into the ToHtml instance for |
Types that implement conversion to GVal
ToGVal m Value Source | Convert Aeson |
ToGVal m Html Source | |
ToGVal m Text Source | |
ToGVal m Text Source | |
ToGVal m Bool Source | |
ToGVal m Scientific Source | |
ToGVal m Integer Source | |
ToGVal m Int Source | |
ToGVal m v => ToGVal m [v] Source | |
ToGVal m v => ToGVal m (Maybe v) Source | |
ToGVal m (GVal m) Source | Trivial instance for |
ToGVal m v => ToGVal m (HashMap Text v) Source |
lookupIndexMay :: Maybe Int -> GVal m -> Maybe (GVal m) Source
Helper function; look up a value by an integer index when the index may or
may not be available. If no index is given, return Nothing
.
lookupLoose :: GVal m -> GVal m -> Maybe (GVal m) Source
Loosely-typed lookup: try dictionary-style lookup first (treat index as a string, and container as a dictionary), if that doesn't yield anything (either because the index is not string-ish, or because the container doesn't provide dictionary-style access), try index-based lookup.
keys :: GVal m -> Maybe [Text] Source
Treat a GVal
as a dictionary and list all the keys, with no particular
ordering.
toBoolean :: GVal m -> Bool Source
Loose cast to boolean.
Numeric zero, empty strings, empty lists, empty objects, Null
, and boolean
False
are considered falsy, anything else (including functions) is
considered true-ish.
toFunction :: GVal m -> Maybe (Function m) Source
scientificToText :: Scientific -> Text Source