summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2024-11-15 17:03:23 +0100
committerEugen Wissner <belka@caraus.de>2024-11-15 17:03:23 +0100
commitb5e6e3a2d68111cc7f84d939dc7b82ff2aac1801 (patch)
tree7a85cb9c4cecb4e36a6612fc857146cd07ce3359 /lib
parent2f46303a6d18b98d1c970a2c18d3907bba826bb0 (diff)
downloadslackbuilder-b5e6e3a2d68111cc7f84d939dc7b82ff2aac1801.tar.gz
Move package configuration to the configuration file
Diffstat (limited to 'lib')
-rw-r--r--lib/SlackBuilder/Package.hs25
1 files changed, 9 insertions, 16 deletions
diff --git a/lib/SlackBuilder/Package.hs b/lib/SlackBuilder/Package.hs
index 5f8472e..5179c4c 100644
--- a/lib/SlackBuilder/Package.hs
+++ b/lib/SlackBuilder/Package.hs
@@ -2,15 +2,16 @@
v. 2.0. If a copy of the MPL was not distributed with this file, You can
obtain one at https://mozilla.org/MPL/2.0/. -}
--- | Contains data describing packages and how they are should be updated,
+-- | Contains data describing packages, methods to update them and to request
+-- information about them.
module SlackBuilder.Package
- ( DownloadPlaceholder(..)
- , Download(..)
+ ( Download(..)
, DownloadTemplate(..)
, PackageDescription(..)
, PackageUpdateData(..)
, Updater(..)
, renderDownloadWithVersion
+ , renderTextWithVersion
) where
import Data.Text (Text)
@@ -41,18 +42,6 @@ data Download = Download
, md5sum :: Digest MD5
} 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
- = StaticPlaceholder Text
- | VersionPlaceholder
- deriving Eq
-
-instance Show DownloadPlaceholder
- where
- show (StaticPlaceholder staticPlaceholder) = Text.unpack staticPlaceholder
- show VersionPlaceholder = "{version}"
-
-- | List of URI components, including version placeholders.
newtype DownloadTemplate = DownloadTemplate
{ unDownloadTemplate :: Text
@@ -65,7 +54,11 @@ instance Show DownloadTemplate
-- | Replaces placeholders in the URL template with the given version.
renderDownloadWithVersion :: MonadThrow m => DownloadTemplate -> Text -> m URI
renderDownloadWithVersion (DownloadTemplate template) version =
- URI.mkURI $ Text.replace "{version}" version template
+ URI.mkURI $ renderTextWithVersion template version
+
+-- | Replaces placeholders in the text with the given version.
+renderTextWithVersion :: Text -> Text -> Text
+renderTextWithVersion template version = Text.replace "{version}" version template
-- | Function used to get the latest version of a source.
data Updater = Updater