From cfb9ed248fd7afa9029695cb5cc759b43276d79b Mon Sep 17 00:00:00 2001 From: Andrei Dziahel Date: Wed, 20 Dec 2017 01:16:44 +0300 Subject: [PATCH] Introduces highlighting package version differences --- src/Stackage/Snapshot/Diff.hs | 16 ++++++++++++++++ templates/package-list.lucius | 9 +++++++++ templates/stackage-diff.hamlet | 24 +++++++++++++++++------- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/Stackage/Snapshot/Diff.hs b/src/Stackage/Snapshot/Diff.hs index 5900e05..f3335be 100644 --- a/src/Stackage/Snapshot/Diff.hs +++ b/src/Stackage/Snapshot/Diff.hs @@ -4,10 +4,12 @@ module Stackage.Snapshot.Diff , snapshotDiff , SnapshotDiff() , toDiffList + , toVersionedDiffList , VersionChange(..) , WithSnapshotNames(..) ) where +import qualified Data.Text as T(commonPrefixes) import Data.Align import Data.Aeson import qualified Data.HashMap.Strict as HashMap @@ -36,6 +38,20 @@ instance ToJSON (WithSnapshotNames SnapshotDiff) where toDiffList :: SnapshotDiff -> [(PackageName, VersionChange)] toDiffList = sortOn (toCaseFold . unPackageName . fst) . HashMap.toList . unSnapshotDiff +versionPrefix :: VersionChange -> Maybe (Text,Text,Text) +versionPrefix vc = case unVersionChange vc of + These (Version a) (Version b) -> T.commonPrefixes a b + _ -> Nothing + +versionedDiffList :: [(PackageName, VersionChange)] -> [(PackageName, VersionChange, Maybe (Text,Text,Text))] +versionedDiffList = map withPrefixedVersion + where + withPrefixedVersion (packageName, versionChange) = (packageName, versionChange, versionPrefix versionChange) + + +toVersionedDiffList :: SnapshotDiff -> [(PackageName, VersionChange, Maybe (Text, Text, Text))] +toVersionedDiffList = versionedDiffList . toDiffList + -- | Versions of a package as it occurs in the listings provided to `snapshotDiff`. -- -- Would be represented with `These v1 v2` if the package is present in both listings, diff --git a/templates/package-list.lucius b/templates/package-list.lucius index 54a842d..556bcb9 100644 --- a/templates/package-list.lucius +++ b/templates/package-list.lucius @@ -2,4 +2,13 @@ .table th, .table td { padding-left: 0; } + + .table span.version-removed { + background-color: red; + text-decoration: line-through; + } + + .table span.version-added { + background-color: green; + } } diff --git a/templates/stackage-diff.hamlet b/templates/stackage-diff.hamlet index 4b414d3..4cae29d 100644 --- a/templates/stackage-diff.hamlet +++ b/templates/stackage-diff.hamlet @@ -33,7 +33,7 @@ $else