Support text based placeholders
This commit is contained in:
@ -9,12 +9,10 @@ module SlackBuilder.Package
|
||||
, DownloadTemplate(..)
|
||||
, PackageDescription(..)
|
||||
, PackageUpdateData(..)
|
||||
, Maintainer(..)
|
||||
, Updater(..)
|
||||
, renderDownloadWithVersion
|
||||
) where
|
||||
|
||||
import Data.List.NonEmpty (NonEmpty(..))
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as Text
|
||||
import Text.URI (URI(..))
|
||||
@ -43,12 +41,6 @@ data Download = Download
|
||||
, md5sum :: Digest MD5
|
||||
} deriving (Eq, Show)
|
||||
|
||||
-- | Package maintainer information.
|
||||
data Maintainer = Maintainer
|
||||
{ name :: Text
|
||||
, email :: Text
|
||||
} deriving (Eq, Show)
|
||||
|
||||
-- | Appears in the download URI template and specifies which part of the URI
|
||||
-- should be replaced with the package version.
|
||||
data DownloadPlaceholder
|
||||
@ -62,20 +54,18 @@ instance Show DownloadPlaceholder
|
||||
show VersionPlaceholder = "{version}"
|
||||
|
||||
-- | List of URI components, including version placeholders.
|
||||
newtype DownloadTemplate = DownloadTemplate (NonEmpty DownloadPlaceholder)
|
||||
deriving Eq
|
||||
newtype DownloadTemplate = DownloadTemplate
|
||||
{ unDownloadTemplate :: Text
|
||||
} deriving Eq
|
||||
|
||||
instance Show DownloadTemplate
|
||||
where
|
||||
show (DownloadTemplate components) = concatMap show components
|
||||
show = Text.unpack . unDownloadTemplate
|
||||
|
||||
-- | Replaces placeholders in the URL template with the given version.
|
||||
renderDownloadWithVersion :: MonadThrow m => DownloadTemplate -> Text -> m URI
|
||||
renderDownloadWithVersion (DownloadTemplate components) version =
|
||||
URI.mkURI $ foldr f "" components
|
||||
where
|
||||
f (StaticPlaceholder staticPlaceholder) = (staticPlaceholder <>)
|
||||
f VersionPlaceholder = (version <>)
|
||||
renderDownloadWithVersion (DownloadTemplate template) version =
|
||||
URI.mkURI $ Text.replace "{version}" version template
|
||||
|
||||
-- | Function used to get the latest version of a source.
|
||||
data Updater = Updater
|
||||
|
Reference in New Issue
Block a user