{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleContexts #-}
-- | Defines the underlying data types used in the package extension.
module Utils.Drasil.FileData (FileAndContents(filePath, fileDoc),
  fileAndContents, hasPathAndDocToFileAndContents) where

import Text.PrettyPrint.HughesPJ (Doc)
import Utils.Drasil.TypeClasses (HasPathAndDoc(..))

-- | The underlying data type for auxiliary files in all renderers.
data FileAndContents = FileAndContents {FileAndContents -> FilePath
filePath :: FilePath, FileAndContents -> Doc
fileDoc :: Doc}

-- | Constructor for auxiliary files.
fileAndContents :: FilePath -> Doc -> FileAndContents
fileAndContents :: FilePath -> Doc -> FileAndContents
fileAndContents = FilePath -> Doc -> FileAndContents
FileAndContents

instance HasPathAndDoc FileAndContents Doc where
  getPath :: FileAndContents -> FilePath
getPath = FileAndContents -> FilePath
filePath
  getDoc :: FileAndContents -> Doc
getDoc = FileAndContents -> Doc
fileDoc

hasPathAndDocToFileAndContents :: (HasPathAndDoc a Doc) => a -> FileAndContents
hasPathAndDocToFileAndContents :: forall a. HasPathAndDoc a Doc => a -> FileAndContents
hasPathAndDocToFileAndContents a
file = FilePath -> Doc -> FileAndContents
fileAndContents (a -> FilePath
forall a b. HasPathAndDoc a b => a -> FilePath
getPath a
file) (a -> Doc
forall a b. HasPathAndDoc a b => a -> b
getDoc a
file)