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

Move concatOutputs to Renderer

This commit is contained in:
joshvera 2016-08-10 12:17:23 -04:00
parent 2933a24d45
commit 220ade0473

View File

@ -1,10 +1,12 @@
module Renderer where module Renderer (Renderer, DiffArguments(..), Output(..), concatOutputs, Format(..)) where
import Prologue import Prologue
import Data.Functor.Both import Data.Functor.Both
import Diff import Diff
import Source import Source (SourceBlob)
import Data.Aeson.Types (Series) import Data.Aeson.Types (Series, pairs)
import Data.Text as T (intercalate)
import Data.Aeson.Encoding (encodingToLazyByteString)
-- | A function that will render a diff, given the two source blobs. -- | A function that will render a diff, given the two source blobs.
type Renderer annotation = Both SourceBlob -> Diff Text annotation -> Output type Renderer annotation = Both SourceBlob -> Diff Text annotation -> Output
@ -14,6 +16,20 @@ data DiffArguments = DiffArguments { format :: Format, output :: Maybe FilePath,
data Output = SplitOutput Text | PatchOutput Text | JSONOutput Series | SummaryOutput Series data Output = SplitOutput Text | PatchOutput Text | JSONOutput Series | SummaryOutput Series
concatOutputs :: [Output] -> Text
concatOutputs l@(JSONOutput _ : _) = toS . encodingToLazyByteString . pairs . mconcat $ toSeries <$> l
concatOutputs l@(SummaryOutput _ : _) = toS . encodingToLazyByteString . pairs . mconcat $ toSeries <$> l
concatOutputs l = T.intercalate "\n" (toText <$> l)
toSeries :: Output -> Series
toSeries (JSONOutput series) = series
toSeries (SummaryOutput series) = series
toText :: Output -> Text
toText (SplitOutput text) = text
toText (PatchOutput text) = text
-- | The available types of diff rendering. -- | The available types of diff rendering.
data Format = Split | Patch | JSON | Summary data Format = Split | Patch | JSON | Summary
deriving (Show) deriving (Show)