From 13d088e6b8f7fd269ff9f69685c18767551fb9d4 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 10 May 2017 13:18:47 -0400 Subject: [PATCH] Define a function to compute a JSONSummary from an Entry. --- src/Renderer/TOC.hs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Renderer/TOC.hs b/src/Renderer/TOC.hs index 38869affa..5cc47a17d 100644 --- a/src/Renderer/TOC.hs +++ b/src/Renderer/TOC.hs @@ -10,6 +10,7 @@ module Renderer.TOC , declarationAlgebra , Entry(..) , tableOfContentsBy +, entrySummary ) where import Category as C @@ -106,6 +107,14 @@ tableOfContentsBy selector = fromMaybe [] . iter diffAlgebra . fmap (Just . fmap termAlgebra r | Just a <- selector r = [a] | otherwise = fold r +-- | Construct a 'JSONSummary' from an 'Entry'. Returns 'Nothing' for 'Unchanged' patches. +entrySummary :: (HasField fields Category, HasField fields (Maybe Declaration), HasField fields SourceSpan) => Entry (Record fields) -> Maybe JSONSummary +entrySummary entry = case entry of + Unchanged _ -> Nothing + Changed a -> Just (recordSummary a "modified") + Patched p -> Just (recordSummary (afterOrBefore p) (patchType p)) + where recordSummary record = JSONSummary . Summarizable (category record) (maybe "" declarationIdentifier (getField record :: Maybe Declaration)) (sourceSpan record) + toc :: HasDefaultFields fields => Both SourceBlob -> Diff (Syntax Text) (Record fields) -> Summaries toc blobs diff = Summaries changes errors where