1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 14:21:31 +03:00

Return Output from json, split, summary, and patch

This commit is contained in:
joshvera 2016-08-09 18:51:44 -04:00
parent 11863b8748
commit 2933a24d45
4 changed files with 5 additions and 6 deletions

View File

@ -9,7 +9,6 @@ import Alignment
import Category
import Data.Aeson as A hiding (json)
import Data.Bifunctor.Join
import Data.ByteString.Builder
import Data.Record
import qualified Data.Text as T
import Data.These
@ -23,7 +22,7 @@ import Term
-- | Render a diff to a string representing its JSON.
json :: (HasField fields Category, HasField fields Range) => Renderer (Record fields)
json blobs diff = toS . toLazyByteString . fromEncoding . pairs $ "rows" .= annotateRows (alignDiff (source <$> blobs) diff) <> "oids" .= (oid <$> blobs) <> "paths" .= (path <$> blobs)
json blobs diff = JSONOutput $ "rows" .= annotateRows (alignDiff (source <$> blobs) diff) <> "oids" .= (oid <$> blobs) <> "paths" .= (path <$> blobs)
where annotateRows = fmap (fmap NumberedLine) . numberedRows
newtype NumberedLine a = NumberedLine (Int, a)

View File

@ -27,7 +27,7 @@ truncatePatch _ blobs = pack $ header blobs <> "#timed_out\nTruncating diff: tim
-- | Render a diff in the traditional patch format.
patch :: HasField fields Range => Renderer (Record fields)
patch blobs diff = pack $ case getLast (foldMap (Last . Just) string) of
patch blobs diff = PatchOutput . pack $ case getLast (foldMap (Last . Just) string) of
Just c | c /= '\n' -> string <> "\n\\ No newline at end of file\n"
_ -> string
where string = header blobs <> mconcat (showHunk blobs <$> hunks diff blobs)

View File

@ -83,7 +83,7 @@ splitPatchToClassName patch = stringValue $ "patch " <> case patch of
-- | Render a diff as an HTML split diff.
split :: (HasField fields Category, HasField fields Cost, HasField fields Range) => Renderer (Record fields)
split blobs diff = TL.toStrict . renderHtml
split blobs diff = SplitOutput $ TL.toStrict . renderHtml
. docTypeHtml
. ((head $ link ! A.rel "stylesheet" ! A.href "style.css") <>)
. body

View File

@ -3,12 +3,12 @@ module Renderer.Summary where
import Category
import Prologue
import Renderer
import Data.Aeson
import Data.Record
import Range
import DiffSummary
import Source
import Data.Aeson
summary :: (HasField fields Category, HasField fields Range) => Renderer (Record fields)
summary blobs diff = toS . encode $ summaries >>= annotatedSummaries
summary blobs diff = SummaryOutput $ "summaries" .= (summaries >>= annotatedSummaries)
where summaries = diffSummaries (source <$> blobs) diff