packages feed

spdx-license 0.1.0 → 0.1.1

raw patch · 2 files changed

+15/−1 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Distribution.SPDX.Template: unsafeRender :: Map Text Text -> License -> Text

Files

spdx-license.cabal view
@@ -1,6 +1,6 @@ cabal-version:      3.0 name:               spdx-license-version:            0.1.0+version:            0.1.1  synopsis:           SPDX license templates description:        Parsing, pretty-printing and rendering of SPDX license templates
src/Distribution/SPDX/Template.hs view
@@ -11,12 +11,14 @@     license,     prettyLicense,     render,+    unsafeRender,   ) where  import Data.Functor import Data.Map.Strict (Map) import qualified Data.Map.Strict as M+import Data.Maybe (fromMaybe) import Data.String.Interpolate import Data.Text (Text, pack) import qualified Data.Text as T@@ -156,6 +158,18 @@ substitute' :: Map Text Text -> [Piece] -> Either SubstitutionError Text substitute' ctx ps = T.concat <$> traverse (substitute ctx) ps +unsafeSubstitute :: Map Text Text -> Piece -> Text+unsafeSubstitute _ (Substansive s) = s+unsafeSubstitute ctx (Optional ps) = unsafeSubstitute' ctx ps+unsafeSubstitute ctx Var {..} = fromMaybe original $ M.lookup name ctx++unsafeSubstitute' :: Map Text Text -> [Piece] -> Text+unsafeSubstitute' ctx ps = T.concat $ map (unsafeSubstitute ctx) ps+ -- | Render a license from a context, if a var is not in the context, the original value will be used render :: Map Text Text -> License -> Either SubstitutionError Text render ctx (License ps) = T.concat <$> traverse (substitute ctx) ps++-- | Render a license without checking whether the texts match the regexes+unsafeRender :: Map Text Text -> License -> Text+unsafeRender ctx (License ps) = T.concat $ map (unsafeSubstitute ctx) ps