blob: 20398064af2c6bda220a77ef36f16de5ef941209 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
|