diff options
| author | Chris Wells <chris@mathematicaster.org> | 2025-02-10 12:48:38 -0600 |
|---|---|---|
| committer | Chris Wells <chris@mathematicaster.org> | 2025-02-10 12:48:38 -0600 |
| commit | 0c677070edf9978cb85a0b521f7e6e0ef6d6b491 (patch) | |
| tree | 1bf0a024ea2c1ccc9c21c68b916e76017bafd310 /src/Data/License.hs | |
| parent | 75ac829ee7d661d758f7828e609e28ee4e05d038 (diff) | |
| download | main-0c677070edf9978cb85a0b521f7e6e0ef6d6b491.tar main-0c677070edf9978cb85a0b521f7e6e0ef6d6b491.tar.gz main-0c677070edf9978cb85a0b521f7e6e0ef6d6b491.tar.bz2 main-0c677070edf9978cb85a0b521f7e6e0ef6d6b491.tar.lz main-0c677070edf9978cb85a0b521f7e6e0ef6d6b491.tar.xz main-0c677070edf9978cb85a0b521f7e6e0ef6d6b491.tar.zst main-0c677070edf9978cb85a0b521f7e6e0ef6d6b491.zip | |
A lot of work on aliases and the like
Diffstat (limited to 'src/Data/License.hs')
| -rw-r--r-- | src/Data/License.hs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/Data/License.hs b/src/Data/License.hs new file mode 100644 index 0000000..2039806 --- /dev/null +++ b/src/Data/License.hs @@ -0,0 +1,40 @@ +module Data.License + ( License (..) + , License_ + , licenseHtml + ) where + +import Prolog +import Network.URI +import Data.Aeson +import Data.Alias +import Data.Set qualified as S +import Text.Blaze +import Text.Blaze.Html + +import Data.Linked + +data License a = License + { name :: !a + , shortName :: !(Maybe a) + , link :: !(Maybe URI) + } deriving (Eq, Foldable, Functor, Generic, Ord, Show, Traversable) + +instance Binary a => Binary (License a) + +type License_ = License StrictText + +licenseHtml :: ToMarkup a => License a -> Html +licenseHtml (License n sn l) = linkedHtml $ Linked (maybe n id sn) l (n <$ sn) + +instance Ord a => ToAliases (License a) a where + toAliases (License n sn _) = S.fromList $ n : toList sn + +instance FromAlias a (License a) where + fromAlias n = pure $ License n Nothing Nothing + +instance FromJSON a => FromJSON (License a) where + parseJSON = withObject "License" $ \v -> License + <$> v .: "name" + <*> v .:? "short" .!= Nothing + <*> v .:? "link" .!= Nothing |
