diff options
author | stuebinm | 2021-12-16 01:34:22 +0100 |
---|---|---|
committer | Rehlein | 2021-12-18 11:56:23 +0100 |
commit | 47dd2e5fdfb29e38cf64e55356630ff1f3135b3a (patch) | |
tree | 8553a62fb48cfce287154bcc938ea39cc9eb1fba /lib | |
parent | 5b3cb907078b6f628a6d07189d39634f0cdfd15d (diff) |
change badge output format
(following a discussion with hxchn)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Badges.hs | 11 | ||||
-rw-r--r-- | lib/CheckDir.hs | 11 |
2 files changed, 7 insertions, 15 deletions
diff --git a/lib/Badges.hs b/lib/Badges.hs index 65433a1..5da2643 100644 --- a/lib/Badges.hs +++ b/lib/Badges.hs @@ -48,20 +48,17 @@ parseToken text = if text =~ ("^[a-zA-Z0-9]{50}$" :: Text) data Badge = Badge BadgeToken BadgeArea deriving (Ord, Eq, Generic, Show) -badgeJsonArray :: A.KeyValue a => Badge -> [a] -badgeJsonArray (Badge token area) = - [ "token" .= token ] <> areaObject - where areaObject = case area of +instance ToJSON Badge where + toJSON (Badge token area) = A.object $ case area of BadgePoint x y -> [ "x" .= x , "y" .= y + , "token" .= token , "type" .= A.String "point" ] BadgeRect {..} -> [ "x" .= areaX , "y" .= areaY + , "token" .= token , "width" .= areaWidth , "height" .= areaHeight , "type" .= A.String "rectangle" ] - -badgeJson :: FilePath -> Badge -> A.Value -badgeJson mappath badge = A.object (badgeJsonArray badge <> [ "map" .= mappath ]) diff --git a/lib/CheckDir.hs b/lib/CheckDir.hs index f21fe9c..a4ac2c6 100644 --- a/lib/CheckDir.hs +++ b/lib/CheckDir.hs @@ -9,7 +9,6 @@ -- | Module that contains high-level checking for an entire directory module CheckDir (recursiveCheckDir, DirResult(..), resultIsFatal) where -import Badges (badgeJson) import CheckMap (MapResult (..), loadAndLintMap) import Control.Monad (void) import Control.Monad.Extra (mapMaybeM) @@ -17,7 +16,7 @@ import Data.Aeson (ToJSON, (.=)) import qualified Data.Aeson as A import Data.Foldable (fold) import Data.Functor ((<&>)) -import Data.Map (Map, elems, keys, mapWithKey) +import Data.Map (Map, elems, keys) import qualified Data.Map as M import Data.Map.Strict (mapKeys, (\\)) import Data.Maybe (mapMaybe) @@ -102,13 +101,9 @@ instance ToJSON DirResult where ] , "resultText" .= prettyprint (Suggestion, res) , "severity" .= maximumLintLevel res - , "badges" .= annotatedBadges - , "maps" .= M.keys (dirresultMaps res) + , "mapInfo" .= fmap (\tm -> A.object [ "badges" .= mapresultBadges tm ]) + (dirresultMaps res) ] - where annotatedBadges = concat - . M.elems - . mapWithKey (\k -> fmap (badgeJson k) . mapresultBadges) - $ dirresultMaps res instance ToJSON MissingAsset where toJSON (MissingAsset md) = A.object |