mirror of
https://github.com/github/semantic.git
synced 2024-12-22 14:21:31 +03:00
Move concatOutputs to Renderer
This commit is contained in:
parent
2933a24d45
commit
220ade0473
@ -1,10 +1,12 @@
|
||||
module Renderer where
|
||||
module Renderer (Renderer, DiffArguments(..), Output(..), concatOutputs, Format(..)) where
|
||||
|
||||
import Prologue
|
||||
import Data.Functor.Both
|
||||
import Diff
|
||||
import Source
|
||||
import Data.Aeson.Types (Series)
|
||||
import Source (SourceBlob)
|
||||
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.
|
||||
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
|
||||
|
||||
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.
|
||||
data Format = Split | Patch | JSON | Summary
|
||||
deriving (Show)
|
||||
|
Loading…
Reference in New Issue
Block a user