module Network.URI.Template.Expand
( expandTemplate
) where
import Prelude
import Data.Map.Strict (Map)
import Data.Text (Text)
import Network.URI.Template.Internal
import Network.URI.Template.VarName
import Network.URI.Template.VarValue
expandTemplate :: Map VarName VarValue -> Template -> Text
expandTemplate :: Map VarName VarValue -> Template -> Text
expandTemplate Map VarName VarValue
env = (TemplatePart -> Text) -> [TemplatePart] -> Text
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (Map VarName VarValue -> TemplatePart -> Text
expandTemplatePart Map VarName VarValue
env) ([TemplatePart] -> Text)
-> (Template -> [TemplatePart]) -> Template -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (.unwrap)
expandTemplatePart :: Map VarName VarValue -> TemplatePart -> Text
expandTemplatePart :: Map VarName VarValue -> TemplatePart -> Text
expandTemplatePart Map VarName VarValue
env = \case
Lit Text
t -> Text
t
Exp Expression
e -> Map VarName VarValue -> Expression -> Text
expandExpression Map VarName VarValue
env Expression
e