{-# LANGUAGE OverloadedStrings #-}
module Text.Pandoc.Filter.Plot.Renderers.Prelude (
module Prelude
, module Text.Pandoc.Filter.Plot.Monad
, Text
, st
, unpack
, commandSuccess
, existsOnPath
, OutputSpec(..)
, appendCapture
, toRPath
) where
import Data.Maybe (isJust)
import Data.Text (Text, unpack)
import System.Directory (findExecutable)
import System.FilePath (isPathSeparator)
import System.Exit (ExitCode(..))
import Text.Shakespeare.Text (st)
import Text.Pandoc.Filter.Plot.Monad
commandSuccess :: FilePath
-> Text
-> PlotM Bool
commandSuccess fp s = do
(ec, _) <- runCommand fp s
return $ ec == ExitSuccess
existsOnPath :: FilePath -> IO Bool
existsOnPath fp = findExecutable fp >>= fmap isJust . return
appendCapture :: (FigureSpec -> FilePath -> Script)
-> FigureSpec -> FilePath -> Script
appendCapture f s fp = mconcat [script s, "\n", f s fp]
data OutputSpec = OutputSpec
{ oFigureSpec :: FigureSpec
, oScriptPath :: FilePath
, oFigurePath :: FilePath
}
toRPath :: FilePath -> FilePath
toRPath = fmap (\c -> if isPathSeparator c then '/' else c)