{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE RecordWildCards #-} module Dhall.URL where import Data.Monoid ((<>)) import Data.Text (Text) import Dhall.Syntax ( Scheme(..) , URL(..) , File(..) , Directory(..) ) import qualified Network.URI.Encode as URI.Encode renderComponent :: Text -> Text renderComponent :: Text -> Text renderComponent component :: Text component = "/" Text -> Text -> Text forall a. Semigroup a => a -> a -> a <> Text -> Text URI.Encode.encodeText Text component renderQuery :: Text -> Text renderQuery :: Text -> Text renderQuery query :: Text query = "?" Text -> Text -> Text forall a. Semigroup a => a -> a -> a <> Text query renderURL :: URL -> Text renderURL :: URL -> Text renderURL url :: URL url = Text schemeText Text -> Text -> Text forall a. Semigroup a => a -> a -> a <> Text authority Text -> Text -> Text forall a. Semigroup a => a -> a -> a <> Text pathText Text -> Text -> Text forall a. Semigroup a => a -> a -> a <> Text queryText where URL {..} = URL url File {..} = File path Directory {..} = Directory directory schemeText :: Text schemeText = case Scheme scheme of HTTP -> "http://" HTTPS -> "https://" pathText :: Text pathText = (Text -> Text) -> [Text] -> Text forall (t :: * -> *) m a. (Foldable t, Monoid m) => (a -> m) -> t a -> m foldMap Text -> Text renderComponent ([Text] -> [Text] forall a. [a] -> [a] reverse [Text] components) Text -> Text -> Text forall a. Semigroup a => a -> a -> a <> Text -> Text renderComponent Text file queryText :: Text queryText = (Text -> Text) -> Maybe Text -> Text forall (t :: * -> *) m a. (Foldable t, Monoid m) => (a -> m) -> t a -> m foldMap Text -> Text renderQuery Maybe Text query